Skip to content

Commit a0c4935

Browse files
committed
Add 'automaticallyAdjustsScrollIndicatorInsets' prop to ScrollView (for iOS)
Summary: In iOS 13 Apple added a new property to UIScrollView that "automatically" alters the scroll indicator insets in a fashion similar to the way 'contentInsetAdjustmentBehavior' alters content insets. See here for iOS documentation: https://developer.apple.com/documentation/uikit/uiscrollview/3198043-automaticallyadjustsscrollindica?language=objc The OS default value for this property is `true`, which we preserve. When set to `false`, the behavior matches iOS <= 12. Closes #28140
1 parent d1ab032 commit a0c4935

File tree

6 files changed

+24
-0
lines changed

6 files changed

+24
-0
lines changed

Libraries/Components/ScrollView/ScrollView.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ type IOSProps = $ReadOnly<{|
171171
* @platform ios
172172
*/
173173
automaticallyAdjustContentInsets?: ?boolean,
174+
/**
175+
* Controls whether iOS should automatically adjust the scroll indicator
176+
* insets. The default value is true. Available on iOS 13 and later.
177+
* @platform ios
178+
*/
179+
automaticallyAdjustsScrollIndicatorInsets?: ?boolean,
174180
/**
175181
* The amount by which the scroll view content is inset from the edges
176182
* of the scroll view. Defaults to `{top: 0, left: 0, bottom: 0, right: 0}`.

Libraries/Components/ScrollView/ScrollViewNativeComponent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ScrollViewNativeComponent: HostComponent<Props> = NativeComponentRegistry.
2626
alwaysBounceHorizontal: true,
2727
alwaysBounceVertical: true,
2828
automaticallyAdjustContentInsets: true,
29+
automaticallyAdjustsScrollIndicatorInsets: true,
2930
bounces: true,
3031
bouncesZoom: true,
3132
canCancelContentTouches: true,

Libraries/Components/ScrollView/ScrollViewNativeComponentType.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type ScrollViewNativeProps = $ReadOnly<{
2121
alwaysBounceHorizontal?: ?boolean,
2222
alwaysBounceVertical?: ?boolean,
2323
automaticallyAdjustContentInsets?: ?boolean,
24+
automaticallyAdjustsScrollIndicatorInsets?: ?boolean,
2425
bounces?: ?boolean,
2526
bouncesZoom?: ?boolean,
2627
canCancelContentTouches?: ?boolean,

Libraries/Components/ScrollView/ScrollViewViewConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const ScrollViewViewConfig = {
2424
alwaysBounceHorizontal: true,
2525
alwaysBounceVertical: true,
2626
automaticallyAdjustContentInsets: true,
27+
automaticallyAdjustsScrollIndicatorInsets: true,
2728
bounces: true,
2829
bouncesZoom: true,
2930
canCancelContentTouches: true,

React/Views/ScrollView/RCTScrollView.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,18 @@ -(type)getter \
928928
RCT_SET_AND_PRESERVE_OFFSET(setZoomScale, zoomScale, CGFloat);
929929
RCT_SET_AND_PRESERVE_OFFSET(setScrollIndicatorInsets, scrollIndicatorInsets, UIEdgeInsets);
930930

931+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
932+
- (void)setAutomaticallyAdjustsScrollIndicatorInsets:(BOOL)automaticallyAdjusts API_AVAILABLE(ios(13.0))
933+
{
934+
// `automaticallyAdjustsScrollIndicatorInsets` is available since iOS 13.
935+
if ([_scrollView respondsToSelector:@selector(setAutomaticallyAdjustsScrollIndicatorInsets:)]) {
936+
if (@available(iOS 13.0, *)) {
937+
_scrollView.automaticallyAdjustsScrollIndicatorInsets = automaticallyAdjusts;
938+
}
939+
}
940+
}
941+
#endif
942+
931943
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
932944
- (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBehavior)behavior API_AVAILABLE(ios(11.0))
933945
{

React/Views/ScrollView/RCTScrollViewManager.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ - (UIView *)view
102102
RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollBegin, RCTDirectEventBlock)
103103
RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollEnd, RCTDirectEventBlock)
104104
RCT_EXPORT_VIEW_PROPERTY(inverted, BOOL)
105+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
106+
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustsScrollIndicatorInsets, BOOL)
107+
#endif
105108
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
106109
RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInsetAdjustmentBehavior)
107110
#endif

0 commit comments

Comments
 (0)