Call navigate directly in onPress handler (#3124)

And not over setting a state and navigating based on state on modal close.
This commit is contained in:
Johannes Klein
2025-10-08 23:02:34 +02:00
committed by GitHub
parent 52af36cd77
commit 3b5e298d36

View File

@@ -2,7 +2,7 @@ import { useNavigation } from "@react-navigation/native";
import type { ApiTaxon } from "api/types";
import ExploreTaxonSearch from "components/Explore/SearchScreens/ExploreTaxonSearch";
import Modal from "components/SharedComponents/Modal";
import React, { useState } from "react";
import React from "react";
import type { RealmTaxon } from "realmModels/types";
type Props = {
@@ -21,26 +21,18 @@ const ExploreTaxonSearchModal = ( {
updateTaxon
}: Props ) => {
const navigation = useNavigation( );
const [detailTaxonId, setDetailTaxonId] = useState<number | undefined | null>( null );
return (
<Modal
showModal={showModal}
fullScreen
closeModal={closeModal}
disableSwipeDirection
onModalHide={( ) => {
if ( detailTaxonId ) {
navigation.push( "TaxonDetails", { id: detailTaxonId } );
}
setDetailTaxonId( null );
}}
modal={(
<ExploreTaxonSearch
closeModal={closeModal}
hideInfoButton={hideInfoButton}
onPressInfo={( taxon: RealmTaxon | ApiTaxon ) => {
setDetailTaxonId( taxon.id );
navigation.push( "TaxonDetails", { id: taxon.id } );
closeModal();
if ( onPressInfo ) {
onPressInfo( );