Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScrollView.scrollEnabled property #2488

Merged
merged 10 commits into from
Jun 4, 2019
30 changes: 26 additions & 4 deletions vnext/ReactUWP/Views/ScrollViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ class ScrollViewShadowNode : public ShadowNodeBase
const char* eventName,
double x, double y, double zoom);
template <typename T> std::tuple<bool, T> getPropertyAndValidity(folly::dynamic propertyValue, T defaultValue);
void SetScrollMode(const winrt::ScrollViewer& scrollViewer);

float m_zoomFactor{ 1.0f };
bool m_isScrollingFromInertia = false;
bool m_isScrolling = false;

bool m_isHorizontal = false;
bool m_isScrollingEnabled = true;

winrt::FrameworkElement::SizeChanged_revoker m_scrollViewerSizeChangedRevoker{};
winrt::FrameworkElement::SizeChanged_revoker m_contentSizeChangedRevoker{};
winrt::ScrollViewer::ViewChanged_revoker m_scrollViewerViewChangedRevoker{};
Expand Down Expand Up @@ -129,9 +132,18 @@ void ScrollViewShadowNode::updateProperties(const folly::dynamic&& reactDiffMap)
const auto [valid, horizontal] = getPropertyAndValidity(propertyValue, false);
if (valid)
{
scrollViewer.HorizontalScrollMode(horizontal ? winrt::ScrollMode::Auto : winrt::ScrollMode::Disabled);
scrollViewer.VerticalScrollMode(horizontal ? winrt::ScrollMode::Disabled : winrt::ScrollMode::Auto);
m_isHorizontal = horizontal;
ScrollViewUWPImplementation(scrollViewer).SetHorizontal(horizontal);
SetScrollMode(scrollViewer);
}
}
if (propertyName == "scrollEnabled")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if [](start = 4, length = 2)

else if

{
const auto [valid, scrollEnabled] = getPropertyAndValidity(propertyValue, true);
if (valid)
{
m_isScrollingEnabled = scrollEnabled;
SetScrollMode(scrollViewer);
}
}
else if (propertyName == "showsHorizontalScrollIndicator")
Expand Down Expand Up @@ -413,6 +425,14 @@ std::tuple<bool, T> ScrollViewShadowNode::getPropertyAndValidity(folly::dynamic
return std::make_tuple(false, defaultValue);
}

void ScrollViewShadowNode::SetScrollMode(const winrt::ScrollViewer& scrollViewer)
{
const auto horizontalScrollingEnabled = m_isScrollingEnabled && m_isHorizontal;
const auto verticalScrollingEnabled = m_isScrollingEnabled && !m_isHorizontal;
scrollViewer.HorizontalScrollMode(horizontalScrollingEnabled ? winrt::ScrollMode::Auto : winrt::ScrollMode::Disabled);
scrollViewer.VerticalScrollMode(verticalScrollingEnabled ? winrt::ScrollMode::Auto : winrt::ScrollMode::Disabled);
}

ScrollViewManager::ScrollViewManager(const std::shared_ptr<IReactInstance>& reactInstance)
: Super(reactInstance)
{
Expand All @@ -425,6 +445,7 @@ const char* ScrollViewManager::GetName() const

folly::dynamic ScrollViewManager::GetCommands() const
{

auto commands = Super::GetCommands();
commands.update(folly::dynamic::object
("scrollTo", static_cast<std::underlying_type_t<ScrollViewCommands>>(ScrollViewCommands::ScrollTo))
Expand All @@ -439,6 +460,7 @@ folly::dynamic ScrollViewManager::GetNativeProps() const

props.update(folly::dynamic::object
("horizontal", "boolean")
("scrollEnabled", "boolean")
("showsHorizontalScrollIndicator", "boolean")
("showsVerticalScrollIndicator", "boolean")
("minimumZoomScale", "float")
Expand Down Expand Up @@ -468,7 +490,7 @@ folly::dynamic ScrollViewManager::GetExportedCustomDirectEventTypeConstants() co

return directEvents;
}

XamlView ScrollViewManager::CreateViewCore(int64_t tag)
{
const auto scrollViewer = [this]()
Expand Down