Skip to content

Commit

Permalink
Add PixelUtil extensions for Int, Long (#46992)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46992

Changelog: [Android][Added] Added PixelUtil extensions for Int and Long

Reviewed By: Abbondanzo

Differential Revision: D64262473

fbshipit-source-id: 49a666662ca260b878bdfa9a81a79dd6a381c879
  • Loading branch information
Thomas Nardone authored and facebook-github-bot committed Oct 16, 2024
1 parent c35035e commit 9406a09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -4490,9 +4490,13 @@ public final class com/facebook/react/uimanager/PixelUtil {
public static final field INSTANCE Lcom/facebook/react/uimanager/PixelUtil;
public final fun dpToPx (D)F
public final fun dpToPx (F)F
public final fun dpToPx (I)F
public final fun dpToPx (J)F
public static final fun getDisplayMetricDensity ()F
public final fun pxToDp (D)F
public final fun pxToDp (F)F
public final fun pxToDp (I)F
public final fun pxToDp (J)F
public static final fun toDIPFromPixel (F)F
public static final fun toPixelFromDIP (D)F
public static final fun toPixelFromDIP (F)F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ public object PixelUtil {
DisplayMetricsHolder.getWindowDisplayMetrics().density

/* Kotlin extensions */
public fun Float.dpToPx(): Float = PixelUtil.toPixelFromDIP(this)
public fun Int.dpToPx(): Float = toPixelFromDIP(this.toFloat())

public fun Double.dpToPx(): Float = PixelUtil.toPixelFromDIP(this)
public fun Long.dpToPx(): Float = toPixelFromDIP(this.toFloat())

public fun Float.pxToDp(): Float = PixelUtil.toDIPFromPixel(this)
public fun Float.dpToPx(): Float = toPixelFromDIP(this)

public fun Double.pxToDp(): Float = PixelUtil.toDIPFromPixel(this.toFloat())
public fun Double.dpToPx(): Float = toPixelFromDIP(this.toFloat())

public fun Int.pxToDp(): Float = toDIPFromPixel(this.toFloat())

public fun Long.pxToDp(): Float = toDIPFromPixel(this.toFloat())

public fun Float.pxToDp(): Float = toDIPFromPixel(this)

public fun Double.pxToDp(): Float = toDIPFromPixel(this.toFloat())
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ internal class OutlineDrawable(

computedBorderRadius =
borderRadius?.resolve(
layoutDirection,
context,
bounds.width().toFloat().dpToPx(),
bounds.height().toFloat().dpToPx())
layoutDirection, context, bounds.width().dpToPx(), bounds.height().dpToPx())

updateOutlineRect()
if (computedBorderRadius != null && computedBorderRadius?.hasRoundedBorders() == true) {
Expand Down

0 comments on commit 9406a09

Please sign in to comment.