Selaa lähdekoodia

Fix native image resource for bottom tab icon (#5775)

bottomTab.icon accepts a string as well as required asset - this was not reflected properly in TypeScript and implementation was missing from Android.
closes #5759
Guy Carmeli 5 vuotta sitten
vanhempi
commit
aa1870a743
No account linked to committer's email address

+ 3
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/BottomTabOptions.java Näytä tiedosto

@@ -12,6 +12,7 @@ import com.reactnativenavigation.parse.params.Number;
12 12
 import com.reactnativenavigation.parse.params.Text;
13 13
 import com.reactnativenavigation.parse.parsers.BoolParser;
14 14
 import com.reactnativenavigation.parse.parsers.ColorParser;
15
+import com.reactnativenavigation.parse.parsers.IconParser;
15 16
 import com.reactnativenavigation.parse.parsers.NumberParser;
16 17
 import com.reactnativenavigation.parse.parsers.TextParser;
17 18
 import com.reactnativenavigation.utils.TypefaceLoader;
@@ -29,8 +30,8 @@ public class BottomTabOptions {
29 30
         options.text = TextParser.parse(json, "text");
30 31
         options.textColor = ColorParser.parse(json, "textColor");
31 32
         options.selectedTextColor = ColorParser.parse(json, "selectedTextColor");
32
-        if (json.has("icon")) options.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
33
-        if (json.has("selectedIcon")) options.selectedIcon = TextParser.parse(json.optJSONObject("selectedIcon"), "uri");
33
+        options.icon = IconParser.parse(json, "icon");
34
+        options.selectedIcon = IconParser.parse(json, "selectedIcon");
34 35
         options.iconColor = ColorParser.parse(json, "iconColor");
35 36
         options.selectedIconColor = ColorParser.parse(json, "selectedIconColor");
36 37
         options.badge = TextParser.parse(json, "badge");

+ 21
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/parsers/IconParser.java Näytä tiedosto

@@ -0,0 +1,21 @@
1
+package com.reactnativenavigation.parse.parsers;
2
+
3
+import com.reactnativenavigation.parse.params.NullText;
4
+import com.reactnativenavigation.parse.params.Text;
5
+
6
+import org.json.JSONException;
7
+import org.json.JSONObject;
8
+
9
+import javax.annotation.Nullable;
10
+
11
+public class IconParser {
12
+    public static Text parse(@Nullable JSONObject json, String key) {
13
+        if (json == null) return new NullText();
14
+        try {
15
+            return json.get(key) instanceof String ? TextParser.parse(json, key) : TextParser.parse(json.optJSONObject(key), "uri");
16
+        } catch (JSONException e) {
17
+            e.printStackTrace();
18
+        }
19
+        return new NullText();
20
+    }
21
+}

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/stack/StackBehaviour.java Näytä tiedosto

@@ -12,7 +12,7 @@ import com.reactnativenavigation.views.topbar.TopBar;
12 12
 import androidx.annotation.NonNull;
13 13
 import androidx.coordinatorlayout.widget.CoordinatorLayout;
14 14
 
15
-public class StackBehaviour<V extends ViewGroup> extends BehaviourDelegate {
15
+public class StackBehaviour extends BehaviourDelegate {
16 16
     public StackBehaviour(BehaviourAdapter delegate) {
17 17
         super(delegate);
18 18
     }

+ 7
- 6
lib/src/commands/OptionsProcessor.ts Näytä tiedosto

@@ -1,8 +1,9 @@
1
-import isEqual from 'lodash/isEqual'
2
-import isObject from 'lodash/isObject'
3
-import isArray from 'lodash/isArray'
4
-import endsWith from 'lodash/endsWith'
5
-import forEach from 'lodash/forEach'
1
+import isEqual from 'lodash/isEqual';
2
+import isObject from 'lodash/isObject';
3
+import isArray from 'lodash/isArray';
4
+import isString from 'lodash/isString';
5
+import endsWith from 'lodash/endsWith';
6
+import forEach from 'lodash/forEach';
6 7
 
7 8
 import { Store } from '../components/Store';
8 9
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
@@ -53,7 +54,7 @@ export class OptionsProcessor {
53 54
       endsWith(key, 'Icon') ||
54 55
       endsWith(key, 'Image')
55 56
     ) {
56
-      options[key] = this.assetService.resolveFromRequire(value);
57
+      options[key] = isString(value) ? value : this.assetService.resolveFromRequire(value);
57 58
     }
58 59
   }
59 60
 

+ 3
- 1
lib/src/interfaces/Options.ts Näytä tiedosto

@@ -549,6 +549,8 @@ export interface DotIndicatorOptions {
549 549
     visible?: boolean;
550 550
 }
551 551
 
552
+export type ImageResource = string;
553
+
552 554
 export interface OptionsBottomTab {
553 555
     dotIndicator?: DotIndicatorOptions;
554 556
 
@@ -572,7 +574,7 @@ export interface OptionsBottomTab {
572 574
    * Set the tab icon
573 575
    * Note: On Android `icon` is required
574 576
    */
575
-  icon?: ImageRequireSource;
577
+  icon?: ImageRequireSource | ImageResource;
576 578
   /**
577 579
    * Set the icon tint
578 580
    */

+ 5
- 0
playground/ios/playground/Images.xcassets/AppIcon.appiconset/Contents.json Näytä tiedosto

@@ -65,6 +65,11 @@
65 65
       "idiom" : "iphone",
66 66
       "filename" : "Icon-180.png",
67 67
       "scale" : "3x"
68
+    },
69
+    {
70
+      "idiom" : "ios-marketing",
71
+      "size" : "1024x1024",
72
+      "scale" : "1x"
68 73
     }
69 74
   ],
70 75
   "info" : {

+ 21
- 0
playground/ios/playground/Images.xcassets/icon_res.imageset/Contents.json Näytä tiedosto

@@ -0,0 +1,21 @@
1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x"
6
+    },
7
+    {
8
+      "idiom" : "universal",
9
+      "filename" : "clear@2x.ios.png",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
playground/ios/playground/Images.xcassets/icon_res.imageset/clear@2x.ios.png Näytä tiedosto


BIN
playground/ios/playground/clear@2x.ios.png Näytä tiedosto