From bd1516e4adf1e4f2463f8231ba5dfeb6971f80da Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Thu, 12 Jan 2023 16:20:36 -0800 Subject: [PATCH 01/11] Don't compute additional horizontal padding for indicator if the content view is empty This was causing default padding when height was 0 --- React/Views/ScrollView/RCTScrollContentView.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/React/Views/ScrollView/RCTScrollContentView.m b/React/Views/ScrollView/RCTScrollContentView.m index 1e2d25658fab09..0ef8a23f802729 100644 --- a/React/Views/ScrollView/RCTScrollContentView.m +++ b/React/Views/ScrollView/RCTScrollContentView.m @@ -51,7 +51,8 @@ - (void)reactSetFrame:(CGRect)frame // the contents will overflow causing the scroll indicators to appear unnecessarily. NSScrollView *platformScrollView = [scrollView scrollView]; if ([platformScrollView scrollerStyle] == NSScrollerStyleLegacy) { - CGFloat horizontalScrollerHeight = [platformScrollView hasHorizontalScroller] ? NSHeight([[platformScrollView horizontalScroller] frame]) : 0; + BOOL hasHorizontalScrollerAndNotEmpty = [platformScrollView hasHorizontalScroller] && platformScrollView.documentView.frame.size.height > 0; + CGFloat horizontalScrollerHeight = hasHorizontalScrollerAndNotEmpty ? NSHeight([[platformScrollView horizontalScroller] frame]) : 0; CGFloat verticalScrollerWidth = [platformScrollView hasVerticalScroller] ? NSWidth([[platformScrollView verticalScroller] frame]) : 0; RCTScrollContentLocalData *localData = From 1669e39e3626e0cdb19ca31f6a1bec271263fa36 Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Thu, 12 Jan 2023 16:24:49 -0800 Subject: [PATCH 02/11] Switch the horizontal/vertical scroller size These were both returning the same value so masked the bug --- React/Views/ScrollView/RCTScrollContentView.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/React/Views/ScrollView/RCTScrollContentView.m b/React/Views/ScrollView/RCTScrollContentView.m index 0ef8a23f802729..3080b42d5de15d 100644 --- a/React/Views/ScrollView/RCTScrollContentView.m +++ b/React/Views/ScrollView/RCTScrollContentView.m @@ -55,10 +55,8 @@ - (void)reactSetFrame:(CGRect)frame CGFloat horizontalScrollerHeight = hasHorizontalScrollerAndNotEmpty ? NSHeight([[platformScrollView horizontalScroller] frame]) : 0; CGFloat verticalScrollerWidth = [platformScrollView hasVerticalScroller] ? NSWidth([[platformScrollView verticalScroller] frame]) : 0; - RCTScrollContentLocalData *localData = - [[RCTScrollContentLocalData alloc] - initWithVerticalScrollerWidth:horizontalScrollerHeight - horizontalScrollerHeight:verticalScrollerWidth]; + RCTScrollContentLocalData *localData = [[RCTScrollContentLocalData alloc] initWithVerticalScrollerWidth:verticalScrollerWidth horizontalScrollerHeight:horizontalScrollerHeight]; + [[[scrollView bridge] uiManager] setLocalData:localData forView:self]; } From 176a118d4b1f90622ecb870833bd76c9bd9c06ae Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Thu, 12 Jan 2023 16:31:25 -0800 Subject: [PATCH 03/11] Split up inset examples to be vertical/horizontal --- .../examples/ScrollView/ScrollViewExample.js | 72 +++++++++++++++---- 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js b/packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js index 6077bd8540fb88..3a243a02cfaf7a 100644 --- a/packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js +++ b/packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js @@ -253,10 +253,17 @@ const examples = ([ }, }, { - title: ' Scroll Indicator\n', - description: 'Adjust properties of the scroll indicator.', + title: ' Vertical Scroll Indicator\n', + description: 'Adjust properties of the vertical scroll indicator.', render: function (): React.Node { - return ; + return ; + }, + }, + { + title: ' Horizontal Scroll Indicator\n', + description: 'Adjust properties of the horizontal scroll indicator.', + render: function (): React.Node { + return ; }, }, { @@ -700,7 +707,7 @@ const ScrollToOptions = () => { ); }; -const ScrollIndicatorExample = () => { +const ScrollIndicatorVerticalExample = () => { const [scrollIndicatorInsets, setScrollIndicatorInsets] = useState(null); const [showsHorizontalScrollIndic, setShowsHorizontalScrollIndic] = useState(true); @@ -712,7 +719,6 @@ const ScrollIndicatorExample = () => { style={[styles.scrollView, {height: 200}]} contentInset={{top: 10, bottom: 10, left: 10, right: 10}} scrollIndicatorInsets={scrollIndicatorInsets} - showsHorizontalScrollIndicator={showsHorizontalScrollIndic} showsVerticalScrollIndicator={showsVerticallScrollIndic} nestedScrollEnabled> {ITEMS.map(createItemRow)} @@ -726,29 +732,65 @@ const ScrollIndicatorExample = () => { onPress={() => scrollIndicatorInsets == null ? setScrollIndicatorInsets({ - top: 10, - left: 10, - bottom: 10, - right: 10, + top: 0, + left: 0, + bottom: 0, + right: 0, }) : setScrollIndicatorInsets(null) } />