Explorar el Código

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 hace 5 años
padre
commit
aa1870a743
No account linked to committer's email address

+ 3
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/BottomTabOptions.java Ver fichero

12
 import com.reactnativenavigation.parse.params.Text;
12
 import com.reactnativenavigation.parse.params.Text;
13
 import com.reactnativenavigation.parse.parsers.BoolParser;
13
 import com.reactnativenavigation.parse.parsers.BoolParser;
14
 import com.reactnativenavigation.parse.parsers.ColorParser;
14
 import com.reactnativenavigation.parse.parsers.ColorParser;
15
+import com.reactnativenavigation.parse.parsers.IconParser;
15
 import com.reactnativenavigation.parse.parsers.NumberParser;
16
 import com.reactnativenavigation.parse.parsers.NumberParser;
16
 import com.reactnativenavigation.parse.parsers.TextParser;
17
 import com.reactnativenavigation.parse.parsers.TextParser;
17
 import com.reactnativenavigation.utils.TypefaceLoader;
18
 import com.reactnativenavigation.utils.TypefaceLoader;
29
         options.text = TextParser.parse(json, "text");
30
         options.text = TextParser.parse(json, "text");
30
         options.textColor = ColorParser.parse(json, "textColor");
31
         options.textColor = ColorParser.parse(json, "textColor");
31
         options.selectedTextColor = ColorParser.parse(json, "selectedTextColor");
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
         options.iconColor = ColorParser.parse(json, "iconColor");
35
         options.iconColor = ColorParser.parse(json, "iconColor");
35
         options.selectedIconColor = ColorParser.parse(json, "selectedIconColor");
36
         options.selectedIconColor = ColorParser.parse(json, "selectedIconColor");
36
         options.badge = TextParser.parse(json, "badge");
37
         options.badge = TextParser.parse(json, "badge");

+ 21
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/parsers/IconParser.java Ver fichero

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 Ver fichero

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

+ 7
- 6
lib/src/commands/OptionsProcessor.ts Ver fichero

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
 import { Store } from '../components/Store';
8
 import { Store } from '../components/Store';
8
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
9
 import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
53
       endsWith(key, 'Icon') ||
54
       endsWith(key, 'Icon') ||
54
       endsWith(key, 'Image')
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 Ver fichero

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

+ 5
- 0
playground/ios/playground/Images.xcassets/AppIcon.appiconset/Contents.json Ver fichero

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

+ 21
- 0
playground/ios/playground/Images.xcassets/icon_res.imageset/Contents.json Ver fichero

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 Ver fichero


BIN
playground/ios/playground/clear@2x.ios.png Ver fichero