Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Implement decelerationRate in ScrollView",
"packageName": "react-native-windows",
"email": "54227869+anupriya13@users.noreply.github.com",
"dependentChangeType": "patch"
}
3 changes: 2 additions & 1 deletion packages/playground/Samples/scrollViewSnapSample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ export default class Bootstrap extends React.Component<{}, any> {
}}
onScroll={() => {
console.log('onScroll');
}}>
}}
decelerationRate={0.95}>
{this.makeItems(20, [styles.itemWrapper])}
</ScrollView>
</View>
Expand Down
1 change: 1 addition & 0 deletions vnext/Microsoft.ReactNative/CompositionSwitcher.idl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ namespace Microsoft.ReactNative.Composition.Experimental
void ScrollBy(Windows.Foundation.Numerics.Vector3 offset, Boolean animate);
void TryUpdatePosition(Windows.Foundation.Numerics.Vector3 position, Boolean animate);
void OnPointerPressed(Microsoft.ReactNative.Composition.Input.PointerRoutedEventArgs args);
void SetDecelerationRate(Windows.Foundation.Numerics.Vector3 decelerationRate);
Boolean Horizontal;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,10 @@ struct CompScrollerVisual : winrt::implements<
UpdateInteractionModes();
}

void SetDecelerationRate(winrt::Windows::Foundation::Numerics::float3 const &decelerationRate) noexcept {
m_interactionTracker.PositionInertiaDecayRate(decelerationRate);
}

void Opacity(float opacity) noexcept {
m_visual.Opacity(opacity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,10 @@ void ScrollViewComponentView::updateProps(
if (!oldProps || oldViewProps.horizontal != newViewProps.horizontal) {
m_scrollVisual.Horizontal(newViewProps.horizontal);
}

if (!oldProps || oldViewProps.decelerationRate != newViewProps.decelerationRate) {
updateDecelerationRate(newViewProps.decelerationRate);
}
}

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

void ScrollViewComponentView::updateDecelerationRate(float value) noexcept {
m_scrollVisual.SetDecelerationRate({value, value, value});
}
} // namespace winrt::Microsoft::ReactNative::Composition::implementation
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
double getHorizontalSize() noexcept;

private:
void updateDecelerationRate(float value) noexcept;
void updateContentVisualSize() noexcept;
bool scrollToEnd(bool animate) noexcept;
bool scrollToStart(bool animate) noexcept;
Expand Down
Loading