Skip to content

Commit 6f4239b

Browse files
mysport12facebook-github-bot
authored andcommittedApr 3, 2019
Add scrollToOverflowEnabled prop to ScrollView (#24296)
Summary: ScrollView's scrollTo behavior on iOS was recently changed to limit the offset to the content size plus any content inset (see #23427). This departure from the old behavior created UI issues for anyone that is using the over-scroll ability for the purpose of positioning elements at specific coordinates on the screen. Examples include using this behavior to position TextInputs above the virtual keyboard programmatically when focused or moving drop down elements positioned near the bottom of the content toward the top of the screen when selected to show a larger absolutely positioned item list. Default behavior does not change and this is an "opt-in" type of prop to re-enable the old behavior. [iOS] [Added] - Added scrollToOverflowEnabled prop to ScrollView Pull Request resolved: #24296 Differential Revision: D14762619 Pulled By: cpojer fbshipit-source-id: d2a552b5cb321d52e8ea4116327bf9ec647a3aae
1 parent 1e2e07d commit 6f4239b

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed
 

‎Libraries/Components/ScrollView/ScrollView.js

+6
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ type IOSProps = $ReadOnly<{|
221221
* @platform ios
222222
*/
223223
scrollIndicatorInsets?: ?EdgeInsetsProp,
224+
/**
225+
* When true, the scroll view can be programmatically scrolled beyond its
226+
* content size. The default value is false.
227+
* @platform ios
228+
*/
229+
scrollToOverflowEnabled?: ?boolean,
224230
/**
225231
* When true, the scroll view scrolls to top when the status bar is tapped.
226232
* The default value is true.

‎React/Views/ScrollView/RCTScrollView.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
@property (nonatomic, assign) NSTimeInterval scrollEventThrottle;
4545
@property (nonatomic, assign) BOOL centerContent;
4646
@property (nonatomic, copy) NSDictionary *maintainVisibleContentPosition;
47+
@property (nonatomic, assign) BOOL scrollToOverflowEnabled;
4748
@property (nonatomic, assign) int snapToInterval;
4849
@property (nonatomic, copy) NSArray<NSNumber *> *snapToOffsets;
4950
@property (nonatomic, assign) BOOL snapToStart;

‎React/Views/ScrollView/RCTScrollView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated
615615
fmax(_scrollView.contentSize.height - _scrollView.bounds.size.height + _scrollView.contentInset.bottom + fmax(_scrollView.contentInset.top, 0), 0.01)); // Make width and height greater than 0
616616
// Ensure at least one scroll event will fire
617617
_allowNextScrollNoMatterWhat = YES;
618-
if (!CGRectContainsPoint(maxRect, offset)) {
618+
if (!CGRectContainsPoint(maxRect, offset) && !self.scrollToOverflowEnabled) {
619619
CGFloat x = fmax(offset.x, CGRectGetMinX(maxRect));
620620
x = fmin(x, CGRectGetMaxX(maxRect));
621621
CGFloat y = fmax(offset.y, CGRectGetMinY(maxRect));

‎React/Views/ScrollView/RCTScrollViewManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ - (UIView *)view
8383
RCT_EXPORT_VIEW_PROPERTY(zoomScale, CGFloat)
8484
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
8585
RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets)
86+
RCT_EXPORT_VIEW_PROPERTY(scrollToOverflowEnabled, BOOL)
8687
RCT_EXPORT_VIEW_PROPERTY(snapToInterval, int)
8788
RCT_EXPORT_VIEW_PROPERTY(snapToOffsets, NSArray<NSNumber *>)
8889
RCT_EXPORT_VIEW_PROPERTY(snapToStart, BOOL)

0 commit comments

Comments
 (0)
Please sign in to comment.