Skip to content
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

[CP Staging] Revert: [NewFeature] Automatic scrolling to the top of report's new unread message marker #42167

Merged
merged 5 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/hooks/useReportScrollManager/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ function useReportScrollManager(): ReportScrollManagerData {

/**
* Scroll to the provided index.
* @param viewPosition (optional) - `0`: top, `0.5`: center, `1`: bottom
*/
// We're defaulting isEditing to false in order to match the
// number of arguments that index.ts version has.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const scrollToIndex = (index: number, isEditing = false, viewPosition?: number) => {
const scrollToIndex = (index: number) => {
if (!flatListRef?.current) {
return;
}

flatListRef.current.scrollToIndex({index, viewPosition});
flatListRef.current.scrollToIndex({index});
};

/**
Expand Down
9 changes: 3 additions & 6 deletions src/hooks/useReportScrollManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ function useReportScrollManager(): ReportScrollManagerData {
const {flatListRef} = useContext(ActionListContext);

/**
* Scroll to the provided index.
* On non-native implementations we do not want to scroll when we are scrolling because
* we are editing a comment.
* @param viewPosition (optional) - `0`: top, `0.5`: center, `1`: bottom
* Scroll to the provided index. On non-native implementations we do not want to scroll when we are scrolling because
*/
const scrollToIndex = (index: number, isEditing?: boolean, viewPosition?: number) => {
const scrollToIndex = (index: number, isEditing?: boolean) => {
if (!flatListRef?.current || isEditing) {
return;
}

flatListRef.current.scrollToIndex({index, animated: true, viewPosition});
flatListRef.current.scrollToIndex({index, animated: true});
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useReportScrollManager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {FlatListRefType} from '@pages/home/ReportScreenContext';

type ReportScrollManagerData = {
ref: FlatListRefType;
scrollToIndex: (index: number, isEditing?: boolean, viewPosition?: number) => void;
scrollToIndex: (index: number, isEditing?: boolean) => void;
scrollToBottom: () => void;
};

Expand Down
25 changes: 0 additions & 25 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,31 +507,6 @@ function ReportActionsList({
calculateUnreadMarker();
}, [calculateUnreadMarker, report.lastReadTime, messageManuallyMarkedUnread]);

useEffect(() => {
const scrollToFirstUnreadMessage = () => {
if (!currentUnreadMarker) {
return;
}

const unreadMessageIndex = sortedVisibleReportActions.findIndex((action) => action.reportActionID === currentUnreadMarker);

// Checking that we have a valid unread message index and the user scroll
// offset is less than the threshold since we don't want to auto-scroll when
// the report is already open and New Messages marker is shown as user might be reading.
if (unreadMessageIndex !== -1 && scrollingVerticalOffset.current < VERTICAL_OFFSET_THRESHOLD) {
// We're passing viewPosition: 1 to scroll to the top of the
// unread message (marker) since we're using an inverted FlatList.
reportScrollManager?.scrollToIndex(unreadMessageIndex, false, 1);
}
};

// Call the scroll function after a small delay to ensure all items
// have been measured and the list is ready to be scrolled.
InteractionManager.runAfterInteractions(scrollToFirstUnreadMessage);
// We only want to run this effect once, when we're navigating to a report with unread messages.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [sortedVisibleReportActions]);

useEffect(() => {
if (!userActiveSince.current || report.reportID !== prevReportID) {
return;
Expand Down
Loading