Skip to content

Hook to android keyboard events #71

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

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/KeyboardAwareMixin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* @flow */

import { PropTypes } from 'react'
import ReactNative, { TextInput, Keyboard, UIManager } from 'react-native'
import ReactNative, { TextInput, Keyboard, Platform, UIManager } 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: {
Expand Down Expand Up @@ -89,8 +91,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',
hide: isAndroid() ? 'keyboardDidHide' : 'keyboardWillHide',
}
this.keyboardWillShowEvent = Keyboard.addListener(events.show, this.updateKeyboardSpace)
this.keyboardWillHideEvent = Keyboard.addListener(events.hide, this.resetKeyboardSpace)
},

componentWillUnmount: function () {
Expand All @@ -107,6 +113,9 @@ const KeyboardAwareMixin = {
* @param extraHeight: takes an extra height in consideration.
*/
scrollToFocusedInput: function (reactNode: Object, extraHeight: number = this.props.extraHeight) {
// Android already does this
if(isAndroid()) return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android does not use this.props.extraHeight.


const scrollView = this.refs._rnkasv_keyboardView.getScrollResponder()
this.setTimeout(() => {
scrollView.scrollResponderScrollNativeHandleToKeyboard(
Expand Down