This repository was archived by the owner on Nov 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathListsProfiler.tsx
More file actions
67 lines (62 loc) · 1.88 KB
/
ListsProfiler.tsx
File metadata and controls
67 lines (62 loc) · 1.88 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, {useCallback} from 'react';
import {Flipper, addPlugin} from 'react-native-flipper';
import {ListsProfilerContextProvider} from './ListsProfilerContext';
import ListsProfilerProps from './ListsProfilerProps';
const bootstrapPlugin = (): Promise<Flipper.FlipperConnection> => {
return new Promise(resolve => {
addPlugin({
getId: () => 'shopify-react-native-performance',
onConnect: connection => {
return resolve(connection);
},
onDisconnect: () => {},
runInBackground: () => true,
});
});
};
/**
* Wrap your app with this component to get events from all the lists wrapped with their performance view.
* For example, `FlatList` must be wrapped in the `FlatListPerformanceView`.
*/
const ListsProfiler = ({onInteractive = () => {}, onBlankArea = () => {}, children}: ListsProfilerProps) => {
let connection: Flipper.FlipperConnection | undefined;
bootstrapPlugin()
.then(conn => {
connection = conn;
})
.catch(error => {
throw error;
});
const onInteractiveCallback = useCallback(
(TTI: number, listName: string) => {
onInteractive(TTI, listName);
connection?.send('newListTTIData', {
TTI,
listName,
});
},
[connection, onInteractive],
);
const onBlankAreaCallback = useCallback(
(offsetStart: number, offsetEnd: number, listName: string) => {
onBlankArea(offsetStart, offsetEnd, listName);
const blankArea = Math.max(Math.max(offsetStart, offsetEnd), 0);
connection?.send('newBlankData', {
offset: blankArea,
listName,
});
},
[connection, onBlankArea],
);
return (
<ListsProfilerContextProvider
value={{
onInteractive: onInteractiveCallback,
onBlankArea: onBlankAreaCallback,
}}
>
{children}
</ListsProfilerContextProvider>
);
};
export default ListsProfiler;