-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
index.ts
34 lines (27 loc) · 1.03 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {useCallback, useContext} from 'react';
import {ActionListContext} from '@pages/home/ReportScreenContext';
import ReportScrollManagerData from './types';
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.
*/
const scrollToIndex = (index: number, isEditing?: boolean) => {
if (!flatListRef?.current || isEditing) {
return;
}
flatListRef.current.scrollToIndex({index, animated: true});
};
/**
* Scroll to the bottom of the flatlist.
*/
const scrollToBottom = useCallback(() => {
if (!flatListRef?.current) {
return;
}
flatListRef.current.scrollToOffset({animated: false, offset: 0});
}, [flatListRef]);
return {ref: flatListRef, scrollToIndex, scrollToBottom};
}
export default useReportScrollManager;