瀏覽代碼

Enable android load drawable images (#3734)

* Enable android load drawable images

* Add debug check

* Update document
Jing Tai Piao 6 年之前
父節點
當前提交
a43d4ba7b5
共有 2 個文件被更改,包括 30 次插入5 次删除
  1. 19
    0
      docs/docs/styling.md
  2. 11
    5
      lib/android/app/src/main/java/com/reactnativenavigation/utils/ImageLoader.java

+ 19
- 0
docs/docs/styling.md 查看文件

@@ -257,6 +257,25 @@ If you'd like to use a custom font, you'll first have to edit your project.
257 257
 
258 258
 * iOS - follow this [guide](https://medium.com/@dabit3/adding-custom-fonts-to-react-native-b266b41bff7f)
259 259
 
260
+## Custom tab icons
261
+
262
+* Android - add cooresponding resoltion icons into folders in android/app/src/main/res.
263
+For example, icon_name.png in each drawable-x folder.
264
+* iOS - drag and drop to Images.xcassets in Xcode.
265
+For example, image set icon_name in Images.xcassets with x1, x2, x3.
266
+
267
+Then, the tab icon can be defined by following syntax:
268
+
269
+```js
270
+bottomTab: {
271
+  icon: {
272
+    uri: 'icon_name',
273
+    ...
274
+  },
275
+  ...
276
+}
277
+```
278
+
260 279
 ## Customizing screen animations
261 280
 Animation used for navigation commands that modify the layout hierarchy can be controlled in options. Animations can be modified per command and it's also possible to change the default animation for each command.
262 281
 

+ 11
- 5
lib/android/app/src/main/java/com/reactnativenavigation/utils/ImageLoader.java 查看文件

@@ -56,13 +56,19 @@ public class ImageLoader {
56 56
 
57 57
     @NonNull
58 58
     private Drawable getDrawable(Context context, String source) throws IOException {
59
-        if (BuildConfig.DEBUG) {
60
-            return readJsDevImage(context, source);
61
-        } else if (isLocalFile(Uri.parse(source))) {
62
-            return loadFile(source);
59
+        Drawable drawable;
60
+
61
+        if (isLocalFile(Uri.parse(source))) {
62
+            drawable = loadFile(source);
63 63
         } else {
64
-            return loadResource(source);
64
+            drawable = loadResource(source);
65
+
66
+            if (drawable == null || BuildConfig.DEBUG) {
67
+                drawable = readJsDevImage(context, source);
68
+            }
65 69
         }
70
+
71
+        return drawable;
66 72
     }
67 73
 
68 74
     @NonNull