Skip to content

Commit 2de7198

Browse files
authored
[Fabric] Implement showsVerticalScrollIndicatorValue and showsHorizontalScrollIndicatorValue for ScrollView (#14526)
1 parent e3da810 commit 2de7198

File tree

4 files changed

+97
-8
lines changed

4 files changed

+97
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Implement showsVerticalScrollIndicatorValue and showsVerticalScrollIndicatorValue for ScrollView",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/playground/Samples/scrollViewSnapSample.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export default class Bootstrap extends React.Component<{}, any> {
3333
keyboardDismiss: false,
3434
snapToOffsets: true,
3535
pagingEnabled: false,
36+
showsHorizontalScrollIndicatorValue: true,
37+
showsVerticalScrollIndicatorValue: false,
3638
};
3739

3840
toggleSwitch1 = (value: boolean) => {
@@ -67,6 +69,14 @@ export default class Bootstrap extends React.Component<{}, any> {
6769
this.setState({keyboardDismiss: value});
6870
};
6971

72+
toggleSwitch9 = (value: boolean) => {
73+
this.setState({showsHorizontalScrollIndicatorValue: value});
74+
};
75+
76+
toggleSwitch10 = (value: boolean) => {
77+
this.setState({showsVerticalScrollIndicatorValue: value});
78+
};
79+
7080
onRefresh = () => {
7181
this.setState({refreshing: true});
7282
void wait(2000).then(() => this.setState({refreshing: false}));
@@ -109,6 +119,42 @@ export default class Bootstrap extends React.Component<{}, any> {
109119
value={this.state.horizontalValue}
110120
/>
111121
</View>
122+
<View
123+
style={{
124+
flexDirection: 'column',
125+
alignSelf: 'stretch',
126+
justifyContent: 'center',
127+
padding: 20,
128+
}}>
129+
<Text>
130+
{' '}
131+
{this.state.showsHorizontalScrollIndicatorValue
132+
? 'Show Horizontal Indicator'
133+
: 'Hide Horizontal Indicator'}
134+
</Text>
135+
<Switch
136+
onValueChange={this.toggleSwitch9}
137+
value={this.state.showsHorizontalScrollIndicatorValue}
138+
/>
139+
</View>
140+
<View
141+
style={{
142+
flexDirection: 'column',
143+
alignSelf: 'stretch',
144+
justifyContent: 'center',
145+
padding: 20,
146+
}}>
147+
<Text>
148+
{' '}
149+
{this.state.showsVerticalScrollIndicatorValue
150+
? 'Show Vertical Indicator'
151+
: 'Hide Vertical Indicator'}
152+
</Text>
153+
<Switch
154+
onValueChange={this.toggleSwitch10}
155+
value={this.state.showsVerticalScrollIndicatorValue}
156+
/>
157+
</View>
112158
<View
113159
style={{
114160
flexDirection: 'column',
@@ -246,6 +292,12 @@ export default class Bootstrap extends React.Component<{}, any> {
246292
snapToEnd={this.state.snapToEndValue}
247293
snapToAlignment={this.state.alignToStartValue ? 'start' : 'end'}
248294
horizontal={this.state.horizontalValue}
295+
showsHorizontalScrollIndicator={
296+
this.state.showsHorizontalScrollIndicatorValue
297+
}
298+
showsVerticalScrollIndicator={
299+
this.state.showsVerticalScrollIndicatorValue
300+
}
249301
onScrollBeginDrag={() => {
250302
console.log('onScrollBeginDrag');
251303
}}

vnext/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct ScrollBarComponent {
8383
void ContentSize(winrt::Windows::Foundation::Size contentSize) noexcept {
8484
m_contentSize = contentSize;
8585
updateThumb();
86-
updateVisibility();
86+
updateVisibility(m_visible);
8787
}
8888

8989
void updateTrack() noexcept {
@@ -108,21 +108,25 @@ struct ScrollBarComponent {
108108

109109
updateTrack();
110110
updateThumb();
111-
updateVisibility();
111+
updateVisibility(m_visible);
112112
}
113113

114-
void updateVisibility() noexcept {
114+
void updateVisibility(bool visible) noexcept {
115+
if (!visible) {
116+
m_visible = false;
117+
m_rootVisual.IsVisible(visible);
118+
return;
119+
}
120+
115121
bool newVisibility = false;
116122
if (m_vertical) {
117123
newVisibility = (m_contentSize.Height > m_size.Height);
118124
} else {
119125
newVisibility = (m_contentSize.Width > m_size.Width);
120126
}
121127

122-
if (newVisibility != m_visible) {
123-
m_visible = newVisibility;
124-
m_rootVisual.IsVisible(m_visible);
125-
}
128+
m_visible = newVisibility;
129+
m_rootVisual.IsVisible(m_visible);
126130
}
127131

128132
void updateRootAndArrowVisualOffsets() noexcept {
@@ -561,7 +565,7 @@ struct ScrollBarComponent {
561565
winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext m_compContext;
562566
winrt::Microsoft::ReactNative::ReactContext m_reactContext;
563567
const bool m_vertical;
564-
bool m_visible{false};
568+
bool m_visible{true};
565569
bool m_shy{false};
566570
int m_thumbSize{0};
567571
float m_arrowSize{0};
@@ -754,6 +758,14 @@ void ScrollViewComponentView::updateProps(
754758
m_scrollVisual.Horizontal(newViewProps.horizontal);
755759
}
756760

761+
if (!oldProps || oldViewProps.showsHorizontalScrollIndicator != newViewProps.showsHorizontalScrollIndicator) {
762+
updateShowsHorizontalScrollIndicator(newViewProps.showsHorizontalScrollIndicator);
763+
}
764+
765+
if (!oldProps || oldViewProps.showsVerticalScrollIndicator != newViewProps.showsVerticalScrollIndicator) {
766+
updateShowsVerticalScrollIndicator(newViewProps.showsVerticalScrollIndicator);
767+
}
768+
757769
if (!oldProps || oldViewProps.decelerationRate != newViewProps.decelerationRate) {
758770
updateDecelerationRate(newViewProps.decelerationRate);
759771
}
@@ -1320,6 +1332,22 @@ double ScrollViewComponentView::getHorizontalSize() noexcept {
13201332
return std::min((m_layoutMetrics.frame.size.width / m_contentSize.width * 100.0), 100.0);
13211333
}
13221334

1335+
void ScrollViewComponentView::updateShowsHorizontalScrollIndicator(bool value) noexcept {
1336+
if (value) {
1337+
m_horizontalScrollbarComponent->updateVisibility(true);
1338+
} else {
1339+
m_horizontalScrollbarComponent->updateVisibility(false);
1340+
}
1341+
}
1342+
1343+
void ScrollViewComponentView::updateShowsVerticalScrollIndicator(bool value) noexcept {
1344+
if (value) {
1345+
m_verticalScrollbarComponent->updateVisibility(true);
1346+
} else {
1347+
m_verticalScrollbarComponent->updateVisibility(false);
1348+
}
1349+
}
1350+
13231351
void ScrollViewComponentView::updateDecelerationRate(float value) noexcept {
13241352
m_scrollVisual.SetDecelerationRate({value, value, value});
13251353
}

vnext/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
129129
bool scrollRight(float delta, bool animate) noexcept;
130130
void updateBackgroundColor(const facebook::react::SharedColor &color) noexcept;
131131
void updateStateWithContentOffset() noexcept;
132+
void updateShowsHorizontalScrollIndicator(bool value) noexcept;
133+
void updateShowsVerticalScrollIndicator(bool value) noexcept;
132134

133135
facebook::react::Size m_contentSize;
134136
winrt::Microsoft::ReactNative::Composition::Experimental::IScrollVisual m_scrollVisual{nullptr};

0 commit comments

Comments
 (0)