Skip to content

Instantly share code, notes, and snippets.

@grabbou
Last active January 16, 2017 15:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grabbou/ab4981fc7c10ba2b31de to your computer and use it in GitHub Desktop.
Save grabbou/ab4981fc7c10ba2b31de to your computer and use it in GitHub Desktop.
TrackKeyboard
import KeyboardEvents from 'react-native-keyboardevents';
import {
Emitter as KeyboardEventEmitter
} from 'react-native-keyboardevents';
export default {
getInitialState() {
return {
keyboardSpace: 0,
isKeyboardOpened: false
};
},
updateKeyboardSpace(frames) {
this.setState({
keyboardSpace: frames.end.height,
isKeyboardOpened: true
});
},
resetKeyboardSpace() {
this.setState({
keyboardSpace: 0,
isKeyboardOpened: false
});
},
componentDidMount() {
KeyboardEventEmitter.on(KeyboardEvents.KeyboardDidShowEvent, this.updateKeyboardSpace);
KeyboardEventEmitter.on(KeyboardEvents.KeyboardWillHideEvent, this.resetKeyboardSpace);
},
componentWillUnmount() {
KeyboardEventEmitter.off(KeyboardEvents.KeyboardDidShowEvent, this.updateKeyboardSpace);
KeyboardEventEmitter.off(KeyboardEvents.KeyboardWillHideEvent, this.resetKeyboardSpace);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment