我在react-native中的stackNavigator附带的标头面临一个小问题。

我有两个视图,分别是Skatebay和Profile。
当我使用stackNavigator时,它会在Skatebay视图中添加一个顶部的“标题”,如果不能的话,如何删除它,我是否可以将其样式设置为已经创建的标题?

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableHighlight,
  Image,
  ScrollView,
  Button,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
import s from './styles/main.js';

class skatebay extends React.Component{

  render(){
    const { navigate } = this.props.navigation;
    return (

  <View style={s.container}>

      <View style={s.toolbar}>
        <TouchableHighlight style={s.toolbarButton} onPress={() => navigate('Profile')}
          title="Profile">
          <Image style={s.toolIcon} source={require('./gfx/profile.png')}/>
        </TouchableHighlight>

        <TouchableHighlight style={s.toolbarTitle} onPress={alert}>
          <Image style={s.logo} source={require('./gfx/logos.png')}/>
        </TouchableHighlight>

        <TouchableHighlight style={s.toolbarButton} onPress={alert}>
          <Image style={s.toolIcon} source={require('./gfx/settings.png')}/>
        </TouchableHighlight>
      </View>

      </View>
    );
    }
}



个人资料视图


class ProfileScreen extends React.Component {
    static navigationOptions = {
        title: 'Profile',
    };
render() {
    return (
      <View>
        <Text>profile</Text>
      </View>
    );
  }
}


const skatebayApp = StackNavigator({
  Main: {screen: skatebay},
  Profile: {screen: ProfileScreen}
});

AppRegistry.registerComponent('skatebayApp', () => skatebayApp);


我说的是我创建的白色标头上方的蓝色/灰色标头。

javascript -  react  native stackNavigation header-LMLPHP

最佳答案

如果您不希望使用默认的StackNavigator标头,则可以不将其传递给StackNavigatorConfig https://reactnavigation.org/docs/navigators/stack#StackNavigatorConfig

const skatebayApp = StackNavigator({
  Main: {screen: skatebay},
  Profile: {screen: ProfileScreen}
}, {
  headerMode: 'none'
});

09-25 16:19