Skip to content

Commit e3ac329

Browse files
mysport12grabbou
authored andcommitted
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 17292c9 commit e3ac329

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

Libraries/Components/ScrollView/ScrollView.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ type IOSProps = $ReadOnly<{|
210210
* @platform ios
211211
*/
212212
scrollIndicatorInsets?: ?EdgeInsetsProp,
213+
/**
214+
* When true, the scroll view can be programmatically scrolled beyond its
215+
* content size. The default value is false.
216+
* @platform ios
217+
*/
218+
scrollToOverflowEnabled?: ?boolean,
213219
/**
214220
* When true, the scroll view scrolls to top when the status bar is tapped.
215221
* The default value is true.

React/Views/ScrollView/RCTScrollView.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated
594594
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
595595
// Ensure at least one scroll event will fire
596596
_allowNextScrollNoMatterWhat = YES;
597-
if (!CGRectContainsPoint(maxRect, offset)) {
597+
if (!CGRectContainsPoint(maxRect, offset) && !self.scrollToOverflowEnabled) {
598598
CGFloat x = fmax(offset.x, CGRectGetMinX(maxRect));
599599
x = fmin(x, CGRectGetMaxX(maxRect));
600600
CGFloat y = fmax(offset.y, CGRectGetMinY(maxRect));

React/Views/ScrollView/RCTScrollViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ - (UIView *)view
8080
RCT_EXPORT_VIEW_PROPERTY(zoomScale, CGFloat)
8181
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
8282
RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets)
83+
RCT_EXPORT_VIEW_PROPERTY(scrollToOverflowEnabled, BOOL)
8384
RCT_EXPORT_VIEW_PROPERTY(snapToInterval, int)
8485
RCT_EXPORT_VIEW_PROPERTY(snapToOffsets, NSArray<NSNumber *>)
8586
RCT_EXPORT_VIEW_PROPERTY(snapToStart, BOOL)

0 commit comments

Comments
 (0)