Skip to content

Commit eed307a

Browse files
author
alvaromb
committed
A version with the RN ancestor stuff
1 parent 160974f commit eed307a

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

lib/KeyboardAwareListView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const KeyboardAwareListView = React.createClass({
2020
this.setResetScrollToCoords(this.props.resetScrollToCoords)
2121
},
2222

23+
getScrollHandle: function () {
24+
return this.refs._rnkasv_keyboardView
25+
},
26+
2327
render: function () {
2428
return (
2529
<ListView

lib/KeyboardAwareMixin.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

33
import { PropTypes } from 'react'
4-
import ReactNative, { TextInput, Keyboard } from 'react-native'
4+
import ReactNative, { TextInput, Keyboard, UIManager } from 'react-native'
55
import TimerMixin from 'react-timer-mixin'
66

77
const _KAM_DEFAULT_TAB_BAR_HEIGHT = 49
@@ -49,14 +49,15 @@ const KeyboardAwareMixin = {
4949
// Automatically scroll to focused TextInput
5050
if (this.props.enableAutoAutomaticScroll) {
5151
const currentlyFocusedField = TextInput.State.currentlyFocusedField()
52-
if (!currentlyFocusedField) {
53-
return
54-
}
55-
try {
56-
this.scrollToFocusedInputWithNodeHandle(currentlyFocusedField)
57-
} catch (e) {
58-
59-
}
52+
UIManager.viewIsAncestorOf(
53+
currentlyFocusedField,
54+
this.getScrollHandle().getScrollResponder().getInnerViewNode(),
55+
(isAncestor) => {
56+
if (isAncestor) {
57+
this.scrollToFocusedInputWithNodeHandle(currentlyFocusedField)
58+
}
59+
}
60+
)
6061
}
6162
},
6263

lib/KeyboardAwareScrollView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const KeyboardAwareScrollView = React.createClass({
2020
this.setResetScrollToCoords(this.props.resetScrollToCoords)
2121
},
2222

23+
getScrollHandle: function () {
24+
return this.refs._rnkasv_keyboardView
25+
},
26+
2327
render: function () {
2428
return (
2529
<ScrollView

0 commit comments

Comments
 (0)