Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

// Deprecated usage inc imports of RCTEventEmitter
@file:Suppress("DEPRECATION")

package com.facebook.react.popupmenu

import com.facebook.react.bridge.Arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.react.uimanager

import android.util.TypedValue
import kotlin.math.min

/** Android dp to pixel manipulation */
public object PixelUtil {
Expand All @@ -29,12 +30,13 @@ public object PixelUtil {
@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
val scaledValue = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, value, displayMetrics)

if (maxFontScale >= 1) {
return min(scaledValue, value * displayMetrics.density * maxFontScale)
}
return value * scaledDensity

return scaledValue
}

/** Convert from SP to PX */
Expand Down