How to hide the header of `createBottomTabNavigator` who is not allowing the headers of all classes implemented using `navigationOptions`

╄→гoц情女王★ 提交于 2019-12-11 15:52:05

问题


All classes of my React Native code have their own header implemented using navigationOptions and I've created the bottomTabNavigator that has its own header overwriting the existing header and their functionality. How to hide the bottomTabNavigator header while own headers of classes work properly and accordingly?

I've used header: null and navigationOptions: { header: null, } in the stack of bottomTabNavigator and also header: { visible: false, } but it didn't work, as header is still visible.

import React from 'react';
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';
import { Input, Icon, SearchBar, ListItem } from 'react-native-elements';

import Notification from './notification.js';
import Nearby from './nearby.js';
import Add from './add.js';

class MainScreen extends React.Component {
  constructor(props){
    super(props);
    this.state = { search: '' };
  }

  static navigationOptions = {
    title: 'Contacts',
    headerLeft: null,
    headerRight: (
      <TouchableOpacity
        activeOpacity={0.6}
        style={{marginRight: 10,}}
        onPress={() => alert('Map is shown!')}>
        <Text style={{ color: '#3090C7', fontSize: 16 }}>View on Map</Text>
      </TouchableOpacity>
    ),
    headerTitleStyle: { width: '110%', textAlign: 'center', },
    headerStyle: { backgroundColor: '#E4E4E2' }
  };

  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'flex-start', alignItems: 'center', backgroundColor: '#F3F3F3' }}>
        <SearchBar
          autoCorrect={false}
          placeholder='Search From Contacts'
          platform = 'ios'
          inputStyle = {styles.txt}
          onChangeText = {search => this.setState ({search})}
          value={this.state.search}
        />
        <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F3F3F3' }}>
          <Text> Successfully Logged-In </Text>
        </View>
      </View>
    );
  }
}

const HomeStack = createBottomTabNavigator({
  Home: { screen: MainScreen, header: { visible: false, } },
  Notification: { screen: Notification, header: null, },
  Nearby: { screen: Nearby, header: null, },
  Add: { screen: Add, header: null, },
});

const Home = createAppContainer(HomeStack);
export default Home;


const styles = StyleSheet.create({

  txt: {
    color: '#3090C7',
    fontSize: 18,
    fontWeight: '500',
  },

  btn: {
    alignItems: 'center',
    justifyContent: 'center',
    alignSelf: 'center',
  },
})

I expect that header of bottomTabNavigator should be hidden and headers of each class should be visible.

来源:https://stackoverflow.com/questions/56987053/how-to-hide-the-header-of-createbottomtabnavigator-who-is-not-allowing-the-hea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!