Skip to content

Commit 6e477f3

Browse files
committed
- better handling of scroll to input, also allow to customize the additional offset.
- protection from invalid refs on scroll to input
1 parent 244a6fa commit 6e477f3

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/KeyboardAwareBase.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import React , { Component, PropTypes } from 'react';
44
import ReactNative, {
55
DeviceEventEmitter,
66
Keyboard,
7-
NativeModules
7+
NativeModules,
8+
InteractionManager
89
} from 'react-native';
910

10-
var ScrollViewManager = NativeModules.ScrollViewManager;
11+
const ScrollViewManager = NativeModules.ScrollViewManager;
1112

1213
export default class KeyboardAwareBase extends Component {
1314
constructor(props) {
@@ -78,9 +79,12 @@ export default class KeyboardAwareBase extends Component {
7879
if (this.props.getTextInputRefs) {
7980
const textInputRefs = this.props.getTextInputRefs();
8081
textInputRefs.forEach((textInputRef) => {
81-
if (textInputRef.isFocused()) {
82-
this._keyboardAwareView.getScrollResponder().scrollResponderScrollNativeHandleToKeyboard(
83-
ReactNative.findNodeHandle(textInputRef), 50 + (this.props.scrollOffset || 0), true);
82+
if (textInputRef && textInputRef.isFocused()) {
83+
InteractionManager.runAfterInteractions(() => {
84+
this._keyboardAwareView.getScrollResponder().scrollResponderScrollNativeHandleToKeyboard(
85+
ReactNative.findNodeHandle(textInputRef), this.props.scrollToInputAdditionalOffset, true);
86+
}
87+
);
8488
}
8589
});
8690
}
@@ -129,9 +133,11 @@ export default class KeyboardAwareBase extends Component {
129133

130134
KeyboardAwareBase.propTypes = {
131135
startScrolledToBottom: PropTypes.bool,
132-
scrollToBottomOnKBShow: PropTypes.bool
136+
scrollToBottomOnKBShow: PropTypes.bool,
137+
scrollToInputAdditionalOffset: PropTypes.number
133138
};
134139
KeyboardAwareBase.defaultProps = {
135140
startScrolledToBottom: false,
136-
scrollToBottomOnKBShow: false
141+
scrollToBottomOnKBShow: false,
142+
scrollToInputAdditionalOffset: 75
137143
};

0 commit comments

Comments
 (0)