in vnext/Microsoft.ReactNative/Views/ScrollViewManager.cpp [133:237]
void ScrollViewShadowNode::updateProperties(winrt::Microsoft::ReactNative::JSValueObject &props) {
m_updating = true;
const auto scrollViewer = GetView().as<winrt::ScrollViewer>();
if (scrollViewer == nullptr)
return;
for (const auto &pair : props) {
const std::string &propertyName = pair.first;
const auto &propertyValue = pair.second;
if (propertyName == "horizontal") {
const auto [valid, horizontal] = getPropertyAndValidity(propertyValue, false);
if (valid) {
m_isHorizontal = horizontal;
ScrollViewUWPImplementation(scrollViewer).SetHorizontal(horizontal);
SetScrollMode(scrollViewer);
}
}
if (propertyName == "scrollEnabled") {
const auto [valid, scrollEnabled] = getPropertyAndValidity(propertyValue, true);
if (valid) {
m_isScrollingEnabled = scrollEnabled;
SetScrollMode(scrollViewer);
}
} else if (propertyName == "showsHorizontalScrollIndicator") {
const auto [valid, showsHorizontalScrollIndicator] = getPropertyAndValidity(propertyValue, true);
if (valid) {
scrollViewer.HorizontalScrollBarVisibility(
showsHorizontalScrollIndicator ? winrt::ScrollBarVisibility::Visible : winrt::ScrollBarVisibility::Hidden);
}
} else if (propertyName == "showsVerticalScrollIndicator") {
const auto [valid, showsVerticalScrollIndicator] = getPropertyAndValidity(propertyValue, true);
if (valid) {
scrollViewer.VerticalScrollBarVisibility(
showsVerticalScrollIndicator ? winrt::ScrollBarVisibility::Visible : winrt::ScrollBarVisibility::Hidden);
}
} else if (propertyName == "minimumZoomScale") {
const auto [valid, minimumZoomScale] = getPropertyAndValidity(propertyValue, 1.0);
if (valid) {
scrollViewer.MinZoomFactor(static_cast<float>(minimumZoomScale));
UpdateZoomMode(scrollViewer);
}
} else if (propertyName == "maximumZoomScale") {
const auto [valid, maximumZoomScale] = getPropertyAndValidity(propertyValue, 1.0);
if (valid) {
scrollViewer.MaxZoomFactor(static_cast<float>(maximumZoomScale));
UpdateZoomMode(scrollViewer);
}
} else if (propertyName == "zoomScale") {
const auto [valid, zoomScale] = getPropertyAndValidity(propertyValue, 1.0);
if (valid) {
m_zoomFactor = static_cast<float>(zoomScale);
m_changeViewAfterLoaded = !scrollViewer.ChangeView(nullptr, nullptr, m_zoomFactor);
}
} else if (propertyName == "snapToInterval") {
const auto [valid, snapToInterval] = getPropertyAndValidity(propertyValue, 0.0);
if (valid) {
ScrollViewUWPImplementation(scrollViewer).SnapToInterval(static_cast<float>(snapToInterval));
}
} else if (propertyName == "snapToOffsets") {
if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::Array) {
const auto snapToOffsets = winrt::single_threaded_vector<float>();
for (const auto &val : propertyValue.AsArray()) {
if (val.Type() == winrt::Microsoft::ReactNative::JSValueType::Double ||
val.Type() == winrt::Microsoft::ReactNative::JSValueType::Int64)
snapToOffsets.Append(val.AsSingle());
}
ScrollViewUWPImplementation(scrollViewer).SnapToOffsets(snapToOffsets.GetView());
}
} else if (propertyName == "snapToStart") {
const auto [valid, snaptoStart] = getPropertyAndValidity(propertyValue, true);
if (valid) {
ScrollViewUWPImplementation(scrollViewer).SnapToStart(snaptoStart);
}
} else if (propertyName == "snapToEnd") {
const auto [valid, snapToEnd] = getPropertyAndValidity(propertyValue, true);
if (valid) {
ScrollViewUWPImplementation(scrollViewer).SnapToEnd(snapToEnd);
}
} else if (propertyName == "keyboardDismissMode") {
m_dismissKeyboardOnDrag = false;
if (propertyValue.Type() == winrt::Microsoft::ReactNative::JSValueType::String) {
m_dismissKeyboardOnDrag = (propertyValue.AsString() == "on-drag");
if (m_dismissKeyboardOnDrag) {
m_SIPEventHandler = std::make_unique<SIPEventHandler>(GetViewManager()->GetReactContext());
m_SIPEventHandler->AttachView(GetView(), false /*fireKeyboardEvents*/);
}
}
} else if (propertyName == "snapToAlignment") {
const auto [valid, snapToAlignment] = getPropertyAndValidity(propertyValue, winrt::SnapPointsAlignment::Near);
if (valid) {
ScrollViewUWPImplementation(scrollViewer).SnapPointAlignment(snapToAlignment);
}
} else if (propertyName == "pagingEnabled") {
const auto [valid, pagingEnabled] = getPropertyAndValidity(propertyValue, false);
if (valid) {
ScrollViewUWPImplementation(scrollViewer).PagingEnabled(pagingEnabled);
}
}
}
Super::updateProperties(props);
m_updating = false;
}