123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- package com.reactnativenavigation.controllers;
-
- import android.content.Intent;
- import android.os.Bundle;
-
- import com.facebook.react.bridge.Callback;
- import com.reactnativenavigation.NavigationApplication;
- import com.reactnativenavigation.params.ActivityParams;
- import com.reactnativenavigation.params.ContextualMenuParams;
- import com.reactnativenavigation.params.FabParams;
- import com.reactnativenavigation.params.ScreenParams;
- import com.reactnativenavigation.params.SnackbarParams;
- import com.reactnativenavigation.params.TitleBarButtonParams;
- import com.reactnativenavigation.params.TitleBarLeftButtonParams;
- import com.reactnativenavigation.params.parsers.ActivityParamsParser;
- import com.reactnativenavigation.params.parsers.ScreenParamsParser;
- import com.reactnativenavigation.views.SideMenu.Side;
-
- import java.util.List;
-
- public class NavigationCommandsHandler {
-
- private static final String ACTIVITY_PARAMS_BUNDLE = "ACTIVITY_PARAMS_BUNDLE";
-
- static ActivityParams parseActivityParams(Intent intent) {
- return ActivityParamsParser.parse(intent.getBundleExtra(NavigationCommandsHandler.ACTIVITY_PARAMS_BUNDLE));
- }
-
- /**
- * start a new activity with CLEAR_TASK | NEW_TASK
- *
- * @param params ActivityParams as bundle
- */
-
- public static void startApp(Bundle params, boolean portraitOnlyMode, boolean landscapeOnlyMode) {
- Intent intent;
- if (portraitOnlyMode) {
- intent = new Intent(NavigationApplication.instance, PortraitNavigationActivity.class);
- } else if (landscapeOnlyMode) {
- intent = new Intent(NavigationApplication.instance, LandscapeNavigationActivity.class);
- } else {
- intent = new Intent(NavigationApplication.instance, NavigationActivity.class);
- }
- IntentDataHandler.setIntentData(intent);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(ACTIVITY_PARAMS_BUNDLE, params);
- NavigationApplication.instance.startActivity(intent);
- }
-
- public static void push(Bundle screenParams) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- final ScreenParams params = ScreenParamsParser.parse(screenParams);
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.push(params);
- }
- });
- }
-
- public static void pop(Bundle screenParams) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- final ScreenParams params = ScreenParamsParser.parse(screenParams);
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.pop(params);
- }
- });
- }
-
- public static void popToRoot(Bundle screenParams) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- final ScreenParams params = ScreenParamsParser.parse(screenParams);
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.popToRoot(params);
- }
- });
- }
-
- public static void newStack(Bundle screenParams) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- final ScreenParams params = ScreenParamsParser.parse(screenParams);
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.newStack(params);
- }
- });
- }
-
- public static void setTopBarVisible(final String screenInstanceID, final boolean hidden, final boolean animated) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setTopBarVisible(screenInstanceID, hidden, animated);
- }
- });
- }
-
- public static void setBottomTabsVisible(final boolean hidden, final boolean animated) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setBottomTabsVisible(hidden, animated);
- }
- });
- }
-
- public static void setScreenTitleBarTitle(final String screenInstanceId, final String title) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setTitleBarTitle(screenInstanceId, title);
- }
- });
- }
-
- public static void setScreenTitleBarSubtitle(final String screenInstanceId, final String subtitle) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setTitleBarSubtitle(screenInstanceId, subtitle);
- }
- });
- }
-
- public static void showModal(Bundle params) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- final ScreenParams screenParams = ScreenParamsParser.parse(params);
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.showModal(screenParams);
- }
- });
- }
-
- public static void setScreenTitleBarRightButtons(final String screenInstanceId,
- final String navigatorEventId,
- final List<TitleBarButtonParams> titleBarButtons) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setTitleBarButtons(screenInstanceId, navigatorEventId, titleBarButtons);
- }
- });
- }
-
- public static void setScreenTitleBarLeftButtons(final String screenInstanceId,
- final String navigatorEventId,
- final TitleBarLeftButtonParams titleBarButtons) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarButtons);
- }
- });
- }
-
- public static void setScreenFab(final String screenInstanceId, final String navigatorEventId, final FabParams fab) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setScreenFab(screenInstanceId, navigatorEventId, fab);
- }
- });
- }
-
- public static void dismissTopModal() {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.dismissTopModal();
- }
- });
- }
-
- public static void dismissAllModals() {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.dismissAllModals();
- }
- });
- }
-
- public static void toggleSideMenuVisible(final boolean animated, final Side side) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.toggleSideMenuVisible(animated, side);
- }
- });
- }
-
- public static void setSideMenuVisible(final boolean animated, final boolean visible, final Side side) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setSideMenuVisible(animated, visible, side);
- }
- });
- }
-
- public static void selectBottomTabByTabIndex(final Integer index) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.selectBottomTabByTabIndex(index);
- }
- });
- }
-
- public static void selectBottomTabByNavigatorId(final String navigatorId) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.selectBottomTabByNavigatorId(navigatorId);
- }
- });
- }
-
- public static void setBottomTabBadgeByIndex(final Integer index, final String badge) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setBottomTabBadgeByIndex(index, badge);
- }
- });
- }
-
- public static void setBottomTabBadgeByNavigatorId(final String navigatorId, final String badge) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.setBottomTabBadgeByNavigatorId(navigatorId, badge);
- }
- });
- }
-
- public static void showSnackbar(final SnackbarParams params) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.showSnackbar(params);
- }
- });
- }
-
- public static void showContextualMenu(final String screenInstanceId, final ContextualMenuParams params, final Callback onButtonClicked) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.showContextualMenu(screenInstanceId, params, onButtonClicked);
- }
- });
- }
-
- public static void dismissContextualMenu(final String screenInstanceId) {
- final NavigationActivity currentActivity = NavigationActivity.currentActivity;
- if (currentActivity == null) {
- return;
- }
-
- NavigationApplication.instance.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- currentActivity.dismissContextualMenu(screenInstanceId);
- }
- });
- }
- }
|