mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Convert react/uimanager/*Util.java -> Kotlin (#43729)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43729 # Changelog: [Internal] - As in the title, converts corresponding type declarations in `react/uimanager/*Util.kt` to Kotlin. Reviewed By: tdn120 Differential Revision: D55574531 fbshipit-source-id: 974234bd57c77e863aa723388e48ffc455e73a96
This commit is contained in:
committed by
Facebook GitHub Bot
parent
287b5d697f
commit
08f57473cc
@@ -4025,9 +4025,9 @@ public abstract interface class com/facebook/react/uimanager/FabricViewStateMana
|
||||
public abstract fun getStateUpdate ()Lcom/facebook/react/bridge/WritableMap;
|
||||
}
|
||||
|
||||
public class com/facebook/react/uimanager/FloatUtil {
|
||||
public fun <init> ()V
|
||||
public static fun floatsEqual (FF)Z
|
||||
public final class com/facebook/react/uimanager/FloatUtil {
|
||||
public static final field INSTANCE Lcom/facebook/react/uimanager/FloatUtil;
|
||||
public static final fun floatsEqual (FF)Z
|
||||
}
|
||||
|
||||
public abstract class com/facebook/react/uimanager/GuardedFrameCallback : android/view/Choreographer$FrameCallback {
|
||||
@@ -4213,15 +4213,16 @@ public class com/facebook/react/uimanager/OnLayoutEvent : com/facebook/react/uim
|
||||
public fun onDispose ()V
|
||||
}
|
||||
|
||||
public class com/facebook/react/uimanager/PixelUtil {
|
||||
public fun <init> ()V
|
||||
public static fun getDisplayMetricDensity ()F
|
||||
public static fun toDIPFromPixel (F)F
|
||||
public static fun toPixelFromDIP (D)F
|
||||
public static fun toPixelFromDIP (F)F
|
||||
public static fun toPixelFromSP (D)F
|
||||
public static fun toPixelFromSP (F)F
|
||||
public static fun toPixelFromSP (FF)F
|
||||
public final class com/facebook/react/uimanager/PixelUtil {
|
||||
public static final field INSTANCE Lcom/facebook/react/uimanager/PixelUtil;
|
||||
public static final fun getDisplayMetricDensity ()F
|
||||
public static final fun toDIPFromPixel (F)F
|
||||
public static final fun toPixelFromDIP (D)F
|
||||
public static final fun toPixelFromDIP (F)F
|
||||
public static final fun toPixelFromSP (D)F
|
||||
public static final fun toPixelFromSP (F)F
|
||||
public static final fun toPixelFromSP (FF)F
|
||||
public static synthetic fun toPixelFromSP$default (FFILjava/lang/Object;)F
|
||||
}
|
||||
|
||||
public final class com/facebook/react/uimanager/PointerEvents : java/lang/Enum {
|
||||
@@ -4776,10 +4777,10 @@ public class com/facebook/react/uimanager/RootViewManager$$PropsSetter : com/fac
|
||||
public synthetic fun setProperty (Lcom/facebook/react/uimanager/ViewManager;Landroid/view/View;Ljava/lang/String;Ljava/lang/Object;)V
|
||||
}
|
||||
|
||||
public class com/facebook/react/uimanager/RootViewUtil {
|
||||
public fun <init> ()V
|
||||
public static fun getRootView (Landroid/view/View;)Lcom/facebook/react/uimanager/RootView;
|
||||
public static fun getViewportOffset (Landroid/view/View;)Landroid/graphics/Point;
|
||||
public final class com/facebook/react/uimanager/RootViewUtil {
|
||||
public static final field INSTANCE Lcom/facebook/react/uimanager/RootViewUtil;
|
||||
public static final fun getRootView (Landroid/view/View;)Lcom/facebook/react/uimanager/RootView;
|
||||
public static final fun getViewportOffset (Landroid/view/View;)Landroid/graphics/Point;
|
||||
}
|
||||
|
||||
public abstract class com/facebook/react/uimanager/SimpleViewManager : com/facebook/react/uimanager/BaseViewManager {
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class FloatUtil {
|
||||
|
||||
private static final float EPSILON = .00001f;
|
||||
|
||||
public static boolean floatsEqual(float f1, float f2) {
|
||||
if (Float.isNaN(f1) || Float.isNaN(f2)) {
|
||||
return Float.isNaN(f1) && Float.isNaN(f2);
|
||||
}
|
||||
return Math.abs(f2 - f1) < EPSILON;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager
|
||||
|
||||
import kotlin.math.abs
|
||||
|
||||
public object FloatUtil {
|
||||
private const val EPSILON = .00001f
|
||||
|
||||
@JvmStatic
|
||||
public fun floatsEqual(f1: Float, f2: Float): Boolean {
|
||||
return if (java.lang.Float.isNaN(f1) || java.lang.Float.isNaN(f2)) {
|
||||
java.lang.Float.isNaN(f1) && java.lang.Float.isNaN(f2)
|
||||
} else abs(f2 - f1) < EPSILON
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
|
||||
/** Android dp to pixel manipulation */
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public class PixelUtil {
|
||||
|
||||
/** Convert from DIP to PX */
|
||||
public static float toPixelFromDIP(float value) {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, value, DisplayMetricsHolder.getWindowDisplayMetrics());
|
||||
}
|
||||
|
||||
/** Convert from DIP to PX */
|
||||
public static float toPixelFromDIP(double value) {
|
||||
return toPixelFromDIP((float) value);
|
||||
}
|
||||
|
||||
/** Convert from SP to PX */
|
||||
public static float toPixelFromSP(float value) {
|
||||
return toPixelFromSP(value, Float.NaN);
|
||||
}
|
||||
|
||||
/** Convert from SP to PX */
|
||||
public static float toPixelFromSP(float value, float maxFontScale) {
|
||||
DisplayMetrics displayMetrics = DisplayMetricsHolder.getWindowDisplayMetrics();
|
||||
float scaledDensity = displayMetrics.scaledDensity;
|
||||
float currentFontScale = scaledDensity / displayMetrics.density;
|
||||
if (maxFontScale >= 1 && maxFontScale < currentFontScale) {
|
||||
scaledDensity = displayMetrics.density * maxFontScale;
|
||||
}
|
||||
|
||||
return value * scaledDensity;
|
||||
}
|
||||
|
||||
/** Convert from SP to PX */
|
||||
public static float toPixelFromSP(double value) {
|
||||
return toPixelFromSP((float) value);
|
||||
}
|
||||
|
||||
/** Convert from PX to DP */
|
||||
public static float toDIPFromPixel(float value) {
|
||||
return value / DisplayMetricsHolder.getWindowDisplayMetrics().density;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link float} that represents the density of the display metrics for device screen.
|
||||
*/
|
||||
public static float getDisplayMetricDensity() {
|
||||
return DisplayMetricsHolder.getWindowDisplayMetrics().density;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager
|
||||
|
||||
import android.util.TypedValue
|
||||
|
||||
/** Android dp to pixel manipulation */
|
||||
public object PixelUtil {
|
||||
/** Convert from DIP to PX */
|
||||
@JvmStatic
|
||||
public fun toPixelFromDIP(value: Float): Float {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, value, DisplayMetricsHolder.getWindowDisplayMetrics())
|
||||
}
|
||||
|
||||
/** Convert from DIP to PX */
|
||||
@JvmStatic
|
||||
public fun toPixelFromDIP(value: Double): Float {
|
||||
return toPixelFromDIP(value.toFloat())
|
||||
}
|
||||
|
||||
/** Convert from SP to PX */
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
public fun toPixelFromSP(value: Float, maxFontScale: Float = Float.NaN): Float {
|
||||
val displayMetrics = DisplayMetricsHolder.getWindowDisplayMetrics()
|
||||
var scaledDensity = displayMetrics.scaledDensity
|
||||
val currentFontScale = scaledDensity / displayMetrics.density
|
||||
if (maxFontScale >= 1 && maxFontScale < currentFontScale) {
|
||||
scaledDensity = displayMetrics.density * maxFontScale
|
||||
}
|
||||
return value * scaledDensity
|
||||
}
|
||||
|
||||
/** Convert from SP to PX */
|
||||
@JvmStatic
|
||||
public fun toPixelFromSP(value: Double): Float {
|
||||
return toPixelFromSP(value.toFloat())
|
||||
}
|
||||
|
||||
/** Convert from PX to DP */
|
||||
@JvmStatic
|
||||
public fun toDIPFromPixel(value: Float): Float {
|
||||
return value / DisplayMetricsHolder.getWindowDisplayMetrics().density
|
||||
}
|
||||
|
||||
/** @return [float] that represents the density of the display metrics for device screen. */
|
||||
@JvmStatic
|
||||
public fun getDisplayMetricDensity(): Float =
|
||||
DisplayMetricsHolder.getWindowDisplayMetrics().density
|
||||
}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
import androidx.annotation.UiThread;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
|
||||
public class RootViewUtil {
|
||||
|
||||
/** Returns the root view of a given view in a react application. */
|
||||
public static RootView getRootView(View reactView) {
|
||||
View current = reactView;
|
||||
while (true) {
|
||||
if (current instanceof RootView) {
|
||||
return (RootView) current;
|
||||
}
|
||||
ViewParent next = current.getParent();
|
||||
if (next == null) {
|
||||
return null;
|
||||
}
|
||||
Assertions.assertCondition(next instanceof View);
|
||||
current = (View) next;
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public static Point getViewportOffset(View v) {
|
||||
int[] locationInWindow = new int[2];
|
||||
v.getLocationInWindow(locationInWindow);
|
||||
|
||||
// we need to subtract visibleWindowCoords - to subtract possible window insets, split
|
||||
// screen or multi window
|
||||
Rect visibleWindowFrame = new Rect();
|
||||
v.getWindowVisibleDisplayFrame(visibleWindowFrame);
|
||||
locationInWindow[0] -= visibleWindowFrame.left;
|
||||
locationInWindow[1] -= visibleWindowFrame.top;
|
||||
|
||||
return new Point(locationInWindow[0], locationInWindow[1]);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager
|
||||
|
||||
import android.graphics.Point
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import androidx.annotation.UiThread
|
||||
import com.facebook.infer.annotation.Assertions
|
||||
|
||||
public object RootViewUtil {
|
||||
/** Returns the root view of a given view in a react application. */
|
||||
@JvmStatic
|
||||
public fun getRootView(reactView: View): RootView? {
|
||||
var current = reactView
|
||||
while (true) {
|
||||
if (current is RootView) {
|
||||
return current
|
||||
}
|
||||
val next = current.parent ?: return null
|
||||
Assertions.assertCondition(next is View)
|
||||
current = next as View
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@JvmStatic
|
||||
public fun getViewportOffset(v: View): Point {
|
||||
val locationInWindow = IntArray(2)
|
||||
v.getLocationInWindow(locationInWindow)
|
||||
|
||||
// we need to subtract visibleWindowCoords - to subtract possible window insets, split
|
||||
// screen or multi window
|
||||
val visibleWindowFrame = Rect()
|
||||
v.getWindowVisibleDisplayFrame(visibleWindowFrame)
|
||||
locationInWindow[0] -= visibleWindowFrame.left
|
||||
locationInWindow[1] -= visibleWindowFrame.top
|
||||
return Point(locationInWindow[0], locationInWindow[1])
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -26,7 +26,10 @@ public class NativeGestureUtil {
|
||||
* @param event the MotionEvent that caused the gesture to be started
|
||||
*/
|
||||
public static void notifyNativeGestureStarted(View view, MotionEvent event) {
|
||||
RootViewUtil.getRootView(view).onChildStartedNativeGesture(view, event);
|
||||
RootView rootView = RootViewUtil.getRootView(view);
|
||||
if (rootView != null) {
|
||||
rootView.onChildStartedNativeGesture(view, event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user