add pinchEnabled prop to ScrollView

Summary:
When false, ScrollView disables use of pinch gestures to zoom in and out. This allows ScrollView's pinch gesture responder to be disabled to only allow zooming programmatically. The default value is ~false~ true.

**Test Plan**
Tested that pinch gesture responder is disabled when pinchEnabled=false.

/cc  nicklockwood sahrens

🍺
Closes https://github.com/facebook/react-native/pull/10037

Differential Revision: D5491953

Pulled By: shergin

fbshipit-source-id: eae16f92ec616e415b4ddacfccb84c697582daf9
This commit is contained in:
Jake Murzy 2017-08-06 23:44:37 -07:00 committed by Facebook Github Bot
parent 95d5d112ac
commit 614dd077b3
3 changed files with 26 additions and 0 deletions

View File

@ -271,6 +271,12 @@ const ScrollView = createReactClass({
* Note: Vertical pagination is not supported on Android.
*/
pagingEnabled: PropTypes.bool,
/**
* When true, ScrollView allows use of pinch gestures to zoom in and out.
* The default value is true.
* @platform ios
*/
pinchGestureEnabled: PropTypes.bool,
/**
* When false, the view cannot be scrolled via touch interaction.
* The default value is true.

View File

@ -156,6 +156,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
@property (nonatomic, assign) BOOL centerContent;
#if !TARGET_OS_TV
@property (nonatomic, strong) RCTRefreshControl *rctRefreshControl;
@property (nonatomic, assign) BOOL pinchGestureEnabled;
#endif
@end
@ -174,6 +175,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
// scrollbar flip because we also flip it with whole `UIScrollView` flip.
self.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
#if !TARGET_OS_TV
_pinchGestureEnabled = YES;
#endif
}
return self;
}
@ -330,6 +335,20 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
_rctRefreshControl = refreshControl;
[self addSubview:_rctRefreshControl];
}
- (void)setPinchGestureEnabled:(BOOL)pinchGestureEnabled
{
self.pinchGestureRecognizer.enabled = pinchGestureEnabled;
_pinchGestureEnabled = pinchGestureEnabled;
}
- (void)didMoveToWindow
{
[super didMoveToWindow];
// ScrollView enables pinch gesture late in its lifecycle. So simply setting it
// in the setter gets overriden when the view loads.
self.pinchGestureRecognizer.enabled = _pinchGestureEnabled;
}
#endif //TARGET_OS_TV
@end

View File

@ -72,6 +72,7 @@ RCT_EXPORT_VIEW_PROPERTY(minimumZoomScale, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
#if !TARGET_OS_TV
RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
RCT_REMAP_VIEW_PROPERTY(pinchGestureEnabled, scrollView.pinchGestureEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(scrollsToTop, BOOL)
#endif
RCT_EXPORT_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL)