diff --git a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx index 5dc1c1832d39..13c7ad92ec49 100644 --- a/src/pages/settings/Profile/CustomStatus/StatusPage.tsx +++ b/src/pages/settings/Profile/CustomStatus/StatusPage.tsx @@ -74,6 +74,26 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) return DateUtils.isTimeAtLeastOneMinuteInFuture({dateTimeString: clearAfterTime}); }, [draftClearAfter, currentUserClearAfter]); + const navigateBackToPreviousScreenTask = useRef<{ + then: ( + onfulfilled?: () => typeof InteractionManager.runAfterInteractions, + onrejected?: () => typeof InteractionManager.runAfterInteractions, + ) => Promise; + done: (...args: Array) => typeof InteractionManager.runAfterInteractions; + cancel: () => void; + } | null>(null); + + useEffect( + () => () => { + if (!navigateBackToPreviousScreenTask.current) { + return; + } + + navigateBackToPreviousScreenTask.current.cancel(); + }, + [], + ); + const navigateBackToPreviousScreen = useCallback(() => Navigation.goBack(), []); const updateStatus = useCallback( ({emojiCode, statusText}: FormOnyxValues) => { @@ -90,7 +110,7 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) clearAfter: clearAfterTime !== CONST.CUSTOM_STATUS_TYPES.NEVER ? clearAfterTime : '', }); User.clearDraftCustomStatus(); - InteractionManager.runAfterInteractions(() => { + navigateBackToPreviousScreenTask.current = InteractionManager.runAfterInteractions(() => { navigateBackToPreviousScreen(); }); }, @@ -106,7 +126,7 @@ function StatusPage({draftStatus, currentUserPersonalDetails}: StatusPageProps) }); formRef.current?.resetForm({[INPUT_IDS.EMOJI_CODE]: ''}); - InteractionManager.runAfterInteractions(() => { + navigateBackToPreviousScreenTask.current = InteractionManager.runAfterInteractions(() => { navigateBackToPreviousScreen(); }); };