[英]How to detect outside textInput touch In React-native
i have create on custom dropdown list View that i am showing on click of TextInput.user can search as well as select item from that list.now i want to close that window on click outside of that textInput How to set visibility false on touch outside of textInput我已经在自定义下拉列表视图上创建了我在单击 TextInput 时显示的视图。用户可以搜索该列表中的 select 项目。现在我想在单击该文本输入外部时关闭该 window 如何在触摸外部时设置可见性 false文本输入
{modalVisible ?
(
<View style={styles.emailItem}>
<ShowCustomDropdown globalsearchdata={globalsearchdata} />
</View>
) : null}
<View style={styles.textinputstyle}>
<TextInput
onTouchStart={()=> setModalVisible(true)}
onChangeText={handleChange}
style={styles.searchInput}
placeholder="Type a message"
value={search_term}
/>
</View>
You don't need onTouchStart
prop, you can use below props in TextInput
, like:您不需要onTouchStart
道具,您可以在TextInput
中使用以下道具,例如:
<TextInput
onFocus={() => setModalVisible(true) } //focus received
onBlur={() => setModalVisible(false) } //focus lost
onChangeText={handleChange}
style={styles.searchInput}
placeholder="Type a message"
value={search_term}
/>
onFocus
prop will let you know if TextInput
is focussed and onBlur
prop will let you know when you click outside TextInput
or it isn't focussed. onFocus
属性会通知您TextInput
是否已聚焦,而onBlur
会在您单击TextInput
外部或未聚焦时通知您。
Hope this works for you.希望这对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.