Skip to content

Commit ddfeefb

Browse files
authored
fix: properly pop to top (#485)
1 parent fc8b828 commit ddfeefb

File tree

7 files changed

+68
-13
lines changed

7 files changed

+68
-13
lines changed

.changeset/calm-singers-scream.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'react-native-bottom-tabs': minor
3+
'@bottom-tabs/react-navigation': minor
4+
---
5+
6+
fix: properly pop to top to resolve freezing issues

apps/example/ios/Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ PODS:
17481748
- React-RCTFBReactNativeSpec
17491749
- ReactCommon/turbomodule/core
17501750
- SocketRocket
1751-
- react-native-bottom-tabs (1.0.3):
1751+
- react-native-bottom-tabs (1.0.5):
17521752
- boost
17531753
- DoubleConversion
17541754
- fast_float
@@ -1766,7 +1766,7 @@ PODS:
17661766
- React-graphics
17671767
- React-ImageManager
17681768
- React-jsi
1769-
- react-native-bottom-tabs/common (= 1.0.3)
1769+
- react-native-bottom-tabs/common (= 1.0.5)
17701770
- React-NativeModulesApple
17711771
- React-RCTFabric
17721772
- React-renderercss
@@ -1778,7 +1778,7 @@ PODS:
17781778
- SocketRocket
17791779
- SwiftUIIntrospect (~> 1.0)
17801780
- Yoga
1781-
- react-native-bottom-tabs/common (1.0.3):
1781+
- react-native-bottom-tabs/common (1.0.5):
17821782
- boost
17831783
- DoubleConversion
17841784
- fast_float
@@ -2461,7 +2461,7 @@ PODS:
24612461
- ReactCommon/turbomodule/core
24622462
- SocketRocket
24632463
- Yoga
2464-
- RNScreens (4.16.0):
2464+
- RNScreens (4.18.0):
24652465
- boost
24662466
- DoubleConversion
24672467
- fast_float
@@ -2488,10 +2488,10 @@ PODS:
24882488
- ReactCodegen
24892489
- ReactCommon/turbomodule/bridging
24902490
- ReactCommon/turbomodule/core
2491-
- RNScreens/common (= 4.16.0)
2491+
- RNScreens/common (= 4.18.0)
24922492
- SocketRocket
24932493
- Yoga
2494-
- RNScreens/common (4.16.0):
2494+
- RNScreens/common (4.18.0):
24952495
- boost
24962496
- DoubleConversion
24972497
- fast_float
@@ -2842,7 +2842,7 @@ SPEC CHECKSUMS:
28422842
React-logger: a3cb5b29c32b8e447b5a96919340e89334062b48
28432843
React-Mapbuffer: 9d2434a42701d6144ca18f0ca1c4507808ca7696
28442844
React-microtasksnativemodule: 75b6604b667d297292345302cc5bfb6b6aeccc1b
2845-
react-native-bottom-tabs: 9a6f606d07e2e46f2535f1faed915fcb2d4f0269
2845+
react-native-bottom-tabs: 8e918142554e3878f043b23bdf93049b34a78ca6
28462846
react-native-safe-area-context: c6e2edd1c1da07bdce287fa9d9e60c5f7b514616
28472847
React-NativeModulesApple: 879fbdc5dcff7136abceb7880fe8a2022a1bd7c3
28482848
React-oscompat: 93b5535ea7f7dff46aaee4f78309a70979bdde9d
@@ -2878,7 +2878,7 @@ SPEC CHECKSUMS:
28782878
ReactTestApp-DevSupport: 9b7bbba5e8fed998e763809171d9906a1375f9d3
28792879
ReactTestApp-Resources: 4f6dff3b157f879757cd750caccd1d34a7eda647
28802880
RNGestureHandler: 3a73f098d74712952870e948b3d9cf7b6cae9961
2881-
RNScreens: 0bbf16c074ae6bb1058a7bf2d1ae017f4306797c
2881+
RNScreens: d821082c6dd1cb397cc0c98b026eeafaa68be479
28822882
RNVectorIcons: c13cc1db346e960ecd0aafcdd5d0bb458133b9c1
28832883
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
28842884
SwiftUIIntrospect: fee9aa07293ee280373a591e1824e8ddc869ba5d

apps/example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dependencies": {
1414
"@bottom-tabs/react-navigation": "*",
1515
"@react-navigation/bottom-tabs": "^7.4.7",
16+
"@react-navigation/devtools": "^7.0.44",
1617
"@react-navigation/native": "^7.1.17",
1718
"@react-navigation/native-stack": "^7.3.26",
1819
"@react-navigation/stack": "^7.4.8",
@@ -24,7 +25,7 @@
2425
"react-native-gesture-handler": "^2.28.0",
2526
"react-native-paper": "^5.14.5",
2627
"react-native-safe-area-context": "^5.6.1",
27-
"react-native-screens": "^4.16.0",
28+
"react-native-screens": "^4.18.0",
2829
"react-native-vector-icons": "^10.2.0"
2930
},
3031
"devDependencies": {

apps/example/src/App.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
Alert,
1313
Platform,
1414
} from 'react-native';
15-
import { NavigationContainer, useNavigation } from '@react-navigation/native';
15+
import {
16+
NavigationContainer,
17+
useNavigation,
18+
useNavigationContainerRef,
19+
} from '@react-navigation/native';
1620
import { createStackNavigator } from '@react-navigation/stack';
1721
import { createNativeStackNavigator } from '@react-navigation/native-stack';
1822
import { SafeAreaProvider } from 'react-native-safe-area-context';
@@ -31,6 +35,7 @@ import NativeBottomTabsUnmounting from './Examples/NativeBottomTabsUnmounting';
3135
import NativeBottomTabsCustomTabBar from './Examples/NativeBottomTabsCustomTabBar';
3236
import NativeBottomTabsFreezeOnBlur from './Examples/NativeBottomTabsFreezeOnBlur';
3337
import BottomAccessoryView from './Examples/BottomAccessoryView';
38+
import { useLogger } from '@react-navigation/devtools';
3439

3540
const HiddenTab = () => {
3641
return <FourTabs hideOneTab />;
@@ -194,9 +199,13 @@ export default function Navigation() {
194199

195200
const NavigationStack = mode === 'js' ? Stack : NativeStack;
196201

202+
const navigationRef = useNavigationContainerRef();
203+
204+
useLogger(navigationRef);
205+
197206
return (
198207
<SafeAreaProvider>
199-
<NavigationContainer>
208+
<NavigationContainer ref={navigationRef}>
200209
<NavigationStack.Navigator initialRouteName="BottomTabs Example">
201210
<NavigationStack.Screen
202211
name="BottomTabs Example"

packages/react-native-bottom-tabs/ios/TabItemEventModifier.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ private final class TabBarDelegate: NSObject, UITabBarControllerDelegate {
1717
}
1818
#endif
1919

20+
let isReselectingSameTab = tabBarController.selectedViewController == viewController
21+
22+
if isReselectingSameTab {
23+
if let index = tabBarController.viewControllers?.firstIndex(of: viewController) {
24+
_ = onClick?(index)
25+
}
26+
27+
return false
28+
}
29+
2030
// Unfortunately, due to iOS 26 new tab switching animations, controlling state from JavaScript is causing significant delays when switching tabs.
2131
// See: https://github.com/callstackincubator/react-native-bottom-tabs/issues/383
2232
// Due to this, whether the tab prevents default has to be defined statically.

packages/react-navigation/src/views/NativeBottomTabView.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export default function NativeBottomTabView({
8989
descriptors[route.key]?.options.preventsDefault
9090
}
9191
onIndexChange={(index) => {
92+
const focused = index === state.index;
9293
const route = state.routes[index];
9394
if (!route) {
9495
return;
@@ -101,6 +102,7 @@ export default function NativeBottomTabView({
101102
});
102103

103104
if (
105+
focused ||
104106
event.defaultPrevented ||
105107
descriptors[route.key]?.options.preventsDefault
106108
) {

yarn.lock

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5614,6 +5614,19 @@ __metadata:
56145614
languageName: node
56155615
linkType: hard
56165616

5617+
"@react-navigation/devtools@npm:^7.0.44":
5618+
version: 7.0.44
5619+
resolution: "@react-navigation/devtools@npm:7.0.44"
5620+
dependencies:
5621+
fast-deep-equal: "npm:^3.1.3"
5622+
nanoid: "npm:^3.3.11"
5623+
stacktrace-parser: "npm:^0.1.11"
5624+
peerDependencies:
5625+
react: ">= 18.2.0"
5626+
checksum: 10/67f7f7ebac0e222437b78cd3dc7d7ac5a00bad706809b18f02ceec716a077e7d5a851cbe6573fbd4828d9b4b6001f1b81564f28c705977581a6b6f080672ff3a
5627+
languageName: node
5628+
linkType: hard
5629+
56175630
"@react-navigation/elements@npm:^2.6.4":
56185631
version: 2.6.4
56195632
resolution: "@react-navigation/elements@npm:2.6.4"
@@ -15950,6 +15963,7 @@ __metadata:
1595015963
"@react-native/metro-config": "npm:0.81.4"
1595115964
"@react-native/typescript-config": "npm:0.81.4"
1595215965
"@react-navigation/bottom-tabs": "npm:^7.4.7"
15966+
"@react-navigation/devtools": "npm:^7.0.44"
1595315967
"@react-navigation/native": "npm:^7.1.17"
1595415968
"@react-navigation/native-stack": "npm:^7.3.26"
1595515969
"@react-navigation/stack": "npm:^7.4.8"
@@ -15965,7 +15979,7 @@ __metadata:
1596515979
react-native-gesture-handler: "npm:^2.28.0"
1596615980
react-native-paper: "npm:^5.14.5"
1596715981
react-native-safe-area-context: "npm:^5.6.1"
15968-
react-native-screens: "npm:^4.16.0"
15982+
react-native-screens: "npm:^4.18.0"
1596915983
react-native-test-app: "npm:^4.4.10"
1597015984
react-native-vector-icons: "npm:^10.2.0"
1597115985
languageName: unknown
@@ -16133,6 +16147,19 @@ __metadata:
1613316147
languageName: node
1613416148
linkType: hard
1613516149

16150+
"react-native-screens@npm:^4.18.0":
16151+
version: 4.18.0
16152+
resolution: "react-native-screens@npm:4.18.0"
16153+
dependencies:
16154+
react-freeze: "npm:^1.0.0"
16155+
warn-once: "npm:^0.1.0"
16156+
peerDependencies:
16157+
react: "*"
16158+
react-native: "*"
16159+
checksum: 10/456c18069ab8fee1d6c341d6bd13cba477fcda10f266844fb5f486ad5ac2c7336a5181956e261be010318be53585d4a72fd9bd00289117bbbdea681309de21f4
16160+
languageName: node
16161+
linkType: hard
16162+
1613616163
"react-native-test-app@npm:^4.4.10":
1613716164
version: 4.4.10
1613816165
resolution: "react-native-test-app@npm:4.4.10"
@@ -17764,7 +17791,7 @@ __metadata:
1776417791
languageName: node
1776517792
linkType: hard
1776617793

17767-
"stacktrace-parser@npm:^0.1.10":
17794+
"stacktrace-parser@npm:^0.1.10, stacktrace-parser@npm:^0.1.11":
1776817795
version: 0.1.11
1776917796
resolution: "stacktrace-parser@npm:0.1.11"
1777017797
dependencies:

0 commit comments

Comments
 (0)