Skip to content

Commit 67b5798

Browse files
authored
Add popToRoot option to bottomTab on Android (#7244)
1 parent e19ff8c commit 67b5798

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static BottomTabOptions parse(Context context, TypefaceLoader typefaceMan
4343
options.selectedFontSize = NumberParser.parse(json, "selectedFontSize");
4444
options.dotIndicator = DotIndicatorOptions.parse(context, json.optJSONObject("dotIndicator"));
4545
options.selectTabOnPress = BoolParser.parse(json, "selectTabOnPress");
46+
options.popToRoot = BoolParser.parse(json, "popToRoot");
4647

4748
return options;
4849
}
@@ -64,6 +65,7 @@ public static BottomTabOptions parse(Context context, TypefaceLoader typefaceMan
6465
public Number fontSize = new NullNumber();
6566
public Number selectedFontSize = new NullNumber();
6667
public Bool selectTabOnPress = new NullBool();
68+
public Bool popToRoot = new NullBool();
6769
public FontOptions font = new FontOptions();
6870

6971

@@ -87,6 +89,7 @@ void mergeWith(final BottomTabOptions other) {
8789
font.mergeWith(other.font);
8890
if (other.dotIndicator.hasValue()) dotIndicator = other.dotIndicator;
8991
if (other.selectTabOnPress.hasValue()) selectTabOnPress = other.selectTabOnPress;
92+
if (other.popToRoot.hasValue()) popToRoot = other.popToRoot;
9093
}
9194

9295
void mergeWithDefault(final BottomTabOptions defaultOptions) {
@@ -109,6 +112,7 @@ void mergeWithDefault(final BottomTabOptions defaultOptions) {
109112
if (!testId.hasValue()) testId = defaultOptions.testId;
110113
if (!dotIndicator.hasValue()) dotIndicator = defaultOptions.dotIndicator;
111114
if (!selectTabOnPress.hasValue()) selectTabOnPress = defaultOptions.selectTabOnPress;
115+
if (!popToRoot.hasValue()) popToRoot = defaultOptions.popToRoot;
112116

113117
}
114118

lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public boolean onTabSelected(int index, boolean wasSelected) {
183183
}
184184
}
185185

186-
if (wasSelected && stack instanceof StackController) {
186+
if (options.popToRoot.get(false) && wasSelected && stack instanceof StackController) {
187187
((StackController) stack).popToRoot(Options.EMPTY, new CommandListenerAdapter());
188188
}
189189

lib/src/interfaces/Options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,11 @@ export interface OptionsBottomTab {
10051005
* instead it will emit a bottomTabPressedEvent
10061006
*/
10071007
selectTabOnPress?: boolean;
1008+
/**
1009+
* Pop to root of stack by tapping on already selected tab
1010+
* #### (Android specific)
1011+
*/
1012+
popToRoot?: boolean;
10081013
}
10091014

10101015
export interface SideMenuSide {

website/docs/api/options-bottomTab.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ const options = {
1717
| ------- | -------- | -------- |
1818
| boolean | No | Both |
1919

20+
## `popToRoot`
21+
22+
Pop to root of stack by tapping on already selected tab.
23+
24+
| Type | Required | Platform |
25+
| ------- | -------- | --------- |
26+
| boolean | No | Android |
27+
2028
## `badge`
2129

2230
| Type | Required | Platform |

0 commit comments

Comments
 (0)