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:
Eric Vicenti
2018-05-06 09:51:18 -07:00
committed by Brent Vatne
parent ad7cde9eb9
commit c1a94895f5

View File

@@ -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({