RN开发-Navigator
1、在入口组件render方法中返回<Navigator>
let defaultName = 'Welcome';
let defaultCompenent = Welcome;
<Navigator
initialRoute={{name:defaultName,component:defaultCompenent}}
/*configureScene={
(route) => {
//页面转跳动画 node_modules/react-native/Libraries/CustomComponent/navigate/
return Navigator.SceneConfig.VerticalDownSwipeJump;
}
}*/
renderScene={
(route,navigator)=>{
let Component = route.component;
return <Component {...route.params} navigator={navigator}></Component>;
}
}
/>
2、在Welcom组件的点击事件中修改转跳页面信息并添加参数
pressButton(){
const {navigator} = this.props;
const self = this;
/* 上文中,<Component {...route.params} navigator={navigator} 中传递了navigator作为props */
if(navigator){
navigator.push({
name: 'Detail',
component: Detail,
params:{
author:this.state.author,
user:this.props.user,
getResult: function(res){
self.setState({
result:res
})
}
}
})
}
}
3、在Detail组件中携带参数返回
(1)、接收参数
//生命周期方法
componentDidMount(){
this.setState({
author:this.props.author,
user:this.props.user
});
}
(2)、携带参数返回
backButton(){
const {navigator} = this.props;
if(this.props.getResult){
let result = USER_MODELS[1];
this.props.getResult(result);
}
if(navigator){
// 入栈出栈,把当前页面pop掉
navigator.pop();
}
}
最新文章
- JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议
- Python--增量循环删除MySQL表数据
- Centos6.5 SVN服务器 搭建及配置
- Python自动化 【第十篇】:Python进阶-多进程/协程/事件驱动与Select\Poll\Epoll异步IO
- 查看进程的io
- 5、XML(1)
- ORACLE 重置SEQQUENCE
- 《Linux系统静态路由和火墙路由》
- Android Studio学习随笔-UI线程阻塞以及优化
- (记录前面算过的后面仍然会用的数减小复杂度)A - AC Me
- Tomcat 启动报错:javax.naming.NamingException: No naming context bound to this class loader
- elasticsearch系列(五)score
- 【LeetCode】258. Add Digits
- angular路由守卫
- 安卓startActivityForResult用法
- Top Page
- .net core实践系列之短信服务-Sikiro.SMS.Api服务的实现
- 注解(Annotation)
- IntelliJ IDEA SVN
- 74.VS2013和opencv3.1.0安装教程