react-native Navigation导航器,太爽了

navigation.navigate(‘Home’, {
screen: ‘Settings’,
params: { user: ‘Tom’ },
});

2.5.2 更新参数

页面上也可以更新参数,类似更新页面状态。navigation.setParams就可以用来更新页面参数

你也可以向页面传递一些初始参数。如果导航到页面并没有设置任何参数,这个初始参数将会被使用。它们会与传递的参数进行浅合并。初始参数被指定为initialParams 属性:

<Stack.Screen
name=“Login”
component={Login}
initialParams={ { userId: 42 }}
/>

2.5.3 传递参数到之前的页面

不仅仅能传递参数到新的页面,也能传递参数到之前的页面。

想做到这个,你可以使用navigate的方法,如果页面存在的话,可以使用像 goBack 这样的方法。你可以通过navigate携带参数将参数传回去:

// Some.js
import React, { useState, Component } from “react”;
import { Text, View } from “react-native”;

class App extends Component {
constructor(props) {
super(props)
}
render() {
return (

{this.props.route.params.type ? this.props.route.params.ty
pe : “has null”}


)
}
}
export default App;

// Home.js
import * as React from ‘react’;
import { View, TextInput, Button } from ‘react-native’;
function goLogin(navigation, postText) {
navigation.push(“Login”, {type: postText}) // 把输入框的值传递给 Login 页面
}
function Some({navigation, route}) {
let {text} = route.params;
let [postText, setPostText] = React.useState(text);
return (

<TextInput
multiline
placeholder=“What’s on your mind?”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值