Skip to content
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 } 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'
Copy link
Collaborator

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:

const isAndroid = Platform.OS === 'android'

It's not necessary to run the function every time you need to check if it's Android or not.


const KeyboardAwareMixin = {
mixins: [TimerMixin],
propTypes: {
Expand Down Expand Up @@ -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',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change isAndroid() to isAndroid. See previous comment.

hide: isAndroid() ? 'keyboardDidHide' : 'keyboardWillHide',
}
this.keyboardWillShowEvent = Keyboard.addListener(events.show, this.updateKeyboardSpace)
this.keyboardWillHideEvent = Keyboard.addListener(events.hide, this.resetKeyboardSpace)
},

componentWillUnmount: function () {
Expand All @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

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

true, not sure about that, I'm going to check

Choose a reason for hiding this comment

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

But android does not respect the extraHeight.

if(isAndroid()) return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please do not use 1 liner ifs. Change to:

if (isAndroid) {
  return
}


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