Bläddra i källkod

Add topBar.topMargin option

Guy Carmeli 6 år sedan
förälder
incheckning
b1b062a201

+ 5
- 4
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java Visa fil

@@ -49,11 +49,12 @@ public class NavigationModule extends ReactContextBaseJavaModule {
49 49
 
50 50
 	@ReactMethod
51 51
     public void getConstants(Promise promise) {
52
+        ReactApplicationContext ctx = getReactApplicationContext();
52 53
         WritableMap constants = Arguments.createMap();
53
-        constants.putString(Constants.BACK_BUTTON_JS_KEY, Constants.BACK_BUTTON_ID);
54
-        constants.putDouble(Constants.STATUS_BAR_HEIGHT_KEY, UiUtils.getStatusBarHeight(getReactApplicationContext()));
55
-        constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY, UiUtils.getToolBarHeight(getReactApplicationContext()));
56
-        constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY, UiUtils.dpToPx(getReactApplicationContext(), Constants.BOTTOM_TABS_HEIGHT));
54
+        constants.putString(Constants.BACK_BUTTON_JS_KEY,    Constants.BACK_BUTTON_ID);
55
+        constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY,    Constants.BOTTOM_TABS_HEIGHT);
56
+        constants.putDouble(Constants.STATUS_BAR_HEIGHT_KEY, UiUtils.pxToDp(ctx, UiUtils.getStatusBarHeight(ctx)));
57
+        constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY,    UiUtils.pxToDp(ctx, UiUtils.getToolBarHeight(ctx)));
57 58
         promise.resolve(constants);
58 59
     }
59 60
 

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/UiUtils.java Visa fil

@@ -86,6 +86,10 @@ public class UiUtils {
86 86
         return (int) (dp * scale + 0.5f);
87 87
     }
88 88
 
89
+    public static float pxToDp(Context context, float px) {
90
+        return px / ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
91
+    }
92
+
89 93
     public static float dpToSp(Context context, float dp) {
90 94
         return dpToPx(context, dp) / context.getResources().getDisplayMetrics().density;
91 95
     }