Native Modules -> Native Extensions

Reviewed By: danzimm

Differential Revision: D6887988

fbshipit-source-id: 475c05f60a2e1ddcfaa9263ab363bff8a528236a
This commit is contained in:
Dmitry Zakharov
2018-02-07 07:29:49 -08:00
committed by Facebook Github Bot
parent 06d8f96a64
commit 0c49c1f332
10 changed files with 123 additions and 92 deletions

View File

@@ -2,13 +2,17 @@ load("//ReactNative:DEFS", "rn_android_library", "YOGA_TARGET", "react_native_de
rn_android_library(
name = "uimanager",
srcs = glob([
"*.java",
"debug/*.java",
"events/*.java",
"layoutanimation/*.java",
]),
srcs = glob(
[
"*.java",
"debug/*.java",
"events/*.java",
"layoutanimation/*.java",
],
excludes = ["DisplayMetricsHolder.java"],
),
exported_deps = [
":DisplayMetrics",
react_native_dep("third-party/java/jsr-305:jsr-305"),
],
provided_deps = [
@@ -21,6 +25,7 @@ rn_android_library(
],
deps = [
YOGA_TARGET,
":DisplayMetrics",
react_native_dep("java/com/facebook/systrace:systrace"),
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
@@ -38,3 +43,19 @@ rn_android_library(
react_native_target("res:uimanager"),
],
)
rn_android_library(
name = "DisplayMetrics",
srcs = glob([
"DisplayMetricsHolder.java",
]),
required_for_source_only_abi = True,
visibility = [
"PUBLIC",
],
deps = [
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/bridge:bridge"),
],
)

View File

@@ -21,6 +21,7 @@ import android.view.Display;
import android.view.WindowManager;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.WritableNativeMap;
/**
* Holds an instance of the current DisplayMetrics so we don't have to thread it through all the
@@ -104,4 +105,26 @@ public class DisplayMetricsHolder {
public static DisplayMetrics getScreenDisplayMetrics() {
return sScreenDisplayMetrics;
}
public static WritableNativeMap getDisplayMetricsMap(double fontScale) {
Assertions.assertNotNull(
sWindowDisplayMetrics != null || sScreenDisplayMetrics != null,
"DisplayMetricsHolder must be initialized with initDisplayMetricsIfNotInitialized or initDisplayMetrics");
final WritableNativeMap result = new WritableNativeMap();
result.putMap("windowPhysicalPixels", getPhysicalPixelsMap(sWindowDisplayMetrics, fontScale));
result.putMap("screenPhysicalPixels", getPhysicalPixelsMap(sScreenDisplayMetrics, fontScale));
return result;
}
private static WritableNativeMap getPhysicalPixelsMap(DisplayMetrics displayMetrics, double fontScale) {
final WritableNativeMap result = new WritableNativeMap();
result.putInt("width", displayMetrics.widthPixels);
result.putInt("height", displayMetrics.heightPixels);
result.putDouble("scale", displayMetrics.density);
result.putDouble("fontScale", fontScale);
result.putDouble("densityDpi", displayMetrics.densityDpi);
return result;
}
}