cordova-plugin-native-keyboard icon indicating copy to clipboard operation
cordova-plugin-native-keyboard copied to clipboard

What part of the React lifecycle is the best place to run the code to show the keyboard?

Open haveamission opened this issue 6 years ago • 3 comments

I am trying to integrate this into a React app, and I am noticing that the keyboard opens, closes, and then opens again and the whole viewport resizes and looks awful.

This is when running the keyboard launch in the render() method - is there a better way to launch the keyboard in React? React Cordova apps are relatively rare and I'm not seeing many instances of how to handle this.

haveamission avatar Jun 14 '19 19:06 haveamission

I have 0 React experience, so don't expect an answer from me.

EddyVerbruggen avatar Jun 14 '19 19:06 EddyVerbruggen

I call the showMessenger method in componentDidMount (so I already have the ref for the autoscrollElement) and hideMessenger in componentWillUnmount

flache avatar Jun 17 '19 12:06 flache

If you are using React Hooks, useEffect with nothing in the dependency array would be equivalent to componentDidMount. Use a useEffect cleanup method would be the same as componentWillUnmount.

useEffect(() => {
     // Put your show keyboard code in here
     
     return () => {
     // Put your componentWillUnmount code here
     }

}, [])

corncobb avatar Sep 10 '20 19:09 corncobb