Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit 8cf63b2

Browse files
committed
fix: use the JUMP_TO action for tab change
The index change event fires after swipe animation. If you quickly navigate to a new screen in stack before animation finishes, the index change event will fire after the previous navigation event. By this time, the tab navigator is not focused anymore. Using the JUMP_TO action instead of NAVIGATE avoids this issue.
1 parent e4b976d commit 8cf63b2

File tree

5 files changed

+44
-42
lines changed

5 files changed

+44
-42
lines changed

example/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"main": "App.js",
1111
"dependencies": {
1212
"@expo/vector-icons": "^10.0.1",
13-
"@react-navigation/core": "^3.2.0",
13+
"@react-navigation/core": "^3.4.0",
1414
"@react-navigation/native": "^3.3.0",
1515
"expo": "32.0.6",
1616
"react": "16.5.0",
@@ -27,6 +27,7 @@
2727
},
2828
"resolutions": {
2929
"**/@expo/vector-icons": "10.0.1",
30+
"**/@react-navigation/core": "3.4.0",
3031
"**/hoist-non-react-statics": "2.5.0",
3132
"**/react-native-tab-view": "2.0.3"
3233
}

example/yarn.lock

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,16 +1060,15 @@
10601060
pouchdb-collections "^1.0.1"
10611061
tiny-queue "^0.2.1"
10621062

1063-
"@react-navigation/[email protected]", "@react-navigation/core@^3.2.0":
1064-
version "3.2.0"
1065-
resolved "https://registry.yarnpkg.com/@react-navigation/core/-/core-3.2.0.tgz#329dfe54f305ee22ed750d51cb09c5d18562d56f"
1066-
integrity sha512-MXjTqqPFbifXGlws4hSye9Ax4dEM2OvV7VMEJOJU9TbzQjyewi59Cjplbt8pYQ5ummvkKeRS2FlQYIygNR5oCQ==
1063+
"@react-navigation/[email protected]", "@react-navigation/core@3.4.0", "@react-navigation/core@^3.4.0":
1064+
version "3.4.0"
1065+
resolved "https://registry.yarnpkg.com/@react-navigation/core/-/core-3.4.0.tgz#776845f9d4f8b2b9cb99c5d2d4433ebcef290d92"
1066+
integrity sha512-YAnx9mK6P/zYkvn4YxZL6thaNdouSmD7FUaftFrOAbE7y7cCfH8hmk7BOLoOet6Sh2+UnrpkWX7Kg54cT2Jw+g==
10671067
dependencies:
1068-
create-react-context "0.2.2"
1069-
hoist-non-react-statics "^2.5.5"
1068+
hoist-non-react-statics "^3.3.0"
10701069
path-to-regexp "^1.7.0"
1071-
query-string "^6.2.0"
1072-
react-is "^16.6.3"
1070+
query-string "^6.4.2"
1071+
react-is "^16.8.6"
10731072

10741073
"@react-navigation/native@^3.3.0", "@react-navigation/native@~3.3.0":
10751074
version "3.3.0"
@@ -2294,14 +2293,6 @@ create-react-class@^15.6.3:
22942293
loose-envify "^1.3.1"
22952294
object-assign "^4.1.1"
22962295

2297-
2298-
version "0.2.2"
2299-
resolved "https://registry.yarnpkg.com/create-react-context/-/create-react-context-0.2.2.tgz#9836542f9aaa22868cd7d4a6f82667df38019dca"
2300-
integrity sha512-KkpaLARMhsTsgp0d2NA/R94F/eDLbhXERdIq3LvX2biCAXcDvHYoOqHfWCHf1+OLj+HKBotLG3KqaOOf+C1C+A==
2301-
dependencies:
2302-
fbjs "^0.8.0"
2303-
gud "^1.0.0"
2304-
23052296
cross-spawn@^5.0.1, cross-spawn@^5.1.0:
23062297
version "5.1.0"
23072298
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
@@ -3034,7 +3025,7 @@ fbjs-scripts@^0.8.1:
30343025
semver "^5.1.0"
30353026
through2 "^2.0.0"
30363027

3037-
[email protected], fbjs@^0.8.0, fbjs@^0.8.4, fbjs@^0.8.9:
3028+
[email protected], fbjs@^0.8.4, fbjs@^0.8.9:
30383029
version "0.8.17"
30393030
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd"
30403031
integrity sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90=
@@ -3270,11 +3261,6 @@ growly@^1.3.0:
32703261
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
32713262
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=
32723263

3273-
gud@^1.0.0:
3274-
version "1.0.0"
3275-
resolved "https://registry.yarnpkg.com/gud/-/gud-1.0.0.tgz#a489581b17e6a70beca9abe3ae57de7a499852c0"
3276-
integrity sha512-zGEOVKFM5sVPPrYs7J5/hYEw2Pof8KCyOwyhG8sAF26mCAeUFAcYPu1mwB7hhpIP29zOIBaDqwuHdLp0jvZXjw==
3277-
32783264
has-ansi@^2.0.0:
32793265
version "2.0.0"
32803266
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
@@ -3323,7 +3309,7 @@ has-values@^1.0.0:
33233309
is-number "^3.0.0"
33243310
kind-of "^4.0.0"
33253311

3326-
[email protected], hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0, hoist-non-react-statics@^2.5.5, hoist-non-react-statics@^3.0.1:
3312+
[email protected], hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0, hoist-non-react-statics@^3.0.1, hoist-non-react-statics@^3.3.0:
33273313
version "2.5.0"
33283314
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz#d2ca2dfc19c5a91c5a6615ce8e564ef0347e2a40"
33293315
integrity sha512-6Bl6XsDT1ntE0lHbIhr4Kp2PGcleGZ66qu5Jqk8lc0Xc/IeG6gVLmwUGs/K0Us+L8VWoKgj0uWdPMataOsm31w==
@@ -4913,12 +4899,13 @@ qs@^6.5.0:
49134899
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
49144900
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
49154901

4916-
query-string@^6.2.0:
4917-
version "6.2.0"
4918-
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.2.0.tgz#468edeb542b7e0538f9f9b1aeb26f034f19c86e1"
4919-
integrity sha512-5wupExkIt8RYL4h/FE+WTg3JHk62e6fFPWtAZA9J5IWK1PfTfKkMS93HBUHcFpeYi9KsY5pFbh+ldvEyaz5MyA==
4902+
query-string@^6.4.2:
4903+
version "6.4.2"
4904+
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.4.2.tgz#8be1dbd105306aebf86022144f575a29d516b713"
4905+
integrity sha512-DfJqAen17LfLA3rQ+H5S4uXphrF+ANU1lT2ijds4V/Tj4gZxA3gx5/tg1bz7kYCmwna7LyJNCYqO7jNRzo3aLw==
49204906
dependencies:
49214907
decode-uri-component "^0.2.0"
4908+
split-on-first "^1.0.0"
49224909
strict-uri-encode "^2.0.0"
49234910

49244911
randomatic@^3.0.0:
@@ -4963,16 +4950,16 @@ [email protected]:
49634950
shell-quote "^1.6.1"
49644951
ws "^3.3.1"
49654952

4966-
react-is@^16.6.3:
4967-
version "16.8.6"
4968-
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
4969-
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
4970-
49714953
react-is@^16.8.1:
49724954
version "16.8.3"
49734955
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.3.tgz#4ad8b029c2a718fc0cfc746c8d4e1b7221e5387d"
49744956
integrity sha512-Y4rC1ZJmsxxkkPuMLwvKvlL1Zfpbcu+Bf4ZigkHup3v9EfdYhAlWAaVyA19olXq2o2mGn0w+dFKvk3pVVlYcIA==
49754957

4958+
react-is@^16.8.6:
4959+
version "16.8.6"
4960+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
4961+
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
4962+
49764963
react-lifecycles-compat@^3.0.4:
49774964
version "3.0.4"
49784965
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
@@ -5696,6 +5683,11 @@ spdx-license-ids@^3.0.0:
56965683
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.1.tgz#e2a303236cac54b04031fa7a5a79c7e701df852f"
56975684
integrity sha512-TfOfPcYGBB5sDuPn3deByxPhmfegAhpDYKSOXZQN81Oyrrif8ZCodOLzK3AesELnCx03kikhyDwh0pfvvQvF8w==
56985685

5686+
split-on-first@^1.0.0:
5687+
version "1.1.0"
5688+
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
5689+
integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==
5690+
56995691
split-string@^3.0.1, split-string@^3.0.2:
57005692
version "3.1.0"
57015693
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"dependencies": {
3939
"hoist-non-react-statics": "^3.3.0",
4040
"react-lifecycles-compat": "^3.0.4",
41-
"react-native-tab-view": "^2.0.3"
41+
"react-native-tab-view": "^2.2.0"
4242
},
4343
"devDependencies": {
4444
"@commitlint/config-conventional": "^7.5.0",
@@ -65,7 +65,7 @@
6565
"release-it": "^10.3.1"
6666
},
6767
"peerDependencies": {
68-
"@react-navigation/core": "^3.0.0",
68+
"@react-navigation/core": "^3.4.0",
6969
"@react-navigation/native": "^3.0.0",
7070
"react": "*",
7171
"react-native": "*",

src/utils/createTabNavigator.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
StackActions,
77
SceneView,
88
createNavigator,
9-
NavigationActions,
9+
SwitchActions,
1010
} from '@react-navigation/core';
1111

1212
export type InjectedProps = {|
@@ -160,8 +160,17 @@ export default function createTabNavigator(TabView: React.ComponentType<*>) {
160160
this.setState({ isSwiping: false });
161161
};
162162

163-
_jumpTo = routeName =>
164-
this.props.navigation.dispatch(NavigationActions.navigate({ routeName }));
163+
_jumpTo = routeName => {
164+
const { navigation } = this.props;
165+
166+
navigation.dispatch(
167+
SwitchActions.jumpTo({
168+
routeName,
169+
key: navigation.state.key,
170+
preserveFocus: true,
171+
})
172+
);
173+
};
165174

166175
_isTabPress: boolean = false;
167176

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7286,10 +7286,10 @@ react-native-tab-view@^1.0.0, react-native-tab-view@^1.2.0:
72867286
dependencies:
72877287
prop-types "^15.6.1"
72887288

7289-
react-native-tab-view@^2.0.3:
7290-
version "2.0.3"
7291-
resolved "https://registry.yarnpkg.com/react-native-tab-view/-/react-native-tab-view-2.0.3.tgz#0160e2d94e69c722fcefa8649ffe13fec9177a0d"
7292-
integrity sha512-/rv+ESxtLFIWucIlq5VhDcZsCxThovE5FWpYngTNxLQgWzI/lem48h6FiYIMU+R6/fXOHmzSIuJtuCxNX+62fw==
7289+
react-native-tab-view@^2.2.0:
7290+
version "2.2.0"
7291+
resolved "https://registry.yarnpkg.com/react-native-tab-view/-/react-native-tab-view-2.2.0.tgz#30d015b8f33f497d82419b56df7d43ecfcc3f9b1"
7292+
integrity sha512-mhFDRvPH/kmvqfAzTwNptbOM/xXmpqYRsD0PSMJX1nP0LzhU4uRI1QmSW6sWZGLyOwKgVw0ZYkwZ54N8AmoO1A==
72937293

72947294
react-native@~0.57.1:
72957295
version "0.57.8"

0 commit comments

Comments
 (0)