mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2025-12-23 22:18:36 -05:00
Reset navigator when navigating to ObsEdit from TabStack (#1897)
* Reset navigator when navigating to ObsEdit from TabStack; closes #1890 * Code cleanup
This commit is contained in:
committed by
GitHub
parent
a781dca7c0
commit
fc4b3caba9
@@ -1,5 +1,6 @@
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import classnames from "classnames";
|
||||
import navigateToObsEdit from "components/ObsEdit/helpers/navigateToObsEdit.ts";
|
||||
import {
|
||||
BackButton,
|
||||
INatIconButton
|
||||
@@ -63,9 +64,7 @@ const ObsDetailsHeader = ( {
|
||||
testID="ObsDetail.editButton"
|
||||
onPress={() => {
|
||||
prepareObsEdit( localObservation );
|
||||
navigation.navigate( "NoBottomTabStackNavigator", {
|
||||
screen: "ObsEdit"
|
||||
} );
|
||||
navigateToObsEdit( navigation );
|
||||
}}
|
||||
icon="pencil"
|
||||
color={!rightIconBlack
|
||||
|
||||
@@ -82,9 +82,7 @@ const Header = ( {
|
||||
|| ( unsynced && !unsavedChanges );
|
||||
|
||||
const handleBackButtonPress = useCallback( ( ) => {
|
||||
if ( params?.lastScreen === "ObsList" ) {
|
||||
navToObsList( );
|
||||
} else if ( params?.lastScreen === "Suggestions" ) {
|
||||
if ( params?.lastScreen === "Suggestions" ) {
|
||||
navigation.navigate( "Suggestions", { lastScreen: "ObsEdit" } );
|
||||
} else if ( shouldNavigateBack ) {
|
||||
navigation.goBack( );
|
||||
@@ -97,7 +95,6 @@ const Header = ( {
|
||||
}
|
||||
}, [
|
||||
currentObservation?.uuid,
|
||||
navToObsList,
|
||||
shouldNavigateBack,
|
||||
navigation,
|
||||
params?.lastScreen,
|
||||
|
||||
28
src/components/ObsEdit/helpers/navigateToObsEdit.ts
Normal file
28
src/components/ObsEdit/helpers/navigateToObsEdit.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { CommonActions } from "@react-navigation/native";
|
||||
|
||||
const navigateToObsEdit = navigation => {
|
||||
// since we can access ObsEdit from two separate stacks, the TabStackNavigator
|
||||
// and the NoBottomTabStackNavigator, we don't want ObsEdit to land on the previous
|
||||
// history of the NoBottomTabStackNavigator (i.e. anything from the ObsCreate flow)
|
||||
// when we're navigating via the TabStack (i.e. MyObservations, ObsDetails)
|
||||
navigation.dispatch(
|
||||
CommonActions.reset( {
|
||||
index: 0,
|
||||
routes: [
|
||||
{
|
||||
name: "NoBottomTabStackNavigator",
|
||||
state: {
|
||||
index: 0,
|
||||
routes: [
|
||||
{
|
||||
name: "ObsEdit"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
} )
|
||||
);
|
||||
};
|
||||
|
||||
export default navigateToObsEdit;
|
||||
@@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import navigateToObsEdit from "components/ObsEdit/helpers/navigateToObsEdit.ts";
|
||||
import type { Node } from "react";
|
||||
import React from "react";
|
||||
import { Pressable } from "react-native";
|
||||
@@ -25,12 +26,7 @@ const MyObservationsPressable = ( { observation, testID, children }: Props ): No
|
||||
const { uuid } = observation;
|
||||
if ( unsynced ) {
|
||||
prepareObsEdit( observation );
|
||||
navigation.navigate( "NoBottomTabStackNavigator", {
|
||||
screen: "ObsEdit",
|
||||
params: {
|
||||
lastScreen: "ObsList"
|
||||
}
|
||||
} );
|
||||
navigateToObsEdit( navigation );
|
||||
} else {
|
||||
navigation.push( "ObsDetails", { uuid } );
|
||||
}
|
||||
|
||||
@@ -148,8 +148,7 @@ const createObservationFlowSlice = ( set, get ) => ( {
|
||||
updateComment: newComment => set( { comment: newComment } ),
|
||||
updateObservations: updatedObservations => set( state => ( {
|
||||
observations: updatedObservations.map( observationToJSON ),
|
||||
currentObservation: observationToJSON( updatedObservations[state.currentObservationIndex] ),
|
||||
unsavedChanges: true
|
||||
currentObservation: observationToJSON( updatedObservations[state.currentObservationIndex] )
|
||||
} ) ),
|
||||
updateObservationKeys: keysAndValues => set( state => ( {
|
||||
observations: updateObservationKeysWithState( keysAndValues, state ),
|
||||
|
||||
Reference in New Issue
Block a user