Browse Source

Hardcode Toolbar icon dimension

Guy Carmeli 8 years ago
parent
commit
d4eaa0886a

+ 16
- 0
android/app/src/main/java/com/reactnativenavigation/utils/ImageUtils.java View File

1
 package com.reactnativenavigation.utils;
1
 package com.reactnativenavigation.utils;
2
 
2
 
3
+import android.content.Context;
4
+import android.content.res.Resources;
3
 import android.graphics.PorterDuff;
5
 import android.graphics.PorterDuff;
4
 import android.graphics.PorterDuffColorFilter;
6
 import android.graphics.PorterDuffColorFilter;
5
 import android.graphics.drawable.Drawable;
7
 import android.graphics.drawable.Drawable;
8
+import android.util.DisplayMetrics;
6
 
9
 
7
 /**
10
 /**
8
  * Created by guyc on 23/04/16.
11
  * Created by guyc on 23/04/16.
13
         drawable.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.SRC_IN));
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 View File

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