-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix scrolling to bottom list on MoneyRequestReportView #59664
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
Merged
mountiny
merged 13 commits into
Expensify:main
from
software-mansion-labs:kicu/58808-money-request-report-scroll
Apr 16, 2025
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
319e605
Fix scrolling to bottom list on MoneyRequestReportView
Kicu d2dc97c
Fix displaying unread marker correctly
Kicu 6607831
Disable LoadingBar on SearchMoneyRequestReportPage
Kicu 814f32c
Merge branch 'main' into kicu/58808-money-request-report-scroll
Kicu acf0d2f
Fix conflicts after merge
Kicu fd5eaf2
Fix displaying unread floating button on MoneyRequestReportActionsList
Kicu 2f936ae
Merge branch 'main' into kicu/58808-money-request-report-scroll
Kicu f430b29
Merge branch 'main' into kicu/58808-money-request-report-scroll
Kicu be2f6a7
Fix TopBar after changes from main
Kicu bc7345e
Improve shouldDisplayNewMarkerOnReportAction a bit
Kicu 998cbc1
Merge branch 'main' into kicu/58808-money-request-report-scroll
Kicu 89df2e9
Improve code comments around MoneyRequestReportActionsList
Kicu 088f516
Fix comment typo
Kicu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
225 changes: 139 additions & 86 deletions
225
src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/pages/home/report/shouldDisplayNewMarkerOnReportAction.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import {isReportActionUnread, isReportPreviewAction, shouldHideNewMarker} from '@libs/ReportActionsUtils'; | ||
import CONST from '@src/CONST'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
|
||
type ShouldDisplayNewMarkerOnReportActionParams = { | ||
/** The reportAction for which the check is done */ | ||
message: OnyxTypes.ReportAction; | ||
|
||
/** The reportAction adjacent to `message` (either previous or next one) */ | ||
nextMessage: OnyxTypes.ReportAction | undefined; | ||
|
||
/** Is it the earliestReceivedOfflineMessage */ | ||
isEarliestReceivedOfflineMessage: boolean; | ||
|
||
/** Time for unreadMarker */ | ||
unreadMarkerTime: string | undefined; | ||
|
||
/** User accountID */ | ||
accountID: number | undefined; | ||
|
||
/** Map of reportActions saved via usePrev */ | ||
prevSortedVisibleReportActionsObjects: Record<string, OnyxTypes.ReportAction>; | ||
|
||
/** Current value for vertical offset */ | ||
scrollingVerticalOffset: number; | ||
|
||
/** The id of reportAction that was last marked as read */ | ||
prevUnreadMarkerReportActionID: string | null; | ||
}; | ||
|
||
/** | ||
* This function decides whether the given report action (message) should have the new marker indicator displayed | ||
* It's used for the standard "chat" Report and for `MoneyRequestReport` actions lists. | ||
*/ | ||
const shouldDisplayNewMarkerOnReportAction = ({ | ||
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. this function was extracted from |
||
message, | ||
nextMessage, | ||
isEarliestReceivedOfflineMessage, | ||
unreadMarkerTime, | ||
accountID, | ||
prevSortedVisibleReportActionsObjects, | ||
prevUnreadMarkerReportActionID, | ||
scrollingVerticalOffset, | ||
}: ShouldDisplayNewMarkerOnReportActionParams): boolean => { | ||
const isNextMessageUnread = !!nextMessage && isReportActionUnread(nextMessage, unreadMarkerTime); | ||
|
||
// If the current message is the earliest message received while offline, we want to display the unread marker above this message. | ||
if (isEarliestReceivedOfflineMessage && !isNextMessageUnread) { | ||
return true; | ||
} | ||
|
||
// If the unread marker should be hidden or is not within the visible area, don't show the unread marker. | ||
if (shouldHideNewMarker(message)) { | ||
return false; | ||
} | ||
|
||
const isCurrentMessageUnread = isReportActionUnread(message, unreadMarkerTime); | ||
|
||
// If the current message is read or the next message is unread, don't show the unread marker. | ||
if (!isCurrentMessageUnread || isNextMessageUnread) { | ||
return false; | ||
} | ||
|
||
const isPendingAdd = (action: OnyxTypes.ReportAction) => { | ||
return action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD; | ||
}; | ||
|
||
// If no unread marker exists, don't set an unread marker for newly added messages from the current user. | ||
const isFromCurrentUser = accountID === (isReportPreviewAction(message) ? message.childLastActorAccountID : message.actorAccountID); | ||
const isNewMessage = !prevSortedVisibleReportActionsObjects[message.reportActionID]; | ||
|
||
// The unread marker will show if the action's `created` time is later than `unreadMarkerTime`. | ||
// The `unreadMarkerTime` has already been updated to match the optimistic action created time, | ||
// but once the new action is saved on the backend, the actual created time will be later than the optimistic one. | ||
// Therefore, we also need to prevent the unread marker from appearing for previously optimistic actions. | ||
const isPreviouslyOptimistic = | ||
(isPendingAdd(prevSortedVisibleReportActionsObjects[message.reportActionID]) && !isPendingAdd(message)) || | ||
(!!prevSortedVisibleReportActionsObjects[message.reportActionID]?.isOptimisticAction && !message.isOptimisticAction); | ||
const shouldIgnoreUnreadForCurrentUserMessage = !prevUnreadMarkerReportActionID && isFromCurrentUser && (isNewMessage || isPreviouslyOptimistic); | ||
|
||
if (isFromCurrentUser) { | ||
return !shouldIgnoreUnreadForCurrentUserMessage; | ||
} | ||
|
||
return !isNewMessage || scrollingVerticalOffset >= CONST.REPORT.ACTIONS.ACTION_VISIBLE_THRESHOLD; | ||
}; | ||
|
||
export default shouldDisplayNewMarkerOnReportAction; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
noticed this was unused