Unfocus a TextInput in React Native

后端 未结 6 1583
我寻月下人不归
我寻月下人不归 2020-12-29 20:44

I\'m building an Android app with React Native.

How can you force a TextInput to \"unFocus\", meaning the cursor is blinking inside the text field. The

6条回答
  •  清酒与你
    2020-12-29 20:55

    My use case was a little different. The user wouldn't enter a value directly in the input field. The field was mainly used to capture the user's attempt at entering a value and open a modal instead. I wanted to blur the field after the modal closed to reduce the extra tap the user would have to do later.

    If using Hooks, you can do something as simple as

    const inputRef = useRef(null);
    
    
    

    Then just call this anywhere you need it.

    inputRef.current.blur();
    

提交回复
热议问题