Commit 46a7892
authored
Optimise
## Description
- Memoize all Gestures, and non-memoized functions.
- Reduce number of used shared values
- Fix unoptimal dependency lists on existing `useMemo`s
## Test plan
- use `android`, `iOS` has no performance issues
- use attached code to measure performance
- tested on physical `Samsung S24 Ultra`
- pre-optimization average: `19 fps`
- post-optimization average: `68 fps`
## Test code
Tested on `@shopify/flash-list` using their `useBenchmark` utility hook.
<details>
<summary>
Collapsed code
</summary>
```js
import { Text, StyleSheet, View, Alert } from 'react-native';
import ReanimatedSwipeable from 'react-native-gesture-handler/ReanimatedSwipeable';
import { FlashList, ListRenderItem, useBenchmark } from '@shopify/flash-list';
import { memo, useRef } from 'react';
function RightAction() {
return <Text style={styles.rightAction}>Text</Text>;
}
type Item = {
id: string;
title: string;
};
const generateItems = (count: number): Item[] => {
return Array.from({ length: count }, () => {
const randomNumber = Math.random().toString(36).substring(2, 8);
return {
id: randomNumber,
title: `Title ${randomNumber}`,
};
});
};
const data = generateItems(200);
const _RenderItemView = (item: Item) => (
<View style={styles.swipeable}>
<Text>{item.title}</Text>
</View>
);
const RenderItemViewMemoed = memo(_RenderItemView);
export default function Example() {
const renderItem: ListRenderItem<Item> = ({ item }) => {
return (
<ReanimatedSwipeable renderRightActions={RightAction}>
<RenderItemViewMemoed {...item} />
</ReanimatedSwipeable>
);
};
const flashListRef = useRef<FlashList<Item> | null>(null);
useBenchmark(flashListRef, (callback) => {
Alert.alert('result', callback.formattedString);
});
return (
<FlashList
ref={flashListRef}
data={data}
renderItem={renderItem}
estimatedItemSize={50}
keyExtractor={(item) => item.id}
/>
);
}
const styles = StyleSheet.create({
leftAction: { width: 50, height: 50, backgroundColor: 'crimson' },
rightAction: { width: 50, height: 50, backgroundColor: 'purple' },
separator: {
width: '100%',
borderTopWidth: 1,
},
swipeable: {
height: 50,
backgroundColor: 'papayawhip',
alignItems: 'center',
},
});
```
</details>ReanimatedSwipeable component (#3165)1 parent ef686fc commit 46a7892
File tree
4 files changed
+665
-279
lines changed- example
- src/release_tests/swipeableReanimation
- src/components
4 files changed
+665
-279
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
95 | 101 | | |
96 | 102 | | |
97 | 103 | | |
98 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
99 | 145 | | |
| 146 | + | |
100 | 147 | | |
101 | 148 | | |
102 | 149 | | |
| |||
110 | 157 | | |
111 | 158 | | |
112 | 159 | | |
| 160 | + | |
113 | 161 | | |
114 | 162 | | |
115 | 163 | | |
| |||
137 | 185 | | |
138 | 186 | | |
139 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
140 | 204 | | |
0 commit comments