mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 22:39:41 +08:00
Fix drawer stack reset-to-top behavior (#4132)
“reset” is not a NavigationAction anymore. The correct fix, for v3, to this is to navigate to the first screen inside the stack. With the less-pushy navigate behavior in v2, this will result in the first route getting selected if you specify it by routeName.
This commit is contained in:
committed by
Brent Vatne
parent
ad7cde9eb9
commit
c1a94895f5
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import { StyleSheet, View } from 'react-native';
|
||||
|
||||
import NavigationActions from '../../NavigationActions';
|
||||
import StackActions from '../../routers/StackActions';
|
||||
import invariant from '../../utils/invariant';
|
||||
|
||||
/**
|
||||
@@ -46,9 +47,10 @@ class DrawerSidebar extends React.PureComponent {
|
||||
_onItemPress = ({ route, focused }) => {
|
||||
if (!focused) {
|
||||
let subAction;
|
||||
// TODO (v3): Revisit and repeal this behavior:
|
||||
// if the child screen is a StackRouter then always navigate to its first screen (see #1914)
|
||||
if (route.index !== undefined && route.index !== 0) {
|
||||
subAction = NavigationActions.reset({
|
||||
if (route.index != null && route.index !== 0) {
|
||||
subAction = StackActions.reset({
|
||||
index: 0,
|
||||
actions: [
|
||||
NavigationActions.navigate({
|
||||
|
||||
Reference in New Issue
Block a user