[英]React Native trigger press event except child component
我的用例是單擊父組件(例如TouchableOpacity
)時觸發某些事件,但是單擊子組件(例如Screen
和其他示例)時什么也不會觸發。 我的情況就像防止網上冒泡一樣。 從文檔中我讀過說它應該使用onStartShouldSetResponderCapture
,但我仍然不知道用法。 以下是代碼段。
<TouchableOpacity style={styles.container} onPress={() => alert('tes')}
>
<Screen style={styles.screenContainer} onStartShouldSetResponderCapture={() => false}>
<Title>Edit Nama Restoran</Title>
<Divider styleName='line' />
<TextInput
style={{ flex: 1 }}
value={value}
onChangeText={value => this.setState({ value })}
onSubmitEditing={this.handleSubmit}
/>
<View styleName='horizontal' style={styles.nameContainer}>
<Button styleName='confirmation dark' onPress={this.handleSubmit}>
<Text>UPDATE</Text>
</Button>
<Button styleName='confirmation' onPress={onClose}>
<Text>CLOSE</Text>
</Button>
</View>
</Screen>
</TouchableOpacity>
編輯:
以下是我的案例的說明。
如果單擊覆蓋(在<Screen>
),則會觸發警報(預期)。
如果單擊白色對話框( <Screen>
和其中的子項),它也會觸發警報(意外)。 我需要的是單擊<Screen>
時不觸發警報。
更新以顯示如何使用模態:
<Modal
visible={this.state.modalVisible}
onRequestClose={() => {alert("Modal has been closed.")}}
>
<TextInput
style={{ flex: 1 }}
value={value}
onChangeText={value => this.setState({ value })}
onSubmitEditing={this.handleSubmit}
/>
</Modal>
不確定這是否是您代碼中的正確代碼段,但基本上不是您想要彈出的部分,將其從可觸摸的不透明度中拉出,然后在其周圍包裹一個模式。 然后單擊以使其可見/不可見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.