From c6e5640e87e7cb5b514ded2c8d4cbb039bd02c5f Mon Sep 17 00:00:00 2001 From: David Vacca Date: Wed, 29 Sep 2021 01:46:07 -0700 Subject: [PATCH] Add snapToAlignment to ReactScrollViewManager Summary: This diff adds the new snapToAlignment into ReactScrollViewManager changelog: [Android][Added] Implement snapToAlignment into ReactScrollViewManager Reviewed By: JoshuaGross Differential Revision: D31182787 fbshipit-source-id: 8049ceb462461a11f184dbc1b40ca8079a3e8b60 --- .../com/facebook/react/views/scroll/ReactScrollView.java | 7 +++++++ .../react/views/scroll/ReactScrollViewManager.java | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index 9fc5b76829c841..38ba923d613262 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -7,6 +7,8 @@ package com.facebook.react.views.scroll; +import static com.facebook.react.views.scroll.ReactScrollViewHelper.SNAP_ALIGNMENT_DISABLED; + import android.animation.Animator; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; @@ -92,6 +94,7 @@ public class ReactScrollView extends ScrollView private @Nullable List mSnapOffsets; private boolean mSnapToStart = true; private boolean mSnapToEnd = true; + private int mSnapToAlignment = SNAP_ALIGNMENT_DISABLED; private @Nullable View mContentView; private ReactViewBackgroundManager mReactBackgroundManager; private int pendingContentOffsetX = UNSET_CONTENT_OFFSET; @@ -218,6 +221,10 @@ public void setSnapToEnd(boolean snapToEnd) { mSnapToEnd = snapToEnd; } + public void setSnapToAlignment(int snapToAlignment) { + mSnapToAlignment = snapToAlignment; + } + public void flashScrollIndicators() { awakenScrollBars(); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java index 974584cd80768b..ac9787e56f79c7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java @@ -115,6 +115,11 @@ public void setSnapToOffsets(ReactScrollView view, @Nullable ReadableArray snapT view.setSnapOffsets(offsets); } + @ReactProp(name = "snapToAlignment") + public void setSnapToAlignment(ReactScrollView view, String alignment) { + view.setSnapToAlignment(ReactScrollViewHelper.parseSnapToAlignment(alignment)); + } + @ReactProp(name = "snapToStart") public void setSnapToStart(ReactScrollView view, boolean snapToStart) { view.setSnapToStart(snapToStart);