Permalink
Browse files

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 #10037

Differential Revision: D5491953

Pulled By: shergin

fbshipit-source-id: eae16f92ec616e415b4ddacfccb84c697582daf9
  • Loading branch information...
jmurzy authored and facebook-github-bot committed Aug 7, 2017
1 parent 95d5d11 commit 614dd077b3621d73a7fd56e0026b8b840bbe625e
@@ -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
*/

This comment has been minimized.

Show comment
Hide comment
@chirag04

chirag04 Aug 7, 2017

Collaborator

isn't this a breaking change? y not default to false?

@jmurzy @shergin ?

@chirag04

chirag04 Aug 7, 2017

Collaborator

isn't this a breaking change? y not default to false?

@jmurzy @shergin ?

This comment has been minimized.

Show comment
Hide comment
@shergin

shergin Aug 7, 2017

Contributor

It should be (and it is, and it always was) true by default. No?

@shergin

shergin Aug 7, 2017

Contributor

It should be (and it is, and it always was) true by default. No?

pinchGestureEnabled: PropTypes.bool,
/**
* When false, the view cannot be scrolled via touch interaction.
* The default value is true.
@@ -156,6 +156,7 @@ @interface RCTCustomScrollView : UIScrollView<UIGestureRecognizerDelegate>
@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 @@ - (instancetype)initWithFrame:(CGRect)frame
// 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 @@ - (void)setRctRefreshControl:(RCTRefreshControl *)refreshControl
_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
@@ -72,6 +72,7 @@ - (UIView *)view
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)

0 comments on commit 614dd07

Please sign in to comment.