Slow FlatList render when list item contains Swipeable
Maintainer thường phản hồi trong vòng 2 ngày
@latekvo đang làm issue này rồi.
Từ ngày 21/1/2025.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Description
I'm seeing a significant slowdown in rendering when I add a Swipeable to the items in a FlatList.
This visually looks about 2x slower on my Androids (emulator, old device, newer device). iOS is less noticeable (iPhone 11) but from what I've profiled it looks like iOS is also slowing down.
By eye it looks like my screen takes ~2s to render on my newer device (~3s on the older device/emulator) with Swipeable present but ~0.5s (~1s on the older device/emulator) when I delete the Swipeable.
I've tried to create a Snack, but it seems to be using Expo 51 and I'm seeing this in Expo 52 with New Architecture. I've still given the link to the Snack below just in case this is helpful.
Steps to reproduce
I wanted to provide as useful an issue as I can in the hope this is helpful, so I've done my best to optimise and strip down my code (see below) and then profiled performance when the Swipeable component is present and, for comparison, when I delete it.
- Add swipeable to a list item in FlatList (I think other similar lists too)
- Render performance is significantly slower
- Remove Swipeable (everything else unchanged) and performance increases noticeably
I've optimised what I can in my code (memo and useCallback) and stripped it back in case it's something else I'm doing. I'm including the code below.
I then used the profiler to see where the slowdown is coming from. Swipeable seems to be taking a chunk of time on each item. I'm including screenshots and exported profile data. I've highlighted the VirtualizedList component with a red dot in the screenshots for visual comparison. The trace highlihts Swipeable in yellow for items rendered.
Performance profiles:
With Swipeable
swipeable-profiling-data.17-01-2025.22-03-28.json
Without Swipeable
no-swipeable-profiling-data.17-01-2025.22-08-42.json
Code
Stripped back as much as possible to make it easier to reproduce if needed.
The Swipeable is the outermost component of the SearchResult list item. Deleting the Swipeable significantly reduces rendering time, particularly noticeable on Android, especially an older real device I'm testing with:
import { memo, ReactElement, useCallback } from 'react';
import { StyleSheet, View, FlatList, Pressable, Text } from 'react-native';
import { Image } from 'expo-image';
import Swipeable from 'react-native-gesture-handler/ReanimatedSwipeable';
const deleteIcon = require('../assets/icons/trash.svg');
export interface Client {
id: string,
firstName: string,
lastName?: string,
}
interface SearchResultProps {
client: Client,
onSelect: (client: Client) => void,
renderRightActions: (client: Client) => ReactElement,
}
interface ClientListProps {
clients: Client[];
onDelete: (id: string) => void,
}
/**
* List item
*/
export const SearchResult = memo(({
client,
onSelect,
renderRightActions,
}: SearchResultProps) => {
return (
// This Swipeable seems to cause the issue
<Swipeable renderRightActions={() => renderRightActions(client)} containerStyle={{ borderRadius: 999, backgroundColor: 'gray', height: 48, marginBottom: 12 }}>
<View style={styles.searchResult}>
<Pressable onPress={() => onSelect(client)}>
<View style={styles.searchResultRow}>
<Text style={styles.searchResultText}>{client.firstName} {client.lastName}</Text>
</View>
</Pressable>
</View>
</Swipeable>
);
}, (prevProps, nextProps) => {
return (
prevProps.client.firstName === nextProps.client.firstName &&
prevProps.client.lastName === nextProps.client.lastName
);
});
/**
* FlatList
*/
export default function ClientList({ clients, onDelete }: ClientListProps): ReactElement {
// Create a render function for the left swipe action (delete)
const renderRightActions = useCallback((client: Client) => (
<Pressable onPress={() => { onDelete(client.id); }} style={styles.actionButton}>
<View style={styles.actionIconContainer}>
<Image source={deleteIcon} style={[styles.actionIcon, { tintColor: 'white' }]} contentFit="contain" testID="deleteIcon" />
</View>
</Pressable>
), []);
const renderitem = useCallback(({ item }: { item: Client, index: number; }) => (
<SearchResult client={item} onSelect={() => { }} renderRightActions={renderRightActions} />
), []);
return (
<View style={{ flex: 1 }}>
<View style={styles.searchResultsContainer}>
<FlatList
data={clients}
keyExtractor={(i) => i.id}
renderItem={renderitem}
/>
</View>
</View>
);
}
const styles = StyleSheet.create({
searchResultsContainer: {
flex: 4,
backgroundColor: 'white',
},
actionButton: {
width: 48,
height: 48,
borderRadius: 999,
backgroundColor: 'red',
},
actionIconContainer: {
height: '100%',
width: '100%',
justifyContent: 'center',
alignItems: 'center',
},
actionIcon: {
height: 28,
width: 28,
},
searchResult: {
marginBottom: 12, // Make up for 'gap' not working in FlatList
},
searchResultRow: {
height: 48,
flexDirection: 'row',
gap: 16,
alignItems: 'center',
backgroundColor: 'white',
borderRadius: 999,
},
searchResultText: {
fontSize: 16,
lineHeight: 24,
color: 'black',
},
});
"react-native-gesture-handler": "~2.20.2",
"react-native-reanimated": "~3.16.1"
Snack or a link to a repository
https://snack.expo.dev/@davidcarboni/swipeable-performance
Gesture Handler version
~2.20.2
React Native version
0.76.6
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
Expo managed workflow
Architecture
Fabric (New Architecture)
Build type
Debug mode
Device
Real device
Device model
OnePlus 9, OnePlus 5 (also Android Emulator and iPhone 11)
Acknowledgements
Yes
- Ngôn ngữ chính
- TypeScript
- Star
- 6.8k
- Fork
- 1.1k
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 28
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của software-mansion/react-native-gesture-handler
-
GestureDetector should bubble touches if all gestures fail (or some other generalized solution)Đang mởMissing repro Platform: Android Platform: iOS
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 39/100
software-mansion/react-native-gesture-handler#4714 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Web] A pan that starts on a Pressable presses it when the mouse button is releasedCó thể đã có người làm @mokshupadhyay đã nhận 2 ngày trước. Đang mởPlatform: Web
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
software-mansion/react-native-gesture-handler#4713 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS] Crash at app exit: static `_managers` map destroyed while `flushOperations` reads itCó thể đã có người làm @beqramo đã nhận 5 ngày trước. Đang mởMissing info Missing repro Platform: iOS Platform: MacOS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 30/100
software-mansion/react-native-gesture-handler#4711 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS][Fabric] Recognizer of a live handler stays on a recycled view and takes every drag on the component that reuses itCó thể đã có người làm @nihar777 đã nhận 6 ngày trước. Đang mởPlatform: iOS
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
software-mansion/react-native-gesture-handler#4710 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[iOS] Button press feedback invisible on quick taps when Reduce Motion is enabledCó thể đã có người làm @andreialecu đã nhận 8 ngày trước. Đang mởMissing info Platform: iOS Platform: MacOS
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
software-mansion/react-native-gesture-handler#4707 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của software-mansion/react-native-gesture-handler
Issue tương tự
-
agentic-workflows
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
opencollective/opencollective-frontend#12789 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Web download page shows a file as Completed when its download from S3 fails with an error responseĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
awslabs/visual-asset-management-system#2097 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
openwatersio/slackwater#591 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
compiler-explorer/compiler-explorer#9738 ·
Maintainer thường phản hồi trong vòng 2 ngày