Skip to content

Commit

Permalink
Fix native image resource for bottom tab icon (#5775)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
guyca authored Dec 15, 2019
1 parent 45eef0d commit aa1870a
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.reactnativenavigation.parse.params.Text;
import com.reactnativenavigation.parse.parsers.BoolParser;
import com.reactnativenavigation.parse.parsers.ColorParser;
import com.reactnativenavigation.parse.parsers.IconParser;
import com.reactnativenavigation.parse.parsers.NumberParser;
import com.reactnativenavigation.parse.parsers.TextParser;
import com.reactnativenavigation.utils.TypefaceLoader;
Expand All @@ -29,8 +30,8 @@ public static BottomTabOptions parse(TypefaceLoader typefaceManager, JSONObject
options.text = TextParser.parse(json, "text");
options.textColor = ColorParser.parse(json, "textColor");
options.selectedTextColor = ColorParser.parse(json, "selectedTextColor");
if (json.has("icon")) options.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
if (json.has("selectedIcon")) options.selectedIcon = TextParser.parse(json.optJSONObject("selectedIcon"), "uri");
options.icon = IconParser.parse(json, "icon");
options.selectedIcon = IconParser.parse(json, "selectedIcon");
options.iconColor = ColorParser.parse(json, "iconColor");
options.selectedIconColor = ColorParser.parse(json, "selectedIconColor");
options.badge = TextParser.parse(json, "badge");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.reactnativenavigation.parse.parsers;

import com.reactnativenavigation.parse.params.NullText;
import com.reactnativenavigation.parse.params.Text;

import org.json.JSONException;
import org.json.JSONObject;

import javax.annotation.Nullable;

public class IconParser {
public static Text parse(@Nullable JSONObject json, String key) {
if (json == null) return new NullText();
try {
return json.get(key) instanceof String ? TextParser.parse(json, key) : TextParser.parse(json.optJSONObject(key), "uri");
} catch (JSONException e) {
e.printStackTrace();
}
return new NullText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

public class StackBehaviour<V extends ViewGroup> extends BehaviourDelegate {
public class StackBehaviour extends BehaviourDelegate {
public StackBehaviour(BehaviourAdapter delegate) {
super(delegate);
}
Expand Down
13 changes: 7 additions & 6 deletions lib/src/commands/OptionsProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import isEqual from 'lodash/isEqual'
import isObject from 'lodash/isObject'
import isArray from 'lodash/isArray'
import endsWith from 'lodash/endsWith'
import forEach from 'lodash/forEach'
import isEqual from 'lodash/isEqual';
import isObject from 'lodash/isObject';
import isArray from 'lodash/isArray';
import isString from 'lodash/isString';
import endsWith from 'lodash/endsWith';
import forEach from 'lodash/forEach';

import { Store } from '../components/Store';
import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
Expand Down Expand Up @@ -53,7 +54,7 @@ export class OptionsProcessor {
endsWith(key, 'Icon') ||
endsWith(key, 'Image')
) {
options[key] = this.assetService.resolveFromRequire(value);
options[key] = isString(value) ? value : this.assetService.resolveFromRequire(value);
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ export interface DotIndicatorOptions {
visible?: boolean;
}

export type ImageResource = string;

export interface OptionsBottomTab {
dotIndicator?: DotIndicatorOptions;

Expand All @@ -572,7 +574,7 @@ export interface OptionsBottomTab {
* Set the tab icon
* Note: On Android `icon` is required
*/
icon?: ImageRequireSource;
icon?: ImageRequireSource | ImageResource;
/**
* Set the icon tint
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
"idiom" : "iphone",
"filename" : "Icon-180.png",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "clear@2x.ios.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added playground/ios/playground/clear@2x.ios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aa1870a

Please sign in to comment.