Skip to content

Commit dcb3568

Browse files
yuryalvaromb
authored andcommitted
Safe getScrollResponder (#112)
1 parent d6b4d05 commit dcb3568

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/KeyboardAwareMixin.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ const KeyboardAwareMixin = {
5959
// Automatically scroll to focused TextInput
6060
if (this.props.enableAutoAutomaticScroll) {
6161
const currentlyFocusedField = TextInput.State.currentlyFocusedField()
62-
if (!currentlyFocusedField) {
62+
const responder = this.getScrollResponder();
63+
if (!currentlyFocusedField || !responder) {
6364
return
6465
}
6566
UIManager.viewIsDescendantOf(
6667
currentlyFocusedField,
67-
this.getScrollResponder().getInnerViewNode(),
68+
responder.getInnerViewNode(),
6869
(isAncestor) => {
6970
if (isAncestor) {
7071
// Check if the TextInput will be hidden by the keyboard
@@ -115,15 +116,17 @@ const KeyboardAwareMixin = {
115116
},
116117

117118
getScrollResponder() {
118-
return this.refs._rnkasv_keyboardView.getScrollResponder()
119+
return this.refs._rnkasv_keyboardView && this.refs._rnkasv_keyboardView.getScrollResponder()
119120
},
120121

121122
scrollToPosition: function (x: number, y: number, animated: bool = true) {
122-
this.getScrollResponder().scrollResponderScrollTo({x: x, y: y, animated: animated})
123+
const responder = this.getScrollResponder();
124+
responder && responder.scrollResponderScrollTo({x: x, y: y, animated: animated})
123125
},
124126

125127
scrollToEnd: function (animated?: bool = true) {
126-
this.getScrollResponder().scrollResponderScrollToEnd({animated: animated})
128+
const responder = this.getScrollResponder();
129+
responder && responder.scrollResponderScrollToEnd({animated: animated})
127130
},
128131

129132
/**
@@ -134,7 +137,8 @@ const KeyboardAwareMixin = {
134137
extraHeight = this.props.extraHeight;
135138
}
136139
this.setTimeout(() => {
137-
this.getScrollResponder().scrollResponderScrollNativeHandleToKeyboard(
140+
const responder = this.getScrollResponder();
141+
responder && responder.scrollResponderScrollNativeHandleToKeyboard(
138142
reactNode, extraHeight, true
139143
)
140144
}, _KAM_KEYBOARD_OPENING_TIME)

0 commit comments

Comments
 (0)