Skip to content

Commit

Permalink
Merge pull request #110 from deepueg/fix-hide-root-up-icon
Browse files Browse the repository at this point in the history
Hide the up indicator icon based on launch config
  • Loading branch information
deepueg authored Apr 27, 2020
2 parents 3f372fd + 41bec01 commit 3168c27
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ActivityDelegateConstants {
public static final String KEY_MINI_APP_COMPONENT_NAME = "miniAppComponentName";
public static final String KEY_MINI_APP_FRAGMENT_TAG = "miniAppFragmentTag";
public static final String KEY_MINI_APP_FRAGMENT_SHOW_UP_ENABLED = "displayHomeAsUpEnabled";
public static final String KEY_MINI_APP_FRAGMENT_HIDE_UP_INDICATOR = "hideUpIndicatorIcon";
public static final String KEY_REGISTER_NAV_VIEW_MODEL = "shouldRegisterNavViewModel";
}

Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public void startMiniAppFragment(@NonNull String componentName, @NonNull LaunchC
Bundle props = launchConfig.mInitialProps != null ? launchConfig.mInitialProps : new Bundle();
props.putString(ActivityDelegateConstants.KEY_MINI_APP_COMPONENT_NAME, componentName);
props.putBoolean(ActivityDelegateConstants.KEY_MINI_APP_FRAGMENT_SHOW_UP_ENABLED, shouldShowUpEnabled(launchConfig.mForceUpEnabled));
if (!launchConfig.mForceUpEnabled) {
props.putBoolean(ActivityDelegateConstants.KEY_MINI_APP_FRAGMENT_HIDE_UP_INDICATOR, launchConfig.mHideUpIndicatorIcon);
}
fragment.setArguments(props);

Logger.d(TAG, "starting fragment: fragmentClass->%s, props->%s", fragment.getClass().getSimpleName(), props);
Expand Down
22 changes: 22 additions & 0 deletions android/lib/src/main/java/com/ern/api/impl/core/LaunchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public class LaunchConfig {
*/
boolean mForceUpEnabled;

/**
* Set this to true if you want to hide the up indicator for a component
*/
boolean mHideUpIndicatorIcon;

/**
* Shows your next page view component as an overLay on top of the existing screen
* This flag is ignored if the component is the root component.
Expand Down Expand Up @@ -157,6 +162,23 @@ public void setForceUpEnabled(boolean forceUpEnabled) {
mForceUpEnabled = forceUpEnabled;
}

/**
* Set this to true will hide the up indicator for a given page.
* Setting this to false will do nothing but falling back to the default ActionBar behavior.
* i.e, if the app bar has an icon then it will show up and vice versa.
*/
public void setHideUpIndicatorIcon(boolean mHideUpIndicatorIcon) {
this.mHideUpIndicatorIcon = mHideUpIndicatorIcon;
}

/**
* Should hide up indicator for a component
* * @return true | false
*/
public boolean isHideUpIndicatorIcon() {
return mHideUpIndicatorIcon;
}

/**
* Shows your next page view component as an overLay on top of the existing screen
* This flag is ignored if the component is the root component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ protected LaunchConfig createDefaultLaunchConfig() {
defaultLaunchConfig.setFragmentContainerId(getFragmentContainerId());
defaultLaunchConfig.setFragmentManager(getSupportFragmentManager());
defaultLaunchConfig.updateInitialProps(getProps());
defaultLaunchConfig.setHideUpIndicatorIcon(true);
return defaultLaunchConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,15 @@ private void updateHomeAsUpIndicator(@Nullable NavigationBarLeftButton leftButto
}

//Default action
if (mFragment.getArguments() != null && mFragment.getArguments().getBoolean(ActivityDelegateConstants.KEY_MINI_APP_FRAGMENT_SHOW_UP_ENABLED)) {
Logger.d(TAG, "Defaulting up indicator for component: %s", getReactComponentName());
supportActionBar.setHomeAsUpIndicator(0);
supportActionBar.setDisplayHomeAsUpEnabled(true);
if (mFragment.getArguments() != null) {
if (mFragment.getArguments().getBoolean(ActivityDelegateConstants.KEY_MINI_APP_FRAGMENT_SHOW_UP_ENABLED)) {
Logger.d(TAG, "Enabling up indicator for component: %s", getReactComponentName());
supportActionBar.setHomeAsUpIndicator(0);
supportActionBar.setDisplayHomeAsUpEnabled(true);
} else if (mFragment.getArguments().getBoolean(ActivityDelegateConstants.KEY_MINI_APP_FRAGMENT_HIDE_UP_INDICATOR)) {
Logger.d(TAG, "Hiding up indicator for component: %s", getReactComponentName());
supportActionBar.setDisplayHomeAsUpEnabled(false);
}
}
} else {
Logger.i(TAG, "Action bar is null, skipping updateHomeAsUpIndicator");
Expand Down

0 comments on commit 3168c27

Please sign in to comment.