forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert react/uimanager/*Util.java -> Kotlin (facebook#43729)
Summary: Pull Request resolved: facebook#43729 # Changelog: [Internal] - As in the title, converts corresponding type declarations in `react/uimanager/*Util.kt` to Kotlin. Differential Revision: https://internalfb.com/D55574531
- Loading branch information
1 parent
b4e3ae5
commit 2bdbe2e
Showing
8 changed files
with
143 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/FloatUtil.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/FloatUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 0 additions & 62 deletions
62
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 0 additions & 49 deletions
49
...es/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/RootViewUtil.java
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
...ages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/RootViewUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters