欢迎来到蕾蕾的博客

react-native项目中遇到的问题

1.react-native的Text宽度不设置时要自适应Text的文本长度

<View style={{alignSelf:'flex-start'}}>
<Text>sss</Text>
</View>

2.react-redux使用时利用ref调用子组件方法不可用报错

如下在父组件中调用子组件的写法

父组件

handleShowModalAdd = () => {
this.add.handleToggle()//handleToggle为子组件中的方法
}
<SystemAdd ref={(el) => this.add = el}/>
但是当我们在子组件中使用redux的时候,由于使用connect对子组件进行了包装,会导致获取不到子组件中的方法

 

下面的是使用redux后的ref使用方法

父组件

handleShowModalAdd = () => {
this.add.handleToggle()   //handleToggle为子组件中的方法
}
<SystemAdd onRef={(ref) => this.add = ref }/>
 子组件

componentDidMount(){
this.props.onRef(this)   //将组件实例this传递给onRef方法
}


————————————————
原文链接:https://blog.csdn.net/chris__wang/article/details/97390279

 

 

3.rn中绝对定位后不能点击的问题

在rn中, 父元素采用相对定位,子元素采用绝对定位, 如果子元素的位置超出了父元素的范围,子元素只能显示,不能添加点击事件。


posted @ 2019-12-04 15:53  蕾蕾是个程序员  阅读(413)  评论(1编辑  收藏  举报