mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix display metric used for scrollview snapping
Summary: Similarly to D29864944 (https://github.com/facebook/react-native/commit/6d4fff2e5ccaffb6b0255a139f2ae8e009278948) we want to use `getWindowDisplayMetrics` instead of `getScreenDisplayMetrics`. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D33916223 fbshipit-source-id: cae07b1f0c1498745f28d0b9f860edcc55bde5ed
This commit is contained in:
committed by
Facebook GitHub Bot
parent
10199b1581
commit
79975d146e
+4
-6
@@ -8,13 +8,11 @@
|
||||
package com.facebook.react.views.scroll;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.DisplayMetrics;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.PointerEvents;
|
||||
import com.facebook.react.uimanager.ReactClippingViewGroupHelper;
|
||||
@@ -99,8 +97,8 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager<ReactHori
|
||||
@ReactProp(name = "snapToInterval")
|
||||
public void setSnapToInterval(ReactHorizontalScrollView view, float snapToInterval) {
|
||||
// snapToInterval needs to be exposed as a float because of the Javascript interface.
|
||||
DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();
|
||||
view.setSnapInterval((int) (snapToInterval * screenDisplayMetrics.density));
|
||||
float density = PixelUtil.getDisplayMetricDensity();
|
||||
view.setSnapInterval((int) (snapToInterval * density));
|
||||
}
|
||||
|
||||
@ReactProp(name = "snapToAlignment")
|
||||
@@ -116,10 +114,10 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager<ReactHori
|
||||
return;
|
||||
}
|
||||
|
||||
DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();
|
||||
float density = PixelUtil.getDisplayMetricDensity();
|
||||
List<Integer> offsets = new ArrayList<Integer>();
|
||||
for (int i = 0; i < snapToOffsets.size(); i++) {
|
||||
offsets.add((int) (snapToOffsets.getDouble(i) * screenDisplayMetrics.density));
|
||||
offsets.add((int) (snapToOffsets.getDouble(i) * density));
|
||||
}
|
||||
view.setSnapOffsets(offsets);
|
||||
}
|
||||
|
||||
+4
-6
@@ -8,7 +8,6 @@
|
||||
package com.facebook.react.views.scroll;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.ViewCompat;
|
||||
@@ -17,7 +16,6 @@ import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.RetryableMountingLayerException;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
import com.facebook.react.uimanager.PointerEvents;
|
||||
import com.facebook.react.uimanager.ReactClippingViewGroupHelper;
|
||||
@@ -98,8 +96,8 @@ public class ReactScrollViewManager extends ViewGroupManager<ReactScrollView>
|
||||
@ReactProp(name = "snapToInterval")
|
||||
public void setSnapToInterval(ReactScrollView view, float snapToInterval) {
|
||||
// snapToInterval needs to be exposed as a float because of the Javascript interface.
|
||||
DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();
|
||||
view.setSnapInterval((int) (snapToInterval * screenDisplayMetrics.density));
|
||||
float density = PixelUtil.getDisplayMetricDensity();
|
||||
view.setSnapInterval((int) (snapToInterval * density));
|
||||
}
|
||||
|
||||
@ReactProp(name = "snapToOffsets")
|
||||
@@ -109,10 +107,10 @@ public class ReactScrollViewManager extends ViewGroupManager<ReactScrollView>
|
||||
return;
|
||||
}
|
||||
|
||||
DisplayMetrics screenDisplayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics();
|
||||
float density = PixelUtil.getDisplayMetricDensity();
|
||||
List<Integer> offsets = new ArrayList<Integer>();
|
||||
for (int i = 0; i < snapToOffsets.size(); i++) {
|
||||
offsets.add((int) (snapToOffsets.getDouble(i) * screenDisplayMetrics.density));
|
||||
offsets.add((int) (snapToOffsets.getDouble(i) * density));
|
||||
}
|
||||
view.setSnapOffsets(offsets);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user