Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

{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>

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You don’t need onTouchStart prop, you can use below props in TextInput, like:

<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.

Hope this works for you.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading