Skip to content

Commit

Permalink
Merge pull request #42167 from ikevin127/revert/35011
Browse files Browse the repository at this point in the history
Revert: [NewFeature] Automatic scrolling to the top of report's new unread message marker
  • Loading branch information
Beamanator authored May 14, 2024
2 parents 27a1e83 + e213cf8 commit 321886a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 38 deletions.
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 @@ -510,31 +510,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

0 comments on commit 321886a

Please sign in to comment.