Skip to content

Commit

Permalink
Add popToRoot option to bottomTab on Android (wix#7244)
Browse files Browse the repository at this point in the history
  • Loading branch information
svbutko authored Sep 3, 2021
1 parent e19ff8c commit 67b5798
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static BottomTabOptions parse(Context context, TypefaceLoader typefaceMan
options.selectedFontSize = NumberParser.parse(json, "selectedFontSize");
options.dotIndicator = DotIndicatorOptions.parse(context, json.optJSONObject("dotIndicator"));
options.selectTabOnPress = BoolParser.parse(json, "selectTabOnPress");
options.popToRoot = BoolParser.parse(json, "popToRoot");

return options;
}
Expand All @@ -64,6 +65,7 @@ public static BottomTabOptions parse(Context context, TypefaceLoader typefaceMan
public Number fontSize = new NullNumber();
public Number selectedFontSize = new NullNumber();
public Bool selectTabOnPress = new NullBool();
public Bool popToRoot = new NullBool();
public FontOptions font = new FontOptions();


Expand All @@ -87,6 +89,7 @@ void mergeWith(final BottomTabOptions other) {
font.mergeWith(other.font);
if (other.dotIndicator.hasValue()) dotIndicator = other.dotIndicator;
if (other.selectTabOnPress.hasValue()) selectTabOnPress = other.selectTabOnPress;
if (other.popToRoot.hasValue()) popToRoot = other.popToRoot;
}

void mergeWithDefault(final BottomTabOptions defaultOptions) {
Expand All @@ -109,6 +112,7 @@ void mergeWithDefault(final BottomTabOptions defaultOptions) {
if (!testId.hasValue()) testId = defaultOptions.testId;
if (!dotIndicator.hasValue()) dotIndicator = defaultOptions.dotIndicator;
if (!selectTabOnPress.hasValue()) selectTabOnPress = defaultOptions.selectTabOnPress;
if (!popToRoot.hasValue()) popToRoot = defaultOptions.popToRoot;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public boolean onTabSelected(int index, boolean wasSelected) {
}
}

if (wasSelected && stack instanceof StackController) {
if (options.popToRoot.get(false) && wasSelected && stack instanceof StackController) {
((StackController) stack).popToRoot(Options.EMPTY, new CommandListenerAdapter());
}

Expand Down
5 changes: 5 additions & 0 deletions lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,11 @@ export interface OptionsBottomTab {
* instead it will emit a bottomTabPressedEvent
*/
selectTabOnPress?: boolean;
/**
* Pop to root of stack by tapping on already selected tab
* #### (Android specific)
*/
popToRoot?: boolean;
}

export interface SideMenuSide {
Expand Down
8 changes: 8 additions & 0 deletions website/docs/api/options-bottomTab.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ const options = {
| ------- | -------- | -------- |
| boolean | No | Both |

## `popToRoot`

Pop to root of stack by tapping on already selected tab.

| Type | Required | Platform |
| ------- | -------- | --------- |
| boolean | No | Android |

## `badge`

| Type | Required | Platform |
Expand Down

0 comments on commit 67b5798

Please sign in to comment.