zoukankan      html  css  js  c++  java
  • React Native中Navigator的安装与使用

    一、安装Navigator

    1.安装react-native-deprecated-custom-components

    npm install react-native-deprecated-custom-components  --save 

    2.若npm安装报错,则执行下面命令

    npm i react-native-deprecated-custom-components  --save

    3.若还未解决则使用yarn命令(前提是自己有yarn的配置环境)

    yarn add react-native-deprecated-custom-components  --save 

    二、使用Navigator

    说明:本demo为男生给女生送一枝玫瑰,女生回赠巧克力。包含了父子组件的通信

    1.引入Navigator

    import {Navigator} from "react-native-deprecated-custom-components" 

    2.页面A(用于放置父组件Boy和子组件Girl):

    <Navigator
                    initialRoute={{
                        //Boy为默认显示组件
                        component: Boy
                    }}
                    renderScene={(route,navigator)=>{
                        let Component = route.component;
                        return <Component navigator={navigator} {...route.params}/>
                    }}
                ></Navigator>

    3.父组件Boy(父组件):

    <View style={styles.container}>
                    <Text style={styles.text}>I am Boy</Text>
                    <Text
                        style={styles.text}
                        onPress={
                            ()=>{
                                this.props.navigator.push({
                                    component:Girl,
                                    params:{
                                        word:'一枝玫瑰',
                                        onCallBack:(word)=>{
                                            this.setState({
                                                word:word
                                            })
                                        }
                                    }
                                })
                            }
                        }
                    >送女孩一支玫瑰</Text>
                    <Text style={styles.text}>{this.state.word}</Text>
                </View>

    4.子组件Girl(子组件):

    <View style={styles.container}>
                    <Text style={styles.text}>
                        I am Girl.
                    </Text>
                    <Text style={styles.text}>
                        我收到了男孩送的玫瑰{this.props.word}
                    </Text>
                    <Text
                        style={styles.text}
                        onPress={
                            ()=>{
                                this.props.onCallBack('一盒巧克力');
                                //删除组件
                                this.props.navigator.pop()
                            }
                        }
                    >
                        回赠巧克力
                    </Text>
                </View>
    
  • 相关阅读:
    shell数组
    正则表达式整数
    云计算的三种服务模式(IaaS/PaaS/SaaS)
    云计算通信协议
    LVS 核心组件和专业术语
    nginx
    【转】mybatis调用mssql有输入输出参数那种..
    OAuth2.0 在 SSO中的应用~
    Git 本地安装
    【转】Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法
  • 原文地址:https://www.cnblogs.com/piaobodewu/p/9847088.html
Copyright © 2011-2022 走看看