Преглед на файлове

Hardcode Toolbar icon dimension

Guy Carmeli преди 8 години
родител
ревизия
d4eaa0886a

+ 16
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ImageUtils.java Целия файл

@@ -1,8 +1,11 @@
1 1
 package com.reactnativenavigation.utils;
2 2
 
3
+import android.content.Context;
4
+import android.content.res.Resources;
3 5
 import android.graphics.PorterDuff;
4 6
 import android.graphics.PorterDuffColorFilter;
5 7
 import android.graphics.drawable.Drawable;
8
+import android.util.DisplayMetrics;
6 9
 
7 10
 /**
8 11
  * Created by guyc on 23/04/16.
@@ -13,4 +16,17 @@ public class ImageUtils {
13 16
         drawable.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.SRC_IN));
14 17
     }
15 18
 
19
+    /**
20
+     * This method converts dp unit to equivalent pixels, depending on device density.
21
+     *
22
+     * @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
23
+     * @param context Context to get resources and device specific display metrics
24
+     * @return A float value to represent px equivalent to dp depending on device density
25
+     */
26
+    public static float convertDpToPixel(float dp, Context context){
27
+        Resources resources = context.getResources();
28
+        DisplayMetrics metrics = resources.getDisplayMetrics();
29
+        float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
30
+        return px;
31
+    }
16 32
 }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/views/RnnToolBar.java Целия файл

@@ -311,7 +311,7 @@ public class RnnToolBar extends Toolbar {
311 311
             mOldButtons = oldScreen == null ? null : oldScreen.getButtons();
312 312
             mNewButtons = newScreen.getButtons();
313 313
             mTintColor = newScreen.navBarButtonColor;
314
-            mIconDimensions = (int) (toolBar.getHeight() * 0.4f);
314
+            mIconDimensions = (int) ImageUtils.convertDpToPixel(48, toolBar.getContext());
315 315
         }
316 316
 
317 317
         @Override