Browse Source

Add topBar.topMargin option

Guy Carmeli 6 years ago
parent
commit
b1b062a201

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

49
 
49
 
50
 	@ReactMethod
50
 	@ReactMethod
51
     public void getConstants(Promise promise) {
51
     public void getConstants(Promise promise) {
52
+        ReactApplicationContext ctx = getReactApplicationContext();
52
         WritableMap constants = Arguments.createMap();
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
         promise.resolve(constants);
58
         promise.resolve(constants);
58
     }
59
     }
59
 
60
 

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

86
         return (int) (dp * scale + 0.5f);
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
     public static float dpToSp(Context context, float dp) {
93
     public static float dpToSp(Context context, float dp) {
90
         return dpToPx(context, dp) / context.getResources().getDisplayMetrics().density;
94
         return dpToPx(context, dp) / context.getResources().getDisplayMetrics().density;
91
     }
95
     }