React Navigation(version 4.x): 跳转到同屏
React Navigation(version 4.x): Transition to the same screen
我正在使用 createStackNavigator
。我有三个屏幕:A、B 和 C
屏幕 B 在我的转换过程中使用了两次。我使用这个符号:
B(1)
: 第一次跳转到B屏有一些参数
B(2)
:我们第二次使用不同参数
转换到屏幕B
考虑这个转变:
A --> B(1) --> C --> B(2)
当前行为:
当我从屏幕 A
过渡到 B(1)
、B(1)
过渡到 C
时,每次新屏幕出现时都会从 右侧显示动画向左。但是当我从 C
过渡到 B(2)
时,新屏幕从 左到右 出现。 (第 1 期)
当我在 B(2)
并使用 navigation.goBack()
时,我看到 A
(但我当然想看到 C
)
(第 2 期)
预期行为:
当我从 C
过渡到 B(2)
时,新屏幕必须从 从右到左出现 (与之前的过渡一样)
当我在 B(2)
并使用 navigation.goBack()
时,我必须看到 C
System:
OS: macOS 10.15.3
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 246.99 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 28, 29
Build Tools: 28.0.3, 29.0.2
System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz => 0.61.4
"react-navigation": "^4.3.7",
"react-navigation-stack": "^1.10.3",
要修复屏幕 C 中的 "when I transit from C to B(2), the new screen must appear from right to left (Like previous transitions)",请使用此代码进行导航:
// this pushes B into the stack insted of navigating to B
() => navigation.push('B')
这个 "When I am on B(2) and use navigation.goBack(), I must see C" 将已经修复,因为堆栈顺序使用 push insted 导航是正确的。
所以你的堆栈预览屏幕将是 C.
我正在使用 createStackNavigator
。我有三个屏幕:A、B 和 C
屏幕 B 在我的转换过程中使用了两次。我使用这个符号:
B(1)
: 第一次跳转到B屏有一些参数
B(2)
:我们第二次使用不同参数
考虑这个转变:
A --> B(1) --> C --> B(2)
当前行为:
当我从屏幕 A
过渡到 B(1)
、B(1)
过渡到 C
时,每次新屏幕出现时都会从 右侧显示动画向左。但是当我从 C
过渡到 B(2)
时,新屏幕从 左到右 出现。 (第 1 期)
当我在 B(2)
并使用 navigation.goBack()
时,我看到 A
(但我当然想看到 C
)
(第 2 期)
预期行为:
当我从 C
过渡到 B(2)
时,新屏幕必须从 从右到左出现 (与之前的过渡一样)
当我在 B(2)
并使用 navigation.goBack()
时,我必须看到 C
System:
OS: macOS 10.15.3
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 246.99 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 28, 29
Build Tools: 28.0.3, 29.0.2
System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz => 0.61.4
"react-navigation": "^4.3.7",
"react-navigation-stack": "^1.10.3",
要修复屏幕 C 中的 "when I transit from C to B(2), the new screen must appear from right to left (Like previous transitions)",请使用此代码进行导航:
// this pushes B into the stack insted of navigating to B
() => navigation.push('B')
这个 "When I am on B(2) and use navigation.goBack(), I must see C" 将已经修复,因为堆栈顺序使用 push insted 导航是正确的。 所以你的堆栈预览屏幕将是 C.