Skip to content

Commit

Permalink
Merge pull request #43085 from c3024/prevent-auto-scroll-on-android
Browse files Browse the repository at this point in the history
prevent autoscroll to bottom on android when last track expense whisper is unresolved
  • Loading branch information
rlinoz authored Jun 7, 2024
2 parents 97ead64 + d7a7f35 commit a4e20bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
17 changes: 10 additions & 7 deletions src/hooks/useReportScrollManager/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ function useReportScrollManager(): ReportScrollManagerData {
/**
* Scroll to the provided index.
*/
const scrollToIndex = (index: number) => {
if (!flatListRef?.current) {
return;
}

flatListRef.current.scrollToIndex({index});
};
const scrollToIndex = useCallback(
(index: number) => {
if (!flatListRef?.current) {
return;
}

flatListRef.current.scrollToIndex({index});
},
[flatListRef],
);

/**
* Scroll to the bottom of the flatlist.
Expand Down
15 changes: 9 additions & 6 deletions src/hooks/useReportScrollManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ function useReportScrollManager(): ReportScrollManagerData {
/**
* 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) => {
if (!flatListRef?.current || isEditing) {
return;
}
const scrollToIndex = useCallback(
(index: number, isEditing?: boolean) => {
if (!flatListRef?.current || isEditing) {
return;
}

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

/**
* Scroll to the bottom of the flatlist.
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ function ReportActionItem({
return;
}

if (prevActionResolution !== (action.originalMessage.resolution ?? null)) {
if (prevActionResolution !== action.originalMessage.resolution) {
reportScrollManager.scrollToIndex(index);
}
}, [index, action, prevActionResolution, reportScrollManager, isActionableWhisper]);
Expand Down

0 comments on commit a4e20bf

Please sign in to comment.