关于RN中 props的父与子试图的一些简单用法

声明一个顶部导航栏View

< View style = { styles . container } >
                 < View style = {{ flex: 1 }} ></ View >
                 < View style = {{ flex: 1 , flexDirection: 'row' }} >
                    < View style = {{ flex: 1 }} >
                        < Text style = {{ alignSelf : 'flex-start' , height: 44 , marginLeft: 8 }} > 管理员 </ Text >
                    </ View >
                    < View style = {{ flex: 1 , flexDirection: 'row' , justifyContent: 'center' , alignItems: 'center' }} >
                        < View style = {{ flex: 4 }} >
                        < Text onPress = { this . props . onPressAdress } style = {{ height: 22 , textAlign : 'right' }} > this.props.name </ Text ></ View >
                        < View style = {{ flex: 1 }} >
                        < TouchableHighlight underlayColor = '#FFA54F' onPress = { this . props . onPressSetting } >
                        < Image style = {{ height: 22 , width: 22 , alignSelf : 'flex-end' }} source = { require ( '../../res/images/setting.png' )} />
                        </ TouchableHighlight ></ View >
                        < View style = {{ flex: 0.3 , width: 5 }} />
                    </ View >
                 </ View >
             </ View >

在使用的时候直接导出这块Component     在另一个界面导入

< BaseHeadView onPressAdress = {() =>this . props . navigation . navigate ( 'SingIn' ,{ name: '总工时:0分钟' })} onPressSetting = {() => alert ( 'dianji设置' )} />

使用时可直接调用父类的属性来进行赋值,可以介绍一部分的代码量,所有的属性都可以  图片  文字  触发方法

自己摸索,如果不对,谢谢大家前来留言指导。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值