Skip to content

Add minPointers prop to ScrollView component #939

@naquilini

Description

@naquilini

Introduction

ScrollView component currently does not support the activation of scroll gesture only when 2 fingers (or more) moves on the screen. The ScrollView (if scroll enabled) always activates when a single gingers moves on the screen.

Details

The underlying native components could already support that.
For instance, in iOS a change like the following in the native code could add the support to minPointers:

diff --git a/node_modules/react-native/React/Views/ScrollView/RCTScrollView.h b/node_modules/react-native/React/Views/ScrollView/RCTScrollView.h
index 10ef46a..a7f74bb 100644
--- a/node_modules/react-native/React/Views/ScrollView/RCTScrollView.h
+++ b/node_modules/react-native/React/Views/ScrollView/RCTScrollView.h
@@ -48,6 +48,7 @@
 @property (nonatomic, assign) BOOL snapToEnd;
 @property (nonatomic, copy) NSString *snapToAlignment;
 @property (nonatomic, assign) BOOL inverted;
+@property (nonatomic, assign) int minPointers;
 /** Focus area of newly-activated text input relative to the window to compare against UIKeyboardFrameBegin/End */
 @property (nonatomic, assign) CGRect firstResponderFocus;
 /** newly-activated text input outside of the scroll view */
diff --git a/node_modules/react-native/React/Views/ScrollView/RCTScrollView.m b/node_modules/react-native/React/Views/ScrollView/RCTScrollView.m
index 6f41b5c..8612ba6 100644
--- a/node_modules/react-native/React/Views/ScrollView/RCTScrollView.m
+++ b/node_modules/react-native/React/Views/ScrollView/RCTScrollView.m
@@ -477,6 +477,9 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps
   if ([changedProps containsObject:@"contentSize"]) {
     [self updateContentSizeIfNeeded];
   }
+  if ([changedProps containsObject:@"minPointers"]) {
+    _scrollView.panGestureRecognizer.minimumNumberOfTouches = self.minPointers;
+  }
 }
 
 - (BOOL)centerContent
diff --git a/node_modules/react-native/React/Views/ScrollView/RCTScrollViewManager.m b/node_modules/react-native/React/Views/ScrollView/RCTScrollViewManager.m
index cd1e7eb..607d498 100644
--- a/node_modules/react-native/React/Views/ScrollView/RCTScrollViewManager.m
+++ b/node_modules/react-native/React/Views/ScrollView/RCTScrollViewManager.m
@@ -101,6 +101,7 @@ - (UIView *)view
 RCT_EXPORT_VIEW_PROPERTY(inverted, BOOL)
 RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustsScrollIndicatorInsets, BOOL)
 RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInsetAdjustmentBehavior)
+RCT_EXPORT_VIEW_PROPERTY(minPointers, int)
 
 // overflow is used both in css-layout as well as by react-native. In css-layout
 // we always want to treat overflow as scroll but depending on what the overflow
```

### Discussion points

- was there a specific reason why a `minPointers` prop was not implemented?
- is there another way to achieve the desired response to user touch gestures to achieve the desired effect?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions