From 5a6eb22b07d0e33a9bb52141766da9aaa39fef66 Mon Sep 17 00:00:00 2001 From: Hamza Sharawi Date: Sun, 12 Jun 2016 10:47:54 +0300 Subject: [PATCH 1/5] Add an option to stop this module when android --- KeyboardSpacer.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/KeyboardSpacer.js b/KeyboardSpacer.js index 0afba1b..bcfc4f6 100644 --- a/KeyboardSpacer.js +++ b/KeyboardSpacer.js @@ -62,7 +62,7 @@ class KeyboardSpacer extends React.Component { } componentDidMount() { - if (Platform.OS == "android") { + if (Platform.OS == "android" && this.props.android) { this._listeners = [ DeviceEventEmitter.addListener('keyboardDidShow', this.updateKeyboardSpace), DeviceEventEmitter.addListener('keyboardDidHide', this.resetKeyboardSpace) @@ -76,14 +76,18 @@ class KeyboardSpacer extends React.Component { } componentWillUnmount() { - this._listeners.forEach(function(/** EmitterSubscription */listener) { + this._listeners && this._listeners.forEach(function(/** EmitterSubscription */listener) { listener.remove(); }); } render() { - return (); + if (Platform.OS === 'android' && !this.props.android) { return null; } + + return (); } } +KeyboardSpacer.defaultProps = { android: true }; + module.exports = KeyboardSpacer; From 06efc3a61b207cc7d03f7d18b63394efdf5c05e5 Mon Sep 17 00:00:00 2001 From: Hamza Sharawi Date: Sun, 12 Jun 2016 11:03:37 +0300 Subject: [PATCH 2/5] README edit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ee09238..08637ff 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ AppRegistry.registerComponent('DemoApp', () => DemoApp); | :------------ |:---------------:| :---------------:| :-----| | topSpacing | 0 | `number` | Add or subtract additional spacing from keyboard height | | animationConfig | [A default animation](https://github.com/Andr3wHur5t/react-native-keyboard-spacer/blob/expose-layout-animations/KeyboardSpacer.js#L14) | `LayoutAnimationConfig` | [LayoutAnimation](https://facebook.github.io/react-native/docs/layoutanimation.html#content) configuration object | +| android | true | `boolean` | Whether the keyboard should be rendered on android or not (return a view or null) | ### Properties - Methods From afde26cde6e81b2f38db756421b79d1103962cea Mon Sep 17 00:00:00 2001 From: Hamza Sharawi Date: Wed, 27 Jul 2016 11:35:00 +0300 Subject: [PATCH 3/5] After-merge conflicts --- KeyboardSpacer.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/KeyboardSpacer.js b/KeyboardSpacer.js index e626f5b..55de245 100644 --- a/KeyboardSpacer.js +++ b/KeyboardSpacer.js @@ -60,7 +60,8 @@ export default class KeyboardSpacer extends Component { componentDidMount() { const updateListener = Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow'; const resetListener = Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide'; - this._listeners = [ + const listenAndroid = Platform.OS === 'android' && this.props.android; + (listenAndroid || Platform.OS === 'ios') && this._listeners = [ Keyboard.addListener(updateListener, this.updateKeyboardSpace), Keyboard.addListener(resetListener, this.resetKeyboardSpace) ]; @@ -73,7 +74,7 @@ export default class KeyboardSpacer extends Component { } componentWillUnmount() { - this._listeners.forEach(listener => listener.remove()); + this._listeners && this._listeners.forEach(listener => listener.remove()); } updateKeyboardSpace(frames) { @@ -95,6 +96,9 @@ export default class KeyboardSpacer extends Component { } render() { + if (Platform.OS === 'android' && !this.props.android) { + return null; + } return ( ); From 770f4acf938830ebba6b6e6d64f9e41343bb1a51 Mon Sep 17 00:00:00 2001 From: Hamza Sharawi Date: Thu, 28 Jul 2016 13:43:56 +0300 Subject: [PATCH 4/5] saber --- KeyboardSpacer.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/KeyboardSpacer.js b/KeyboardSpacer.js index 55de245..e8adcda 100644 --- a/KeyboardSpacer.js +++ b/KeyboardSpacer.js @@ -61,10 +61,13 @@ export default class KeyboardSpacer extends Component { const updateListener = Platform.OS === 'android' ? 'keyboardDidShow' : 'keyboardWillShow'; const resetListener = Platform.OS === 'android' ? 'keyboardDidHide' : 'keyboardWillHide'; const listenAndroid = Platform.OS === 'android' && this.props.android; - (listenAndroid || Platform.OS === 'ios') && this._listeners = [ - Keyboard.addListener(updateListener, this.updateKeyboardSpace), - Keyboard.addListener(resetListener, this.resetKeyboardSpace) - ]; + const shouldListen = listenAndroid || Platform.OS === 'ios'; + if (shouldListen) { + this._listeners = [ + Keyboard.addListener(updateListener, this.updateKeyboardSpace), + Keyboard.addListener(resetListener, this.resetKeyboardSpace) + ]; + } } componentWillUpdate(props, state) { From 1afb2b9041ca8d904602a7f0da37677b4bd2efbc Mon Sep 17 00:00:00 2001 From: Hamza Sharawi Date: Wed, 25 Oct 2017 17:34:53 +0300 Subject: [PATCH 5/5] fix crash in android --- KeyboardSpacer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/KeyboardSpacer.js b/KeyboardSpacer.js index e8adcda..5f47de4 100644 --- a/KeyboardSpacer.js +++ b/KeyboardSpacer.js @@ -6,6 +6,7 @@ import { Keyboard, LayoutAnimation, View, + ViewPropTypes, Platform, StyleSheet } from 'react-native'; @@ -22,7 +23,7 @@ export default class KeyboardSpacer extends Component { static propTypes = { topSpacing: PropTypes.number, onToggle: PropTypes.func, - style: View.propTypes.style, + style: ViewPropTypes.style, animationConfig: PropTypes.object, android: PropTypes.bool, };