-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Navigation] Fix goBack in IOU steps #56876
Changes from all commits
7954cbb
cbce226
c5b6b49
fa07c33
ee22bd0
55d0a70
b0e37b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ import { | |
} from '@userActions/IOU'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {Route} from '@src/ROUTES'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type SCREENS from '@src/SCREENS'; | ||
import type {Participant} from '@src/types/onyx/IOU'; | ||
|
@@ -42,7 +41,7 @@ type IOURequestStepParticipantsProps = WithWritableReportOrNotFoundProps<typeof | |
|
||
function IOURequestStepParticipants({ | ||
route: { | ||
params: {iouType, reportID, transactionID, action}, | ||
params: {iouType, reportID, transactionID, action, backTo}, | ||
}, | ||
transaction, | ||
}: IOURequestStepParticipantsProps) { | ||
|
@@ -109,6 +108,19 @@ function IOURequestStepParticipants({ | |
resetDraftTransactionsCustomUnit(transactionID); | ||
}, [isFocused, isMovingTransactionFromTrackExpense, transactionID]); | ||
|
||
const waitForKeyboardDismiss = useCallback( | ||
(callback: () => void) => { | ||
if (isAndroidNative || isMobileSafari) { | ||
KeyboardUtils.dismiss().then(() => { | ||
callback(); | ||
}); | ||
} else { | ||
callback(); | ||
} | ||
}, | ||
[isAndroidNative, isMobileSafari], | ||
); | ||
|
||
const trackExpense = useCallback(() => { | ||
// If coming from the combined submit/track flow and the user proceeds to just track the expense, | ||
// we will use the track IOU type in the confirmation flow. | ||
|
@@ -120,8 +132,16 @@ function IOURequestStepParticipants({ | |
setCustomUnitRateID(transactionID, rateID); | ||
setMoneyRequestParticipantsFromReport(transactionID, selfDMReport); | ||
const iouConfirmationPageRoute = ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, CONST.IOU.TYPE.TRACK, transactionID, selfDMReportID); | ||
Navigation.navigate(iouConfirmationPageRoute); | ||
}, [action, selfDMReport, selfDMReportID, transactionID]); | ||
waitForKeyboardDismiss(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we type a participant from the keyboard and select it, we want to first close the keyboard and then navigate |
||
// If the backTo parameter is set, we should navigate back to the confirmation screen that is already on the stack. | ||
if (backTo) { | ||
// We don't want to compare params because we just changed the participants. | ||
Navigation.goBack(iouConfirmationPageRoute, {compareParams: false}); | ||
} else { | ||
Navigation.navigate(iouConfirmationPageRoute); | ||
} | ||
}); | ||
}, [action, backTo, selfDMReport, selfDMReportID, transactionID, waitForKeyboardDismiss]); | ||
|
||
const addParticipant = useCallback( | ||
(val: Participant[]) => { | ||
|
@@ -159,19 +179,6 @@ function IOURequestStepParticipants({ | |
[iouType, reportID, trackExpense, transactionID, isMovingTransactionFromTrackExpense], | ||
); | ||
|
||
const handleNavigation = useCallback( | ||
(route: Route) => { | ||
if (isAndroidNative || isMobileSafari) { | ||
KeyboardUtils.dismiss().then(() => { | ||
Navigation.navigate(route); | ||
}); | ||
} else { | ||
Navigation.navigate(route); | ||
} | ||
}, | ||
[isAndroidNative, isMobileSafari], | ||
); | ||
|
||
const goToNextStep = useCallback(() => { | ||
const isCategorizing = action === CONST.IOU.ACTION.CATEGORIZE; | ||
const isShareAction = action === CONST.IOU.ACTION.SHARE; | ||
|
@@ -202,12 +209,24 @@ function IOURequestStepParticipants({ | |
? ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(action, iouType, transactionID, selectedReportID.current || reportID, iouConfirmationPageRoute) | ||
: iouConfirmationPageRoute; | ||
|
||
handleNavigation(route); | ||
}, [action, participants, iouType, transaction, transactionID, reportID, handleNavigation]); | ||
waitForKeyboardDismiss(() => { | ||
// If the backTo parameter is set, we should navigate back to the confirmation screen that is already on the stack. | ||
if (backTo) { | ||
// We don't want to compare params because we just changed the participants. | ||
Navigation.goBack(route, {compareParams: false}); | ||
} else { | ||
Navigation.navigate(route); | ||
} | ||
}); | ||
}, [action, participants, iouType, transaction, transactionID, reportID, waitForKeyboardDismiss, backTo]); | ||
|
||
const navigateBack = useCallback(() => { | ||
if (backTo) { | ||
Navigation.goBack(backTo); | ||
return; | ||
} | ||
navigateToStartMoneyRequestStep(iouRequestType, iouType, transactionID, reportID, action); | ||
}, [iouRequestType, iouType, transactionID, reportID, action]); | ||
}, [backTo, iouRequestType, iouType, transactionID, reportID, action]); | ||
|
||
useEffect(() => { | ||
const isCategorizing = action === CONST.IOU.ACTION.CATEGORIZE; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By doing this way, we don't need to cast the result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I assume that as a result type we want to have array of objects that have a defined value of
CustomUnit