【问题标题】:react-native bottom navigator does not hide bottomtab totally and it is bumping upreact-native 底部导航器没有完全隐藏底部标签,它正在向上
【发布时间】:2020-07-28 01:43:55
【问题描述】:

请帮助我。 我制作聊天用户界面。 这个问题让我恶心... 请给我一个建议。

我的情况如下

我的代码是这样的。 你可以很容易地理解我的代码..

App.js // BottomTabNavigator 部分

const Tab = createBottomTabNavigator();
    const App = () => {
      const visible = (route) => {
        if (route.state?.index > 0) {
          return false;
        } else {
          return true;
        }
      };
    
      return (
        <>
          <StatusBar barStyle="dark-content" />
          <SafeAreaView style={{flex: 1}}>
            <NavigationContainer>
              <Tab.Navigator
                tabBarOptions={{
                  activeTintColor: 'red',
                  inactiveTintColor: 'blue',
                }}>
                <Tab.Screen
                  name={'chat'}
                  component={Chat}
                  options={({route}) => ({
                    tabBarVisible: visible(route),
                  })}
                />
                <Tab.Screen name={'setting'} component={Setting} />
              </Tab.Navigator>
            </NavigationContainer>
          </SafeAreaView>
        </>
      );
    };

Chat.js // StackNavigator 部分

const Stack = createStackNavigator();
const Chat = ({navigation}) => {
  return (
    <Stack.Navigator>
      <Stack.Screen name="chatlist" component={Chatlist} />
      <Stack.Screen name="chatroom" component={Chatroom} />
    </Stack.Navigator>
  );
};

聊天列表.js

const Chatlist = ({route, navigation}) => {
  return (
    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
      <TouchableOpacity onPress={() => navigation.navigate('chatroom')}>
        <Text>chatlist</Text>
      </TouchableOpacity>
    </View>
  );
};

Chatroom.js

const Chatroom = () => {
  return (
    <View style={{flex: 1, backgroundColor: 'red'}}>
      <Text>Chatroom</Text>
    </View>
  );
};

【问题讨论】:

    标签: react-native react-navigation chat stack-navigator react-navigation-bottom-tab


    【解决方案1】:

    尝试删除 SafeAreaView

    const Tab = createBottomTabNavigator();
        const App = () => {
          const visible = (route) => {
            if (route.state?.index > 0) {
              return false;
            } else {
              return true;
            }
          };
        
          return (
                <NavigationContainer>
                  <Tab.Navigator
                    tabBarOptions={{
                      activeTintColor: 'red',
                      inactiveTintColor: 'blue',
                    }}>
                    <Tab.Screen
                      name={'chat'}
                      component={Chat}
                      options={({route}) => ({
                        // Delete tabBarVisible here ======>
                        // tabBarVisible: visible(route),
                      })}
                    />
                    <Tab.Screen name={'setting'} component={Setting} />
                  </Tab.Navigator>
                </NavigationContainer>
          );
        };
    
    

    【讨论】:

    • 或者你可以在``` ({ tabBarVisible: visible( route), })} /> ``` 我发现了关于 tabBarVisible 的问题 github.com/react-navigation/react-navigation/issues/5790
    • 谢谢。但是当用户进入聊天室时我想隐藏bottomTab ..
    • ``` ({ })} /> ```
    • 谢谢。我做到了。但我想在聊天室屏幕时隐藏标签栏。该解决方案使标签栏保留在所有屏幕中..
    • 非常感谢!!我又读了一遍。它说你是对的。所以我必须改变设计。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多