-
Notifications
You must be signed in to change notification settings - Fork 647
Hook to android keyboard events #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8e51404
e229205
7ac2217
bd5a58e
efd7676
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,15 @@ | ||
| /* @flow */ | ||
|
|
||
| import { PropTypes } from 'react' | ||
| import ReactNative, { TextInput, Keyboard } from 'react-native' | ||
| import ReactNative, { TextInput, Keyboard, Platform } from 'react-native' | ||
| import TimerMixin from 'react-timer-mixin' | ||
|
|
||
| const _KAM_DEFAULT_TAB_BAR_HEIGHT = 49 | ||
| const _KAM_KEYBOARD_OPENING_TIME = 250 | ||
| const _KAM_EXTRA_HEIGHT = 75 | ||
|
|
||
| const isAndroid = () => Platform.OS === 'android' | ||
|
|
||
| const KeyboardAwareMixin = { | ||
| mixins: [TimerMixin], | ||
| propTypes: { | ||
|
|
@@ -73,8 +75,12 @@ const KeyboardAwareMixin = { | |
|
|
||
| componentDidMount: function () { | ||
| // Keyboard events | ||
| this.keyboardWillShowEvent = Keyboard.addListener('keyboardWillShow', this.updateKeyboardSpace) | ||
| this.keyboardWillHideEvent = Keyboard.addListener('keyboardWillHide', this.resetKeyboardSpace) | ||
| const events = { | ||
| show: isAndroid() ? 'keyboardDidShow' : 'keyboardWillShow', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change |
||
| hide: isAndroid() ? 'keyboardDidHide' : 'keyboardWillHide', | ||
| } | ||
| this.keyboardWillShowEvent = Keyboard.addListener(events.show, this.updateKeyboardSpace) | ||
| this.keyboardWillHideEvent = Keyboard.addListener(events.hide, this.resetKeyboardSpace) | ||
| }, | ||
|
|
||
| componentWillUnmount: function () { | ||
|
|
@@ -91,6 +97,9 @@ const KeyboardAwareMixin = { | |
| * @param extraHeight: takes an extra height in consideration. | ||
| */ | ||
| scrollToFocusedInput: function (reactNode: Object, extraHeight: number = this.props.extraHeight) { | ||
| // Android already does this | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry but I come from the iOS world and I'm no Android expert. Are you sure that Android does this for every version since 4.2? /cc @jblack10101
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true, not sure about that, I'm going to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But android does not respect the extraHeight. |
||
| if(isAndroid()) return; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not use 1 liner if (isAndroid) {
return
} |
||
|
|
||
| const scrollView = this.refs._rnkasv_keyboardView.getScrollResponder() | ||
| this.setTimeout(() => { | ||
| scrollView.scrollResponderScrollNativeHandleToKeyboard( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to:
It's not necessary to run the function every time you need to check if it's Android or not.