Skip to content

Commit ee1ac17

Browse files
authored
Merge pull request #1 from astrails/update
fix: crash in RN0.63
2 parents 771535f + b65646a commit ee1ac17

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Diff for: index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export default class extends PureComponent {
7777
};
7878

7979
static defaultProps = {
80+
topOffset: 0,
8081
keyboardOffset: 40,
8182
multilineInputStyle: null,
8283
useAnimatedScrollView: false,
@@ -136,7 +137,9 @@ export default class extends PureComponent {
136137
<View style={styles.wrap}>
137138
<ScrollComponent ref={this._onRef}
138139
onFocus={this._onFocus}
139-
onBlur={this._onBlur} {...otherProps}>
140+
onBlur={this._onBlur} {...otherProps}
141+
// fix missing TextInput missing focus
142+
keyboardShouldPersistTaps='handled'>
140143
<View style={ styles.inScrollComponent} onStartShouldSetResponderCapture={isIOS ? this._onTouchStart : null}>
141144
{newChildren}
142145
<View style={styles.hidden}
@@ -323,7 +326,7 @@ export default class extends PureComponent {
323326

324327
_scrollToKeyboard = (target, offset) => {
325328
const toKeyboardOffset = this._topOffset + this.props.keyboardOffset - offset;
326-
this._root.scrollResponderScrollNativeHandleToKeyboard(target, toKeyboardOffset, true);
329+
this._root.scrollResponderScrollNativeHandleToKeyboard(target, toKeyboardOffset, false); // false to support multiline scroll when a new is entered
327330
};
328331

329332
_onKeyboardShow = () => {
@@ -368,7 +371,8 @@ export default class extends PureComponent {
368371
// 原因可能是系统并未判定 TextInput 获取焦点,这可能是一个 bug
369372
// 通常需要在 onStartShouldSetResponderCapture 返回 false 的情况下再点击一次 TextInput 才能恢复正常
370373
// 所以这里手动再设置一次焦点
371-
focus(target);
374+
// added keyboardShouldPersistTaps='handled' to scroll root instead - shoud fix this issue
375+
// focus(target);
372376

373377
const inputInfo = this._getInputInfo(target);
374378
const multiline = getProps(event._targetInst).multiline;
@@ -469,7 +473,8 @@ function focus(targetTag) {
469473
}
470474

471475
function getTarget(event) {
472-
return event.target ||
476+
return event.nativeEvent.target || // on >= 0.63 target tag can be found on nativeEvent not sure in other versions
477+
event.target ||
473478
event.currentTarget ||
474479
event._targetInst.stateNode._nativeTag; // for Android
475480
}

0 commit comments

Comments
 (0)