Skip to content

Commit e3da810

Browse files
authored
[Fabric] Implement decelerationRate in ScrollView (#14528)
1 parent 7777a30 commit e3da810

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
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 decelerationRate in ScrollView",
4+
"packageName": "react-native-windows",
5+
"email": "54227869+anupriya13@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

packages/playground/Samples/scrollViewSnapSample.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ export default class Bootstrap extends React.Component<{}, any> {
251251
}}
252252
onScroll={() => {
253253
console.log('onScroll');
254-
}}>
254+
}}
255+
decelerationRate={0.95}>
255256
{this.makeItems(20, [styles.itemWrapper])}
256257
</ScrollView>
257258
</View>

vnext/Microsoft.ReactNative/CompositionSwitcher.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ namespace Microsoft.ReactNative.Composition.Experimental
115115
void ScrollBy(Windows.Foundation.Numerics.Vector3 offset, Boolean animate);
116116
void TryUpdatePosition(Windows.Foundation.Numerics.Vector3 position, Boolean animate);
117117
void OnPointerPressed(Microsoft.ReactNative.Composition.Input.PointerRoutedEventArgs args);
118+
void SetDecelerationRate(Windows.Foundation.Numerics.Vector3 decelerationRate);
118119
Boolean Horizontal;
119120
}
120121

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,10 @@ struct CompScrollerVisual : winrt::implements<
836836
UpdateInteractionModes();
837837
}
838838

839+
void SetDecelerationRate(winrt::Windows::Foundation::Numerics::float3 const &decelerationRate) noexcept {
840+
m_interactionTracker.PositionInertiaDecayRate(decelerationRate);
841+
}
842+
839843
void Opacity(float opacity) noexcept {
840844
m_visual.Opacity(opacity);
841845
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,10 @@ void ScrollViewComponentView::updateProps(
753753
if (!oldProps || oldViewProps.horizontal != newViewProps.horizontal) {
754754
m_scrollVisual.Horizontal(newViewProps.horizontal);
755755
}
756+
757+
if (!oldProps || oldViewProps.decelerationRate != newViewProps.decelerationRate) {
758+
updateDecelerationRate(newViewProps.decelerationRate);
759+
}
756760
}
757761

758762
void ScrollViewComponentView::updateState(
@@ -1316,4 +1320,7 @@ double ScrollViewComponentView::getHorizontalSize() noexcept {
13161320
return std::min((m_layoutMetrics.frame.size.width / m_contentSize.width * 100.0), 100.0);
13171321
}
13181322

1323+
void ScrollViewComponentView::updateDecelerationRate(float value) noexcept {
1324+
m_scrollVisual.SetDecelerationRate({value, value, value});
1325+
}
13191326
} // namespace winrt::Microsoft::ReactNative::Composition::implementation

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
119119
double getHorizontalSize() noexcept;
120120

121121
private:
122+
void updateDecelerationRate(float value) noexcept;
122123
void updateContentVisualSize() noexcept;
123124
bool scrollToEnd(bool animate) noexcept;
124125
bool scrollToStart(bool animate) noexcept;

0 commit comments

Comments
 (0)