Skip to content

Commit

Permalink
Fabric: Stop ScrollView from scrolling past content (#10652)
Browse files Browse the repository at this point in the history
* Fabric: Stop ScrollView from scrolling past content

* Change files
  • Loading branch information
acoates-ms committed Sep 29, 2022
1 parent 19110d7 commit e3b38c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fabric: Stop ScrollView from scrolling past content",
"packageName": "react-native-windows",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ struct CompScrollerVisual : winrt::Microsoft::ReactNative::Composition::implemen
}

void Size(winrt::Windows::Foundation::Numerics::float2 const &size) noexcept {
m_visualSize = size;
m_visual.Size(size);
UpdateMaxPosition();
}

void Offset(winrt::Windows::Foundation::Numerics::float3 const &offset) noexcept {
Expand Down Expand Up @@ -499,8 +501,9 @@ struct CompScrollerVisual : winrt::Microsoft::ReactNative::Composition::implemen
}

void ContentSize(winrt::Windows::Foundation::Numerics::float2 const &size) noexcept {
m_contentSize = size;
m_contentVisual.Size(size);
m_interactionTracker.MaxPosition({size.x, size.y, 0});
UpdateMaxPosition();
}

winrt::Windows::Foundation::Numerics::float3 ScrollPosition() noexcept {
Expand All @@ -516,6 +519,15 @@ struct CompScrollerVisual : winrt::Microsoft::ReactNative::Composition::implemen
m_scrollPositionChangedEvent(*this, winrt::make<CompScrollPositionChangedArgs>(position));
}

void UpdateMaxPosition() {
m_interactionTracker.MaxPosition(
{std::max<float>(m_contentSize.x - m_visualSize.x, 0),
std::max<float>(m_contentSize.y - m_visualSize.y, 0),
0});
}

winrt::Windows::Foundation::Numerics::float2 m_contentSize{0};
winrt::Windows::Foundation::Numerics::float2 m_visualSize{0};
winrt::event<
winrt::Windows::Foundation::EventHandler<winrt::Microsoft::ReactNative::Composition::ScrollPositionChangedArgs>>
m_scrollPositionChangedEvent;
Expand Down

0 comments on commit e3b38c1

Please sign in to comment.