diff --git a/lib/android/app/build.gradle b/lib/android/app/build.gradle index be8a3781f4e..473d9bfc440 100644 --- a/lib/android/app/build.gradle +++ b/lib/android/app/build.gradle @@ -93,6 +93,10 @@ android { dimension "RNN.reactNativeVersion" buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "62") } + reactNative63 { + dimension "RNN.reactNativeVersion" + buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "63") + } } def flavor = resolveFlavor() @@ -109,7 +113,9 @@ String resolveFlavor() { Integer reactNativeMinorComponent = reactNativeVersionComponents[1].toInteger() Integer reactNativePatchComponent = reactNativeVersionComponents[2].toInteger() - if (reactNativeMinorComponent >= 62) { + if (reactNativeMinorComponent >= 63) { + return "reactNative63" + } else if (reactNativeMinorComponent >= 62) { return "reactNative62" } else if (reactNativeMinorComponent >= 60) { return "reactNative60" diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/BackButton.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/BackButton.java index ad291fb6409..b65b35d1b54 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/BackButton.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/BackButton.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.NullBool; import com.reactnativenavigation.options.params.Text; @@ -11,7 +13,7 @@ import org.json.JSONObject; public class BackButton extends ButtonOptions { - public static BackButton parse(JSONObject json) { + public static BackButton parse(Context context, JSONObject json) { BackButton result = new BackButton(); if (json == null || json.toString().equals("{}")) return result; @@ -22,8 +24,8 @@ public static BackButton parse(JSONObject json) { result.id = json.optString("id", Constants.BACK_BUTTON_ID); result.enabled = BoolParser.parse(json, "enabled"); result.disableIconTint = BoolParser.parse(json, "disableIconTint"); - result.color = ColorParser.parse(json, "color"); - result.disabledColor = ColorParser.parse(json, "disabledColor"); + result.color = ColorParser.parse(context, json, "color"); + result.disabledColor = ColorParser.parse(context, json, "disabledColor"); result.testId = TextParser.parse(json, "testID"); return result; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java index 32b5b212b1c..8c0a53e222c 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java @@ -1,5 +1,6 @@ package com.reactnativenavigation.options; +import android.content.Context; import android.graphics.Typeface; import com.reactnativenavigation.options.params.Bool; @@ -23,25 +24,25 @@ public class BottomTabOptions { - public static BottomTabOptions parse(TypefaceLoader typefaceManager, JSONObject json) { + public static BottomTabOptions parse(Context context, TypefaceLoader typefaceManager, JSONObject json) { BottomTabOptions options = new BottomTabOptions(); if (json == null) return options; options.text = TextParser.parse(json, "text"); - options.textColor = ColorParser.parse(json, "textColor"); - options.selectedTextColor = ColorParser.parse(json, "selectedTextColor"); + options.textColor = ColorParser.parse(context, json, "textColor"); + options.selectedTextColor = ColorParser.parse(context, json, "selectedTextColor"); 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.iconColor = ColorParser.parse(context, json, "iconColor"); + options.selectedIconColor = ColorParser.parse(context, json, "selectedIconColor"); options.badge = TextParser.parse(json, "badge"); - options.badgeColor = ColorParser.parse(json, "badgeColor"); + options.badgeColor = ColorParser.parse(context, json, "badgeColor"); options.animateBadge = BoolParser.parse(json, "animateBadge"); options.testId = TextParser.parse(json, "testID"); options.fontFamily = typefaceManager.getTypeFace(json.optString("fontFamily", "")); options.fontSize = NumberParser.parse(json, "fontSize"); options.selectedFontSize = NumberParser.parse(json, "selectedFontSize"); - options.dotIndicator = DotIndicatorOptions.parse(json.optJSONObject("dotIndicator")); + options.dotIndicator = DotIndicatorOptions.parse(context, json.optJSONObject("dotIndicator")); options.selectTabOnPress = BoolParser.parse(json, "selectTabOnPress"); return options; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabsOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabsOptions.java index 7563c917b84..9db22979d36 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabsOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabsOptions.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.Fraction; @@ -21,11 +23,11 @@ public class BottomTabsOptions { - public static BottomTabsOptions parse(JSONObject json) { + public static BottomTabsOptions parse(Context context, JSONObject json) { BottomTabsOptions options = new BottomTabsOptions(); if (json == null) return options; - options.backgroundColor = ColorParser.parse(json, "backgroundColor"); + options.backgroundColor = ColorParser.parse(context, json, "backgroundColor"); options.currentTabId = TextParser.parse(json, "currentTabId"); options.currentTabIndex = NumberParser.parse(json,"currentTabIndex"); options.hideOnScroll = BoolParser.parse(json, "hideOnScroll"); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/ButtonOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/ButtonOptions.java index 3da42c0fd5e..a5143419f92 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/ButtonOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/ButtonOptions.java @@ -1,5 +1,6 @@ package com.reactnativenavigation.options; +import android.content.Context; import android.graphics.Typeface; import android.view.MenuItem; @@ -68,7 +69,7 @@ public boolean equals(ButtonOptions other) { component.equals(other.component); } - private static ButtonOptions parseJson(JSONObject json, TypefaceLoader typefaceManager) { + private static ButtonOptions parseJson(Context context, JSONObject json, TypefaceLoader typefaceManager) { ButtonOptions button = new ButtonOptions(); button.id = take(json.optString("id"), "btn" + CompatUtils.generateViewId()); button.accessibilityLabel = TextParser.parse(json, "accessibilityLabel"); @@ -77,8 +78,8 @@ private static ButtonOptions parseJson(JSONObject json, TypefaceLoader typefaceM button.enabled = BoolParser.parse(json, "enabled"); button.disableIconTint = BoolParser.parse(json, "disableIconTint"); button.showAsAction = parseShowAsAction(json); - button.color = ColorParser.parse(json, "color"); - button.disabledColor = ColorParser.parse(json, "disabledColor"); + button.color = ColorParser.parse(context, json, "color"); + button.disabledColor = ColorParser.parse(context, json, "disabledColor"); button.fontSize = FractionParser.parse(json, "fontSize"); button.fontFamily = typefaceManager.getTypeFace(json.optString("fontFamily", "")); button.fontWeight = TextParser.parse(json, "fontWeight"); @@ -92,7 +93,7 @@ private static ButtonOptions parseJson(JSONObject json, TypefaceLoader typefaceM return button; } - public static ArrayList parse(JSONObject json, String buttonsType, TypefaceLoader typefaceLoader) { + public static ArrayList parse(Context context, JSONObject json, String buttonsType, TypefaceLoader typefaceLoader) { ArrayList buttons = new ArrayList<>(); if (!json.has(buttonsType)) { return null; @@ -100,18 +101,18 @@ public static ArrayList parse(JSONObject json, String buttonsType JSONArray jsonArray = json.optJSONArray(buttonsType); if (jsonArray != null) { - buttons.addAll(parseJsonArray(jsonArray, typefaceLoader)); + buttons.addAll(parseJsonArray(context, jsonArray, typefaceLoader)); } else { - buttons.add(parseJson(json.optJSONObject(buttonsType), typefaceLoader)); + buttons.add(parseJson(context, json.optJSONObject(buttonsType), typefaceLoader)); } return buttons; } - private static ArrayList parseJsonArray(JSONArray jsonArray, TypefaceLoader typefaceLoader) { + private static ArrayList parseJsonArray(Context context, JSONArray jsonArray, TypefaceLoader typefaceLoader) { ArrayList buttons = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.optJSONObject(i); - ButtonOptions button = ButtonOptions.parseJson(json, typefaceLoader); + ButtonOptions button = ButtonOptions.parseJson(context, json, typefaceLoader); buttons.add(button); } return buttons; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/DotIndicatorOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/DotIndicatorOptions.java index 66cd54d6585..a3678a5c811 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/DotIndicatorOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/DotIndicatorOptions.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.NullBool; @@ -15,11 +17,11 @@ import androidx.annotation.Nullable; public class DotIndicatorOptions { - public static DotIndicatorOptions parse(@Nullable JSONObject json) { + public static DotIndicatorOptions parse(Context context, @Nullable JSONObject json) { DotIndicatorOptions options = new DotIndicatorOptions(); if (json == null) return options; - options.color = ColorParser.parse(json, "color"); + options.color = ColorParser.parse(context, json, "color"); options.size = NumberParser.parse(json, "size"); options.visible = BoolParser.parse(json, "visible"); options.animate = BoolParser.parse(json, "animate"); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/FabOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/FabOptions.java index ad330fe99b7..f6684b4089d 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/FabOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/FabOptions.java @@ -1,6 +1,8 @@ package com.reactnativenavigation.options; +import android.content.Context; + import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.NullBool; @@ -18,23 +20,23 @@ public class FabOptions { - public static FabOptions parse(JSONObject json) { + public static FabOptions parse(Context context, JSONObject json) { FabOptions options = new FabOptions(); if (json == null) return options; options.id = TextParser.parse(json, "id"); - options.backgroundColor = ColorParser.parse(json, "backgroundColor"); - options.clickColor = ColorParser.parse(json, "clickColor"); - options.rippleColor = ColorParser.parse(json, "rippleColor"); + options.backgroundColor = ColorParser.parse(context, json, "backgroundColor"); + options.clickColor = ColorParser.parse(context, json, "clickColor"); + options.rippleColor = ColorParser.parse(context, json, "rippleColor"); options.visible = BoolParser.parse(json, "visible"); if (json.has("icon")) { options.icon = TextParser.parse(json.optJSONObject("icon"), "uri"); } - options.iconColor = ColorParser.parse(json, "iconColor"); + options.iconColor = ColorParser.parse(context, json, "iconColor"); if (json.has("actions")) { JSONArray fabsArray = json.optJSONArray("actions"); for (int i = 0; i < fabsArray.length(); i++) { - options.actionsArray.add(FabOptions.parse(fabsArray.optJSONObject(i))); + options.actionsArray.add(FabOptions.parse(context, fabsArray.optJSONObject(i))); } } options.alignHorizontally = TextParser.parse(json, "alignHorizontally"); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java index 3d1ba11973a..7678f0f153a 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java @@ -3,6 +3,7 @@ import android.app.Activity; import com.facebook.react.ReactInstanceManager; +import com.facebook.react.bridge.ReactContext; import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabPresenter; import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsPresenter; import com.reactnativenavigation.viewcontrollers.component.ComponentPresenter; @@ -69,17 +70,18 @@ public void init(Activity activity, EventEmitter eventEmitter, ChildControllersR } public ViewController create(final LayoutNode node) { + final ReactContext context = reactInstanceManager.getCurrentReactContext(); switch (node.type) { case Component: - return createComponent(node); + return createComponent(context, node); case ExternalComponent: - return createExternalComponent(node); + return createExternalComponent(context, node); case Stack: - return createStack(node); + return createStack(context, node); case BottomTabs: - return createBottomTabs(node); + return createBottomTabs(context, node); case SideMenuRoot: - return createSideMenuRoot(node); + return createSideMenuRoot(context, node); case SideMenuCenter: return createSideMenuContent(node); case SideMenuLeft: @@ -87,17 +89,17 @@ public ViewController create(final LayoutNode node) { case SideMenuRight: return createSideMenuRight(node); case TopTabs: - return createTopTabs(node); + return createTopTabs(context, node); default: throw new IllegalArgumentException("Invalid node type: " + node.type); } } - private ViewController createSideMenuRoot(LayoutNode node) { + private ViewController createSideMenuRoot(ReactContext context, LayoutNode node) { SideMenuController sideMenuController = new SideMenuController(activity, childRegistry, node.id, - parse(typefaceManager, node.getOptions()), + parse(context, typefaceManager, node.getOptions()), new SideMenuPresenter(), new Presenter(activity, defaultOptions) ); @@ -149,7 +151,7 @@ private ViewController createSideMenuRight(LayoutNode node) { return create(node.children.get(0)); } - private ViewController createComponent(LayoutNode node) { + private ViewController createComponent(ReactContext context, LayoutNode node) { String id = node.id; String name = node.data.optString("name"); return new ComponentViewController(activity, @@ -157,13 +159,13 @@ private ViewController createComponent(LayoutNode node) { id, name, new ComponentViewCreator(reactInstanceManager), - parse(typefaceManager, node.getOptions()), + parse(context, typefaceManager, node.getOptions()), new Presenter(activity, defaultOptions), new ComponentPresenter(defaultOptions) ); } - private ViewController createExternalComponent(LayoutNode node) { + private ViewController createExternalComponent(ReactContext context, LayoutNode node) { final ExternalComponent externalComponent = ExternalComponent.parse(node.data); return new ExternalComponentViewController(activity, childRegistry, @@ -172,19 +174,19 @@ private ViewController createExternalComponent(LayoutNode node) { externalComponent, externalComponentCreators.get(externalComponent.name.get()), reactInstanceManager, - new EventEmitter(reactInstanceManager.getCurrentReactContext()), + new EventEmitter(context), new ExternalComponentPresenter(), - parse(typefaceManager, node.getOptions()) + parse(context, typefaceManager, node.getOptions()) ); } - private ViewController createStack(LayoutNode node) { + private ViewController createStack(ReactContext context, LayoutNode node) { return new StackControllerBuilder(activity, eventEmitter) .setChildren(createChildren(node.children)) .setChildRegistry(childRegistry) .setTopBarController(new TopBarController()) .setId(node.id) - .setInitialOptions(parse(typefaceManager, node.getOptions())) + .setInitialOptions(parse(context, typefaceManager, node.getOptions())) .setStackPresenter(new StackPresenter(activity, new TitleBarReactViewCreator(reactInstanceManager), new TopBarBackgroundViewCreator(reactInstanceManager), @@ -205,7 +207,7 @@ private List createChildren(List children) { return result; } - private ViewController createBottomTabs(LayoutNode node) { + private ViewController createBottomTabs(ReactContext context, LayoutNode node) { List tabs = new ArrayList<>(); for (int i = 0; i < node.children.size(); i++) { tabs.add(create(node.children.get(i))); @@ -217,22 +219,22 @@ private ViewController createBottomTabs(LayoutNode node) { eventEmitter, new ImageLoader(), node.id, - parse(typefaceManager, node.getOptions()), + parse(context, typefaceManager, node.getOptions()), new Presenter(activity, defaultOptions), new BottomTabsAttacher(tabs, bottomTabsPresenter, defaultOptions), bottomTabsPresenter, new BottomTabPresenter(activity, tabs, new ImageLoader(), defaultOptions)); } - private ViewController createTopTabs(LayoutNode node) { + private ViewController createTopTabs(ReactContext context, LayoutNode node) { final List tabs = new ArrayList<>(); for (int i = 0; i < node.children.size(); i++) { ViewController tabController = create(node.children.get(i)); - Options options = parse(typefaceManager, node.children.get(i).getOptions()); + Options options = parse(context, typefaceManager, node.children.get(i).getOptions()); options.setTopTabIndex(i); tabs.add(tabController); } - return new TopTabsController(activity, childRegistry, node.id, tabs, new TopTabsLayoutCreator(activity, tabs), parse(typefaceManager, node.getOptions()), new Presenter(activity, defaultOptions)); + return new TopTabsController(activity, childRegistry, node.id, tabs, new TopTabsLayoutCreator(activity, tabs), parse(context, typefaceManager, node.getOptions()), new Presenter(activity, defaultOptions)); } @NonNull diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutOptions.java index 136be653c36..5c1833b562e 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutOptions.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.NullColor; import com.reactnativenavigation.options.params.NullNumber; @@ -10,12 +12,12 @@ import org.json.JSONObject; public class LayoutOptions { - public static LayoutOptions parse(JSONObject json) { + public static LayoutOptions parse(Context context, JSONObject json) { LayoutOptions result = new LayoutOptions(); if (json == null) return result; - result.backgroundColor = ColorParser.parse(json, "backgroundColor"); - result.componentBackgroundColor = ColorParser.parse(json, "componentBackgroundColor"); + result.backgroundColor = ColorParser.parse(context, json, "backgroundColor"); + result.componentBackgroundColor = ColorParser.parse(context, json, "componentBackgroundColor"); result.topMargin = NumberParser.parse(json, "topMargin"); result.orientation = OrientationOptions.parse(json); result.direction = LayoutDirection.fromString(json.optString("direction", "")); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/NavigationBarOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/NavigationBarOptions.java index ae02e70baee..35d71119631 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/NavigationBarOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/NavigationBarOptions.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.NullBool; @@ -10,11 +12,11 @@ import org.json.JSONObject; public class NavigationBarOptions { - public static NavigationBarOptions parse(JSONObject json) { + public static NavigationBarOptions parse(Context context, JSONObject json) { NavigationBarOptions result = new NavigationBarOptions(); if (json == null) return result; - result.backgroundColor = ColorParser.parse(json, "backgroundColor"); + result.backgroundColor = ColorParser.parse(context, json, "backgroundColor"); result.isVisible = BoolParser.parse(json, "visible"); return result; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/Options.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/Options.java index 6018a01f005..7cbf49b0ace 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/Options.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/Options.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import com.reactnativenavigation.options.params.NullNumber; import com.reactnativenavigation.options.params.NullText; import com.reactnativenavigation.options.parsers.TypefaceLoader; @@ -13,23 +15,23 @@ public class Options { public static final Options EMPTY = new Options(); @NonNull - public static Options parse(TypefaceLoader typefaceManager, JSONObject json) { + public static Options parse(Context context, TypefaceLoader typefaceManager, JSONObject json) { Options result = new Options(); if (json == null) return result; - result.topBar = TopBarOptions.parse(typefaceManager, json.optJSONObject("topBar")); - result.topTabs = TopTabsOptions.parse(json.optJSONObject("topTabs")); + result.topBar = TopBarOptions.parse(context, typefaceManager, json.optJSONObject("topBar")); + result.topTabs = TopTabsOptions.parse(context, json.optJSONObject("topTabs")); result.topTabOptions = TopTabOptions.parse(typefaceManager, json.optJSONObject("topTab")); - result.bottomTabOptions = BottomTabOptions.parse(typefaceManager, json.optJSONObject("bottomTab")); - result.bottomTabsOptions = BottomTabsOptions.parse(json.optJSONObject("bottomTabs")); + result.bottomTabOptions = BottomTabOptions.parse(context, typefaceManager, json.optJSONObject("bottomTab")); + result.bottomTabsOptions = BottomTabsOptions.parse(context, json.optJSONObject("bottomTabs")); result.overlayOptions = OverlayOptions.parse(json.optJSONObject("overlay")); - result.fabOptions = FabOptions.parse(json.optJSONObject("fab")); + result.fabOptions = FabOptions.parse(context, json.optJSONObject("fab")); result.sideMenuRootOptions = SideMenuRootOptions.parse(json.optJSONObject("sideMenu")); result.animations = AnimationsOptions.parse(json.optJSONObject("animations")); result.modal = ModalOptions.parse(json); - result.navigationBar = NavigationBarOptions.parse(json.optJSONObject("navigationBar")); - result.statusBar = StatusBarOptions.parse(json.optJSONObject("statusBar")); - result.layout = LayoutOptions.parse(json.optJSONObject("layout")); + result.navigationBar = NavigationBarOptions.parse(context, json.optJSONObject("navigationBar")); + result.statusBar = StatusBarOptions.parse(context, json.optJSONObject("statusBar")); + result.layout = LayoutOptions.parse(context, json.optJSONObject("layout")); return result; } diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/StatusBarOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/StatusBarOptions.java index 7b34f324213..a1bfe56cd99 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/StatusBarOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/StatusBarOptions.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import androidx.annotation.Nullable; import com.reactnativenavigation.options.params.Bool; @@ -38,11 +40,11 @@ public boolean hasValue() { } } - public static StatusBarOptions parse(JSONObject json) { + public static StatusBarOptions parse(Context context, JSONObject json) { StatusBarOptions result = new StatusBarOptions(); if (json == null) return result; - result.backgroundColor = ColorParser.parse(json, "backgroundColor"); + result.backgroundColor = ColorParser.parse(context, json, "backgroundColor"); result.textColorScheme = TextColorScheme.fromString(json.optString("style")); result.visible = BoolParser.parse(json, "visible"); result.drawBehind = BoolParser.parse(json, "drawBehind"); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/SubtitleOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/SubtitleOptions.java index 098e0fb1760..478e53235be 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/SubtitleOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/SubtitleOptions.java @@ -1,5 +1,6 @@ package com.reactnativenavigation.options; +import android.content.Context; import android.graphics.Typeface; import androidx.annotation.Nullable; @@ -17,14 +18,14 @@ import org.json.JSONObject; public class SubtitleOptions { - public static SubtitleOptions parse(TypefaceLoader typefaceManager, JSONObject json) { + public static SubtitleOptions parse(Context context, TypefaceLoader typefaceManager, JSONObject json) { final SubtitleOptions options = new SubtitleOptions(); if (json == null) { return options; } options.text = TextParser.parse(json, "text"); - options.color = ColorParser.parse(json, "color"); + options.color = ColorParser.parse(context, json, "color"); options.fontSize = FractionParser.parse(json, "fontSize"); options.fontFamily = typefaceManager.getTypeFace(json.optString("fontFamily", "")); options.alignment = Alignment.fromString(TextParser.parse(json, "alignment").get("")); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/TitleOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/TitleOptions.java index 63f585bbcb0..00c0ddb544e 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/TitleOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/TitleOptions.java @@ -1,5 +1,6 @@ package com.reactnativenavigation.options; +import android.content.Context; import android.graphics.Typeface; import androidx.annotation.Nullable; @@ -21,13 +22,13 @@ public class TitleOptions { - public static TitleOptions parse(TypefaceLoader typefaceManager, JSONObject json) { + public static TitleOptions parse(Context context, TypefaceLoader typefaceManager, JSONObject json) { final TitleOptions options = new TitleOptions(); if (json == null) return options; options.component = ComponentOptions.parse(json.optJSONObject("component")); options.text = TextParser.parse(json, "text"); - options.color = ColorParser.parse(json, "color"); + options.color = ColorParser.parse(context, json, "color"); options.fontSize = FractionParser.parse(json, "fontSize"); options.fontFamily = typefaceManager.getTypeFace(json.optString("fontFamily", "")); options.alignment = Alignment.fromString(TextParser.parse(json, "alignment").get("")); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarBackgroundOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarBackgroundOptions.java index 8d7ccf5e369..883d4a6174b 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarBackgroundOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarBackgroundOptions.java @@ -1,5 +1,6 @@ package com.reactnativenavigation.options; +import android.content.Context; import android.graphics.Color; import com.reactnativenavigation.options.params.Bool; @@ -12,11 +13,11 @@ import org.json.JSONObject; public class TopBarBackgroundOptions { - public static TopBarBackgroundOptions parse(JSONObject json) { + public static TopBarBackgroundOptions parse(Context context, JSONObject json) { TopBarBackgroundOptions options = new TopBarBackgroundOptions(); if (json == null) return options; - options.color = ColorParser.parse(json, "color"); + options.color = ColorParser.parse(context, json, "color"); options.component = ComponentOptions.parse(json.optJSONObject("component")); options.waitForRender = BoolParser.parse(json, "waitForRender"); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarButtons.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarButtons.java index 444b2c25015..4b17bd3ec34 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarButtons.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarButtons.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import androidx.annotation.Nullable; import com.reactnativenavigation.utils.CollectionUtils; @@ -11,20 +13,20 @@ public class TopBarButtons { - public static TopBarButtons parse(TypefaceLoader typefaceLoader, JSONObject json) { + public static TopBarButtons parse(Context context, TypefaceLoader typefaceLoader, JSONObject json) { TopBarButtons result = new TopBarButtons(); if (json == null) return result; - result.right = parseButtons(typefaceLoader, json, "rightButtons"); - result.left = parseButtons(typefaceLoader, json, "leftButtons"); - result.back = BackButton.parse(json.optJSONObject("backButton")); + result.right = parseButtons(context, typefaceLoader, json, "rightButtons"); + result.left = parseButtons(context, typefaceLoader, json, "leftButtons"); + result.back = BackButton.parse(context, json.optJSONObject("backButton")); return result; } @Nullable - private static ArrayList parseButtons(TypefaceLoader typefaceLoader, JSONObject json, String buttons) { - return ButtonOptions.parse(json, buttons, typefaceLoader); + private static ArrayList parseButtons(Context context, TypefaceLoader typefaceLoader, JSONObject json, String buttons) { + return ButtonOptions.parse(context, json, buttons, typefaceLoader); } public BackButton back = new BackButton(); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarOptions.java index 34f16268d5e..11e74794781 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarOptions.java @@ -1,6 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; import android.util.Log; import com.reactnativenavigation.BuildConfig; @@ -25,29 +26,29 @@ public class TopBarOptions { - public static TopBarOptions parse(TypefaceLoader typefaceLoader, JSONObject json) { + public static TopBarOptions parse(Context context, TypefaceLoader typefaceLoader, JSONObject json) { TopBarOptions options = new TopBarOptions(); if (json == null) return options; - options.title = TitleOptions.parse(typefaceLoader, json.optJSONObject("title")); - options.subtitle = SubtitleOptions.parse(typefaceLoader, json.optJSONObject("subtitle")); - options.background = TopBarBackgroundOptions.parse(json.optJSONObject("background")); + options.title = TitleOptions.parse(context, typefaceLoader, json.optJSONObject("title")); + options.subtitle = SubtitleOptions.parse(context, typefaceLoader, json.optJSONObject("subtitle")); + options.background = TopBarBackgroundOptions.parse(context, json.optJSONObject("background")); options.visible = BoolParser.parse(json, "visible"); options.animate = BoolParser.parse(json,"animate"); options.hideOnScroll = BoolParser.parse(json,"hideOnScroll"); options.drawBehind = BoolParser.parse(json,"drawBehind"); options.testId = TextParser.parse(json, "testID"); options.height = NumberParser.parse(json, "height"); - options.borderColor = ColorParser.parse(json, "borderColor"); + options.borderColor = ColorParser.parse(context, json, "borderColor"); options.borderHeight = FractionParser.parse(json, "borderHeight"); options.elevation = FractionParser.parse(json, "elevation"); options.topMargin = NumberParser.parse(json, "topMargin"); - options.buttons = TopBarButtons.parse(typefaceLoader, json); + options.buttons = TopBarButtons.parse(context, typefaceLoader, json); - options.rightButtonColor = ColorParser.parse(json, "rightButtonColor"); - options.leftButtonColor = ColorParser.parse(json, "leftButtonColor"); - options.leftButtonDisabledColor = ColorParser.parse(json, "leftButtonDisabledColor"); - options.rightButtonDisabledColor = ColorParser.parse(json, "rightButtonDisabledColor"); + options.rightButtonColor = ColorParser.parse(context, json, "rightButtonColor"); + options.leftButtonColor = ColorParser.parse(context, json, "leftButtonColor"); + options.leftButtonDisabledColor = ColorParser.parse(context, json, "leftButtonDisabledColor"); + options.rightButtonDisabledColor = ColorParser.parse(context, json, "rightButtonDisabledColor"); options.validate(); return options; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopTabsOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopTabsOptions.java index 7540518f56b..1a1d3c2aa87 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopTabsOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopTabsOptions.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options; +import android.content.Context; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -23,11 +25,11 @@ public class TopTabsOptions { @NonNull public Bool visible = new NullBool(); @NonNull public Number height = new NullNumber(); - public static TopTabsOptions parse(@Nullable JSONObject json) { + public static TopTabsOptions parse(Context context, @Nullable JSONObject json) { TopTabsOptions result = new TopTabsOptions(); if (json == null) return result; - result.selectedTabColor = ColorParser.parse(json, "selectedTabColor"); - result.unselectedTabColor = ColorParser.parse(json, "unselectedTabColor"); + result.selectedTabColor = ColorParser.parse(context, json, "selectedTabColor"); + result.unselectedTabColor = ColorParser.parse(context, json, "unselectedTabColor"); result.fontSize = NumberParser.parse(json, "fontSize"); result.visible = BoolParser.parse(json, "visible"); result.height = NumberParser.parse(json, "height"); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/JSONParser.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/JSONParser.java index 38172a66182..09b91606ed5 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/JSONParser.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/JSONParser.java @@ -3,11 +3,17 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; +import com.facebook.react.bridge.WritableArray; +import com.facebook.react.bridge.WritableMap; +import com.facebook.react.bridge.WritableNativeArray; +import com.facebook.react.bridge.WritableNativeMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.util.Iterator; + public class JSONParser { public JSONObject parse(ReadableMap map) { try { @@ -90,4 +96,56 @@ private static Object parseNumber(ReadableArray arr, int index) { return arr.getInt(index); } } + + public static WritableMap convert(JSONObject jsonObject) { + WritableMap map = new WritableNativeMap(); + + Iterator iterator = jsonObject.keys(); + while (iterator.hasNext()) { + String key = iterator.next(); + Object value = jsonObject.opt(key); + if (value instanceof JSONObject) { + map.putMap(key, convert((JSONObject) value)); + } else if (value instanceof JSONArray) { + map.putArray(key, convert((JSONArray) value)); + } else if (value instanceof Boolean) { + map.putBoolean(key, (Boolean) value); + } else if (value instanceof Integer) { + map.putInt(key, (Integer) value); + } else if (value instanceof Double) { + map.putDouble(key, (Double) value); + } else if (value instanceof String) { + map.putString(key, (String) value); + } else { + map.putString(key, value.toString()); + } + } + + return map; + } + + public static WritableArray convert(JSONArray jsonArray) { + WritableArray array = new WritableNativeArray(); + + for (int i = 0; i < jsonArray.length(); i++) { + Object value = jsonArray.opt(i); + if (value instanceof JSONObject) { + array.pushMap(convert((JSONObject) value)); + } else if (value instanceof JSONArray) { + array.pushArray(convert((JSONArray) value)); + } else if (value instanceof Boolean) { + array.pushBoolean((Boolean) value); + } else if (value instanceof Integer) { + array.pushInt((Integer) value); + } else if (value instanceof Double) { + array.pushDouble((Double) value); + } else if (value instanceof String) { + array.pushString((String) value); + } else { + array.pushString(value.toString()); + } + } + + return array; + } } diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java b/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java index 71f62d262f6..3bfbc0b4083 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java @@ -189,8 +189,9 @@ private Navigator navigator() { } private Options parse(@Nullable ReadableMap mergeOptions) { + ReactApplicationContext ctx = getReactApplicationContext(); return mergeOptions == - null ? Options.EMPTY : Options.parse(new TypefaceLoader(activity()), jsonParser.parse(mergeOptions)); + null ? Options.EMPTY : Options.parse(ctx, new TypefaceLoader(activity()), jsonParser.parse(mergeOptions)); } protected void handle(Runnable task) { diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative51/java/com/reactnativenavigation/options/parsers/ColorParser.java similarity index 80% rename from lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/ColorParser.java rename to lib/android/app/src/reactNative51/java/com/reactnativenavigation/options/parsers/ColorParser.java index e818c384816..f6ff316278a 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/ColorParser.java +++ b/lib/android/app/src/reactNative51/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -1,5 +1,7 @@ package com.reactnativenavigation.options.parsers; +import android.content.Context; + import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.DontApplyColour; import com.reactnativenavigation.options.params.NullColor; @@ -7,7 +9,7 @@ import org.json.JSONObject; public class ColorParser { - public static Colour parse(JSONObject json, String color) { + public static Colour parse(Context context, JSONObject json, String color) { if (json.has(color)) { return json.opt(color) instanceof Integer ? new Colour(json.optInt(color)) : new DontApplyColour(); } diff --git a/lib/android/app/src/reactNative55/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative55/java/com/reactnativenavigation/options/parsers/ColorParser.java new file mode 100644 index 00000000000..f6ff316278a --- /dev/null +++ b/lib/android/app/src/reactNative55/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -0,0 +1,18 @@ +package com.reactnativenavigation.options.parsers; + +import android.content.Context; + +import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.params.DontApplyColour; +import com.reactnativenavigation.options.params.NullColor; + +import org.json.JSONObject; + +public class ColorParser { + public static Colour parse(Context context, JSONObject json, String color) { + if (json.has(color)) { + return json.opt(color) instanceof Integer ? new Colour(json.optInt(color)) : new DontApplyColour(); + } + return new NullColor(); + } +} diff --git a/lib/android/app/src/reactNative56/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative56/java/com/reactnativenavigation/options/parsers/ColorParser.java new file mode 100644 index 00000000000..f6ff316278a --- /dev/null +++ b/lib/android/app/src/reactNative56/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -0,0 +1,18 @@ +package com.reactnativenavigation.options.parsers; + +import android.content.Context; + +import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.params.DontApplyColour; +import com.reactnativenavigation.options.params.NullColor; + +import org.json.JSONObject; + +public class ColorParser { + public static Colour parse(Context context, JSONObject json, String color) { + if (json.has(color)) { + return json.opt(color) instanceof Integer ? new Colour(json.optInt(color)) : new DontApplyColour(); + } + return new NullColor(); + } +} diff --git a/lib/android/app/src/reactNative57/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative57/java/com/reactnativenavigation/options/parsers/ColorParser.java new file mode 100644 index 00000000000..f6ff316278a --- /dev/null +++ b/lib/android/app/src/reactNative57/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -0,0 +1,18 @@ +package com.reactnativenavigation.options.parsers; + +import android.content.Context; + +import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.params.DontApplyColour; +import com.reactnativenavigation.options.params.NullColor; + +import org.json.JSONObject; + +public class ColorParser { + public static Colour parse(Context context, JSONObject json, String color) { + if (json.has(color)) { + return json.opt(color) instanceof Integer ? new Colour(json.optInt(color)) : new DontApplyColour(); + } + return new NullColor(); + } +} diff --git a/lib/android/app/src/reactNative57_5/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative57_5/java/com/reactnativenavigation/options/parsers/ColorParser.java new file mode 100644 index 00000000000..f6ff316278a --- /dev/null +++ b/lib/android/app/src/reactNative57_5/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -0,0 +1,18 @@ +package com.reactnativenavigation.options.parsers; + +import android.content.Context; + +import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.params.DontApplyColour; +import com.reactnativenavigation.options.params.NullColor; + +import org.json.JSONObject; + +public class ColorParser { + public static Colour parse(Context context, JSONObject json, String color) { + if (json.has(color)) { + return json.opt(color) instanceof Integer ? new Colour(json.optInt(color)) : new DontApplyColour(); + } + return new NullColor(); + } +} diff --git a/lib/android/app/src/reactNative60/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative60/java/com/reactnativenavigation/options/parsers/ColorParser.java new file mode 100644 index 00000000000..f6ff316278a --- /dev/null +++ b/lib/android/app/src/reactNative60/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -0,0 +1,18 @@ +package com.reactnativenavigation.options.parsers; + +import android.content.Context; + +import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.params.DontApplyColour; +import com.reactnativenavigation.options.params.NullColor; + +import org.json.JSONObject; + +public class ColorParser { + public static Colour parse(Context context, JSONObject json, String color) { + if (json.has(color)) { + return json.opt(color) instanceof Integer ? new Colour(json.optInt(color)) : new DontApplyColour(); + } + return new NullColor(); + } +} diff --git a/lib/android/app/src/reactNative62/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative62/java/com/reactnativenavigation/options/parsers/ColorParser.java new file mode 100644 index 00000000000..f6ff316278a --- /dev/null +++ b/lib/android/app/src/reactNative62/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -0,0 +1,18 @@ +package com.reactnativenavigation.options.parsers; + +import android.content.Context; + +import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.params.DontApplyColour; +import com.reactnativenavigation.options.params.NullColor; + +import org.json.JSONObject; + +public class ColorParser { + public static Colour parse(Context context, JSONObject json, String color) { + if (json.has(color)) { + return json.opt(color) instanceof Integer ? new Colour(json.optInt(color)) : new DontApplyColour(); + } + return new NullColor(); + } +} diff --git a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java new file mode 100644 index 00000000000..9ee17e9f455 --- /dev/null +++ b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/options/parsers/ColorParser.java @@ -0,0 +1,30 @@ +package com.reactnativenavigation.options.parsers; + +import android.content.Context; + +import com.facebook.react.bridge.ColorPropConverter; +import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.params.DontApplyColour; +import com.reactnativenavigation.options.params.NullColor; +import com.reactnativenavigation.options.parsers.JSONParser; + +import org.json.JSONObject; + +public class ColorParser { + public static Colour parse(Context context, JSONObject json, String colorName) { + if (json.has(colorName)) { + Object color = json.opt(colorName); + if (color == null) { + return new DontApplyColour(); + } else if (color instanceof Integer) { + return new Colour(json.optInt(colorName)); + } + Object convertedColor = JSONParser.convert(json.optJSONObject(colorName)); + Integer processedColor = ColorPropConverter.getColor(convertedColor, context); + if (processedColor != null) { + return new Colour(processedColor); + } + } + return new NullColor(); + } +} diff --git a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/DevBundleDownloadListenerAdapter.java b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/DevBundleDownloadListenerAdapter.java new file mode 100644 index 00000000000..d5ad33c75c5 --- /dev/null +++ b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/DevBundleDownloadListenerAdapter.java @@ -0,0 +1,22 @@ +package com.reactnativenavigation.react; + +import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener; + +import javax.annotation.Nullable; + +public class DevBundleDownloadListenerAdapter implements DevBundleDownloadListener, NavigationDevBundleDownloadListener { + @Override + public void onSuccess() { + onSuccess(); + } + + @Override + public void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total) { + + } + + @Override + public void onFailure(Exception cause) { + + } +} diff --git a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/JsDevReloadHandlerFacade.java b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/JsDevReloadHandlerFacade.java new file mode 100644 index 00000000000..feb40fb680e --- /dev/null +++ b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/JsDevReloadHandlerFacade.java @@ -0,0 +1,22 @@ +package com.reactnativenavigation.react; + +import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener; + +import javax.annotation.Nullable; + +public class JsDevReloadHandlerFacade implements DevBundleDownloadListener, NavigationDevBundleDownloadListener { + @Override + public void onSuccess() { + onSuccess(); + } + + @Override + public void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total) { + + } + + @Override + public void onFailure(Exception cause) { + + } +} diff --git a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/NavigationReactNativeHost.java b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/NavigationReactNativeHost.java new file mode 100644 index 00000000000..0391aa6d22e --- /dev/null +++ b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/NavigationReactNativeHost.java @@ -0,0 +1,67 @@ +package com.reactnativenavigation.react; + +import com.facebook.infer.annotation.Assertions; +import com.facebook.react.ReactInstanceManager; +import com.facebook.react.ReactInstanceManagerBuilder; +import com.facebook.react.ReactNativeHost; +import com.facebook.react.ReactPackage; +import com.facebook.react.common.LifecycleState; +import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener; +import com.reactnativenavigation.NavigationApplication; +import com.reactnativenavigation.react.DevBundleDownloadListenerAdapter; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public abstract class NavigationReactNativeHost extends ReactNativeHost implements BundleDownloadListenerProvider { + + private @Nullable NavigationDevBundleDownloadListener bundleListener; + private final DevBundleDownloadListener bundleListenerMediator = new DevBundleDownloadListenerAdapter() { + @Override + public void onSuccess() { + if (bundleListener != null) { + bundleListener.onSuccess(); + } + } + }; + + public NavigationReactNativeHost(NavigationApplication application) { + super(application); + } + + @Override + public void setBundleLoaderListener(NavigationDevBundleDownloadListener listener) { + bundleListener = listener; + } + + protected ReactInstanceManager createReactInstanceManager() { + ReactInstanceManagerBuilder builder = ReactInstanceManager.builder() + .setApplication(getApplication()) + .setJSMainModulePath(getJSMainModuleName()) + .setUseDeveloperSupport(getUseDeveloperSupport()) + .setRedBoxHandler(getRedBoxHandler()) + .setJavaScriptExecutorFactory(getJavaScriptExecutorFactory()) + .setUIImplementationProvider(getUIImplementationProvider()) + .setInitialLifecycleState(LifecycleState.BEFORE_CREATE) + .setJSIModulesPackage(getJSIModulePackage()) + .setDevBundleDownloadListener(getDevBundleDownloadListener()); + + for (ReactPackage reactPackage : getPackages()) { + builder.addPackage(reactPackage); + } + + String jsBundleFile = getJSBundleFile(); + if (jsBundleFile != null) { + builder.setJSBundleFile(jsBundleFile); + } else { + builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName())); + } + return builder.build(); + } + + @SuppressWarnings("WeakerAccess") + @NonNull + protected DevBundleDownloadListener getDevBundleDownloadListener() { + return bundleListenerMediator; + } +} \ No newline at end of file diff --git a/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/ReloadHandlerFacade.java b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/ReloadHandlerFacade.java new file mode 100644 index 00000000000..f30f66b91b6 --- /dev/null +++ b/lib/android/app/src/reactNative63/java/com/reactnativenavigation/react/ReloadHandlerFacade.java @@ -0,0 +1,22 @@ +package com.reactnativenavigation.react; + +import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener; + +import javax.annotation.Nullable; + +public abstract class ReloadHandlerFacade implements DevBundleDownloadListener { + @Override + public void onSuccess() { + + } + + @Override + public void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total) { + + } + + @Override + public void onFailure(Exception cause) { + + } +} diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java index ee815842172..f63bd8beb4f 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java @@ -65,7 +65,7 @@ public void beforeEach() { @Test public void parsesNullAsDefaultEmptyOptions() { - assertThat(Options.parse(mockLoader, null)).isNotNull(); + assertThat(Options.parse(null, mockLoader, null)).isNotNull(); } @Test @@ -77,7 +77,7 @@ public void parsesJson() throws Exception { .put("fab", createFab()) .put("bottomTabs", createBottomTabs()) .put("layout", layout); - Options result = Options.parse(mockLoader, json); + Options result = Options.parse(null, mockLoader, json); assertResult(result); } @@ -200,12 +200,12 @@ private JSONObject createOtherBottomTabs() throws JSONException { public void mergeDoesNotMutate() throws Exception { JSONObject json1 = new JSONObject(); json1.put("topBar", createTopBar(true)); - Options options1 = Options.parse(mockLoader, json1); + Options options1 = Options.parse(null, mockLoader, json1); options1.topBar.title.text = new Text("some title"); JSONObject json2 = new JSONObject(); json2.put("topBar", createTopBar(false)); - Options options2 = Options.parse(mockLoader, json2); + Options options2 = Options.parse(null, mockLoader, json2); options2.topBar.title.text = new NullText(); Options merged = options1.mergeWith(options2); @@ -223,7 +223,7 @@ public void mergeDefaultOptions() throws Exception { .put("fab", createFab()) .put("bottomTabs", createBottomTabs()) .put("layout", layout); - Options defaultOptions = Options.parse(mockLoader, json); + Options defaultOptions = Options.parse(null, mockLoader, json); Options options = new Options(); assertResult(options.mergeWith(defaultOptions)); @@ -238,12 +238,12 @@ public void mergedDefaultOptionsDontOverrideGivenOptions() throws Exception { .put("fab", createOtherFab()) .put("bottomTabs", createOtherBottomTabs()) .put("layout", layout); - Options defaultOptions = Options.parse(mockLoader, defaultJson); + Options defaultOptions = Options.parse(null, mockLoader, defaultJson); JSONObject json = new JSONObject() .put("topBar", createTopBar(TOP_BAR_VISIBLE.get())) .put("bottomTabs", createBottomTabs()); - Options options = Options.parse(mockLoader, json); + Options options = Options.parse(null, mockLoader, json); options.withDefaultOptions(defaultOptions); assertResult(options); } diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java index 30b2d6d868d..74f99c8673a 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/options/parsers/ColorParseTest.java @@ -15,6 +15,6 @@ public class ColorParseTest extends BaseTest { public void nullIsParsedAsNoColor() throws JSONException { JSONObject json = new JSONObject(); json.put("color", "NoColor"); - assertThat(ColorParser.parse(json, "color")).isInstanceOf(DontApplyColour.class); + assertThat(ColorParser.parse(null, json, "color")).isInstanceOf(DontApplyColour.class); } }