mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: This diff updates the size of RootShadowNode and re-render RN views when the Size of the Android React View changes Reviewed By: achen1 Differential Revision: D9173758 fbshipit-source-id: 7cc6bbfb646025c3ec1773ab041eb9207623af71
66 lines
1.5 KiB
Java
66 lines
1.5 KiB
Java
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* 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 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 TypedValue.applyDimension(
|
|
TypedValue.COMPLEX_UNIT_SP,
|
|
value,
|
|
DisplayMetricsHolder.getWindowDisplayMetrics());
|
|
}
|
|
|
|
/**
|
|
* 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.getScreenDisplayMetrics().density;
|
|
}
|
|
|
|
}
|