useKeyboard on Android
andreasbergqvist opened this issue ยท 3 comments
keyboardWillShow & keyboardWillHide is not available on Android.
See: https://facebook.github.io/react-native/docs/keyboard
One idea is to listen to those + keyboardDidShow & keyboardDidHide (these are available on Android).
Would that be a feasible solution or will it mess something up?
react-navigation-tabs uses the next technique
if (Platform.OS === 'ios') {
Keyboard.addListener('keyboardWillShow', this._handleKeyboardShow);
Keyboard.addListener('keyboardWillHide', this._handleKeyboardHide);
} else {
Keyboard.addListener('keyboardDidShow', this._handleKeyboardShow);
Keyboard.addListener('keyboardDidHide', this._handleKeyboardHide);
}
}
componentWillUnmount() {
if (Platform.OS === 'ios') {
Keyboard.removeListener('keyboardWillShow', this._handleKeyboardShow);
Keyboard.removeListener('keyboardWillHide', this._handleKeyboardHide);
} else {
Keyboard.removeListener('keyboardDidShow', this._handleKeyboardShow);
Keyboard.removeListener('keyboardDidHide', this._handleKeyboardHide);
}
}
_handleKeyboardShow = () =>
this.setState({ keyboard: true }, () =>
Animated.timing(this.state.visible, {
toValue: 0,
duration: 150,
useNativeDriver: true,
}).start()
);
_handleKeyboardHide = () =>
Animated.timing(this.state.visible, {
toValue: 1,
duration: 100,
useNativeDriver: true,
}).start(() => {
this.setState({ keyboard: false });
});
btw
this.keyboardWillShowListener
- this -> global context
๐ This issue has been resolved in version 1.0.0 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐
Note that if you set android:windowSoftInputMode to adjustResize or adjustPan, only keyboardDidShow and keyboardDidHide events will be available on Android. If you set android:windowSoftInputMode to adjustNothing, no events will be available on Android.
Remove adjustNothing from your AndroidManifest file