Prop to disable the default pan responder on ScrollView that blocks touches when snapToInterval is enabled (#19110)

Summary:
The ScrollView component seems to have been written for a default touch up / touch down scrolling behavior. However, when using snapToInterval, this default behavior of adding PanResponders while the ScrollView is animating or has an active touch causes bugs with the PanResponder hijacking touches it is not supposed to hijack.
Pull Request resolved: https://github.com/facebook/react-native/pull/19110

Differential Revision: D14071342

Pulled By: hramos

fbshipit-source-id: ac285d9967dd6e2a347943b2455d4f986062ef62
This commit is contained in:
Pim de Witte
2019-02-25 12:10:40 -08:00
committed by Facebook Github Bot
parent fd3db03427
commit 7c4dbd617d
2 changed files with 21 additions and 0 deletions

View File

@@ -141,6 +141,10 @@ const ScrollResponderMixin = {
* Invoke this from an `onScroll` event.
*/
scrollResponderHandleScrollShouldSetResponder: function(): boolean {
// Allow any event touch pass through if the default pan responder is disabled
if (this.props.disableScrollViewPanResponder === true) {
return false;
}
return this.state.isTouching;
},
@@ -172,6 +176,11 @@ const ScrollResponderMixin = {
scrollResponderHandleStartShouldSetResponder: function(
e: PressEvent,
): boolean {
// Allow any event touch pass through if the default pan responder is disabled
if (this.props.disableScrollViewPanResponder === true) {
return false;
}
const currentlyFocusedTextInput = TextInputState.currentlyFocusedField();
if (
@@ -204,6 +213,11 @@ const ScrollResponderMixin = {
return true;
}
// Allow any event touch pass through if the default pan responder is disabled
if (this.props.disableScrollViewPanResponder === true) {
return false;
}
// * the keyboard is up, keyboardShouldPersistTaps is 'never' (the default),
// and a new touch starts with a non-textinput target (in which case the
// first tap should be sent to the scroll view and dismiss the keyboard,

View File

@@ -95,6 +95,13 @@ type IOSProps = $ReadOnly<{|
* @platform ios
*/
bounces?: ?boolean,
/**
* By default, ScrollView has an active pan responder that hijacks panresponders
* deeper in the render tree in order to prevent accidental touches while scrolling.
* However, in certain occasions (such as when using snapToInterval) in a vertical scrollview
* You may want to disable this behavior in order to prevent the ScrollView from blocking touches
*/
disableScrollViewPanResponder?: ?boolean,
/**
* When true, gestures can drive zoom past min/max and the zoom will animate
* to the min/max value at gesture end, otherwise the zoom will not exceed