Skip to content

Commit

Permalink
Fix keyboardDismissMode="on-drag" on Android (#31943)
Browse files Browse the repository at this point in the history
Summary:
Fixes #23364

The current logic using `_isTouching` does not work because `_handleTouchCancel` is always called before scroll events begin. This means `_isTouching` is always false. To fix it I moved the logic to `_handleScrollBeginDrag` which is only called once when scroll drag beings. This accomplishes the expected behavior and is better than keeping it in onScroll where it would be called for each scroll event.

## Changelog

[Android] [Fixed] - Fix keyboardDismissMode="on-drag" on Android

Pull Request resolved: #31943

Test Plan: Tested in an app that on-drag does not work before and works after this patch.

Reviewed By: sshic

Differential Revision: D30674276

Pulled By: yungsters

fbshipit-source-id: aa0bd605809fa01518f70fbf323c06e32c76ed1d
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Sep 2, 2021
1 parent a40f973 commit 7edf927
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -1178,11 +1178,6 @@ class ScrollView extends React.Component<Props, State> {
);
}
}
if (Platform.OS === 'android') {
if (this.props.keyboardDismissMode === 'on-drag' && this._isTouching) {
dismissKeyboard();
}
}
this._observedScrollSinceBecomingResponder = true;
this.props.onScroll && this.props.onScroll(e);
};
Expand Down Expand Up @@ -1299,6 +1294,14 @@ class ScrollView extends React.Component<Props, State> {
*/
_handleScrollBeginDrag: (e: ScrollEvent) => void = (e: ScrollEvent) => {
FrameRateLogger.beginScroll(); // TODO: track all scrolls after implementing onScrollEndAnimation

if (
Platform.OS === 'android' &&
this.props.keyboardDismissMode === 'on-drag'
) {
dismissKeyboard();
}

this.props.onScrollBeginDrag && this.props.onScrollBeginDrag(e);
};

Expand Down

0 comments on commit 7edf927

Please sign in to comment.