mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-05-06 06:35:57 -04:00
Reset stack when user navigates from AddObsModal (#1858)
* Reset navigation stack when user navigates from AddObsModal; closes #1857 * Fix AddObs nav test
This commit is contained in:
committed by
GitHub
parent
b6ea37e7e2
commit
b61ff38f7c
@@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import { CommonActions, useNavigation } from "@react-navigation/native";
|
||||
import AddObsModal from "components/AddObsModal";
|
||||
import { Modal } from "components/SharedComponents";
|
||||
import GradientButton from "components/SharedComponents/Buttons/GradientButton.tsx";
|
||||
@@ -30,11 +30,29 @@ const AddObsButton = (): React.Node => {
|
||||
if ( screen !== "ObsEdit" ) {
|
||||
resetObservationFlowSlice( );
|
||||
}
|
||||
// access nested screen
|
||||
navigation.navigate( "NoBottomTabStackNavigator", {
|
||||
screen,
|
||||
params: { ...params, previousScreen: currentRoute }
|
||||
} );
|
||||
|
||||
// we need to reset the navigation stack whenever a user navigates from the AddObs wheel,
|
||||
// otherwise the user can end up closing out to a previous place in the stack, #1857
|
||||
navigation.dispatch(
|
||||
CommonActions.reset( {
|
||||
index: 0,
|
||||
routes: [
|
||||
{
|
||||
name: "NoBottomTabStackNavigator",
|
||||
state: {
|
||||
index: 0,
|
||||
routes: [
|
||||
{
|
||||
name: screen,
|
||||
params: { ...params, previousScreen: currentRoute }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
} )
|
||||
);
|
||||
|
||||
closeModal( );
|
||||
};
|
||||
const navToARCamera = ( ) => { navAndCloseModal( "Camera", { camera: "AI" } ); };
|
||||
|
||||
@@ -7,17 +7,34 @@ import { renderComponent } from "tests/helpers/render";
|
||||
|
||||
const actor = userEvent.setup();
|
||||
|
||||
const mockNavigate = jest.fn();
|
||||
const mockDispatch = jest.fn();
|
||||
jest.mock( "@react-navigation/native", () => {
|
||||
const actualNav = jest.requireActual( "@react-navigation/native" );
|
||||
return {
|
||||
...actualNav,
|
||||
useNavigation: () => ( {
|
||||
navigate: mockNavigate
|
||||
dispatch: mockDispatch
|
||||
} )
|
||||
};
|
||||
} );
|
||||
|
||||
const resetNavigation = ( name, params ) => ( {
|
||||
payload: {
|
||||
index: 0,
|
||||
routes: [{
|
||||
name: "NoBottomTabStackNavigator",
|
||||
state: {
|
||||
index: 0,
|
||||
routes: [{
|
||||
name,
|
||||
params
|
||||
}]
|
||||
}
|
||||
}]
|
||||
},
|
||||
type: "RESET"
|
||||
} );
|
||||
|
||||
beforeAll( ( ) => {
|
||||
jest.useFakeTimers( );
|
||||
} );
|
||||
@@ -32,10 +49,9 @@ describe( "AddObsButton", ( ) => {
|
||||
expect( addObsButton ).toBeTruthy( );
|
||||
await actor.press( addObsButton );
|
||||
|
||||
expect( mockNavigate ).toHaveBeenCalledWith( "NoBottomTabStackNavigator", {
|
||||
screen: "Camera",
|
||||
params: { camera: "AI", previousScreen: null }
|
||||
} );
|
||||
expect( mockDispatch ).toHaveBeenCalledWith(
|
||||
resetNavigation( "Camera", { camera: "AI", previousScreen: null } )
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
||||
@@ -74,9 +90,8 @@ describe( "with advanced user layout", ( ) => {
|
||||
expect( noEvidenceButton ).toBeTruthy( );
|
||||
await actor.press( noEvidenceButton );
|
||||
|
||||
expect( mockNavigate ).toHaveBeenCalledWith( "NoBottomTabStackNavigator", {
|
||||
screen: "ObsEdit",
|
||||
params: { previousScreen: null }
|
||||
} );
|
||||
expect( mockDispatch ).toHaveBeenCalledWith(
|
||||
resetNavigation( "ObsEdit", { previousScreen: null } )
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
||||
Reference in New Issue
Block a user