React-native导航总结

1.安装依赖

npm install @react-navigation/native
npm install @react-navigation/stack
npm install @react-navigation/bottom-tabs
npm install @react-navigation/material-top-tabs react-native-tab-view
npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view

2.配置
在android/app/build.gradle dependencies 对象里面

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

3.堆栈导航
1.导入

import {NavigationContainer} from '@react-navigation/native';
//  导航容器
import {createStackNavigator} from '@react-navigation/stack';
//  导入创建堆栈导航方法
2. 创建 堆栈导航
const Stack = createStackNavigator();
3.创建导航需要的界面
 <NavigationContainer>
        <Stack.Navigator>
          <Stack.Screen 
            name="Home" 
            component={Home}
                />
          <Stack.Screen 
            name="Details" 
            component={Details}         
        
            />
        </Stack.Navigator>
      </NavigationContainer>

4.包装导航

NavigationContainer 导航容器
Stack.Navigator 堆栈导航
Stack.Screen  堆栈导航页面

5.页面的跳转
this.props.navigation
push 推入堆栈
replace 替换当前页面
goBack() 返回
popToTop() 回到顶层
6.参数的处理

navigation.push(“Details”,{id:"abc"}) //传递参数
this.props.route.params.id	//获取参数
<Stack.Screen   initialParams={{id:1}}>	//配置初始化参数
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值