mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add snapToAlignment to ReactHorizontalScrollViewManager
Summary: This diff adds the new snapToAlignment into ReactHorizontalScrollViewManager changelog: [Android][Added] Implement snapToAlignment into ReactHorizontalScrollViewManager Reviewed By: JoshuaGross Differential Revision: D31174545 fbshipit-source-id: c56bfca207980428be98dd21a5387a0ff6bcd296
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a54cfb9e57
commit
deec1db9fd
+7
@@ -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;
|
||||
@@ -94,6 +96,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
private @Nullable List<Integer> mSnapOffsets;
|
||||
private boolean mSnapToStart = true;
|
||||
private boolean mSnapToEnd = true;
|
||||
private int mSnapToAlignment = SNAP_ALIGNMENT_DISABLED;
|
||||
private ReactViewBackgroundManager mReactBackgroundManager;
|
||||
private boolean mPagedArrowScrolling = false;
|
||||
private int pendingContentOffsetX = UNSET_CONTENT_OFFSET;
|
||||
@@ -239,6 +242,10 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
mSnapToEnd = snapToEnd;
|
||||
}
|
||||
|
||||
public void setSnapToAlignment(int snapToAlignment) {
|
||||
mSnapToAlignment = snapToAlignment;
|
||||
}
|
||||
|
||||
public void flashScrollIndicators() {
|
||||
awakenScrollBars();
|
||||
}
|
||||
|
||||
+5
@@ -102,6 +102,11 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager<ReactHori
|
||||
view.setSnapInterval((int) (snapToInterval * screenDisplayMetrics.density));
|
||||
}
|
||||
|
||||
@ReactProp(name = "snapToAlignment")
|
||||
public void setSnapToAlignment(ReactHorizontalScrollView view, String alignment) {
|
||||
view.setSnapToAlignment(ReactScrollViewHelper.parseSnapToAlignment(alignment));
|
||||
}
|
||||
|
||||
@ReactProp(name = "snapToOffsets")
|
||||
public void setSnapToOffsets(
|
||||
ReactHorizontalScrollView view, @Nullable ReadableArray snapToOffsets) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.OverScroller;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.uimanager.UIManagerHelper;
|
||||
@@ -26,6 +27,11 @@ public class ReactScrollViewHelper {
|
||||
public static final String AUTO = "auto";
|
||||
public static final String OVER_SCROLL_NEVER = "never";
|
||||
|
||||
public static final int SNAP_ALIGNMENT_DISABLED = 0;
|
||||
public static final int SNAP_ALIGNMENT_START = 1;
|
||||
public static final int SNAP_ALIGNMENT_CENTER = 2;
|
||||
public static final int SNAP_ALIGNMENT_END = 3;
|
||||
|
||||
public interface ScrollListener {
|
||||
void onScroll(
|
||||
ViewGroup scrollView, ScrollEventType scrollEventType, float xVelocity, float yVelocity);
|
||||
@@ -119,6 +125,20 @@ public class ReactScrollViewHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static int parseSnapToAlignment(@Nullable String alignment) {
|
||||
if (alignment == null) {
|
||||
return SNAP_ALIGNMENT_DISABLED;
|
||||
} else if ("start".equalsIgnoreCase(alignment)) {
|
||||
return SNAP_ALIGNMENT_START;
|
||||
} else if ("center".equalsIgnoreCase(alignment)) {
|
||||
return SNAP_ALIGNMENT_CENTER;
|
||||
} else if ("end".equals(alignment)) {
|
||||
return SNAP_ALIGNMENT_END;
|
||||
} else {
|
||||
throw new JSApplicationIllegalArgumentException("wrong snap alignment value: " + alignment);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getDefaultScrollAnimationDuration(Context context) {
|
||||
if (!mSmoothScrollDurationInitialized) {
|
||||
mSmoothScrollDurationInitialized = true;
|
||||
|
||||
Reference in New Issue
Block a user