man*_*nok 14 reactjs react-native
在我的应用程序中,我有一个嵌套的 Touchable 元素。每次我按下其中一个,我只得到一个事件。我可以将内部向下传播到层吗?提前致谢!
代码如下:
<TouchableHighlight style={{ flex: 1 }} onPress={() => { console.log('outer press') }}>
<TouchableHighlight style={{ flex: 0.8, backgroundColor: 'blue' }} onPress={() => { console.log('inner press') }}>
<Text>1</Text>
</TouchableHighlight>
</TouchableHighlight>
Run Code Online (Sandbox Code Playgroud)
Pri*_*dya 12
一个Touchables包含一个本地状态,这是原产于它和其他的Touchables都没有意识到这一点。
因此,当您触摸嵌套时Touchable,事件会传播到访问状态的子元素,并且除非完成,否则不会释放资源
这将是您案例中嵌套的生命周期buttons,如docs
Parent: Parent Touchable
Child: Child Touchable
Parent onStartShouldSetResponder > Parent onResponderGrant > Parent onResponderTerminationRequest > Parent onResponderTerminate > Child onStartShouldSetResponder > Child onResponderGrant > Child onResponderRelease
Run Code Online (Sandbox Code Playgroud)
家长将无法访问,因为 onResponderReject
如果父母
View想阻止孩子在触摸开始时成为响应者,它应该有一个onStartShouldSetResponderCapture返回true.
你可以看看这个视频
| 归档时间: |
|
| 查看次数: |
10853 次 |
| 最近记录: |