最近做了个App项目,基于react-native的,其中要设计一个底部的导航栏,就用到了react-navigation的bottom-tabs。
引入bottom-tabs,代码如下:
import {
NavigationContainer
} from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createNativeStackNavigator } from '@react-navigation/native-stack'; //本机原生导航,性能强,自定义性不如stack
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
render() {
return (<NavigationContainer ref={navigationRef}>
<Stack.Navigator initialRouteName={initialRouteName}>
<Stack.Screen
options={{ headerShown: false }}
name="Tab"
component={TabNavigator}
/>
<Stack.Screen
options={{
headerShown: false
}}
name="Login"
component={LoginScreen}
/>
</Stack.Navigator>
</NavigationContainer>)
}
但在用真机调试时,点击tab按钮死活没反应,只偶尔能跳转页面,找了半天资料发现都不行。
最终发现是因为开启了手机的远程调试,关闭stopDebugging即可,因为这个远程调试可能会影响app的一些反应速度,但没想到会彻底点不动,坑呀!