Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/tender-cows-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"react-native-gesture-image-viewer": patch
---

fix: remove key prop from list item children for better performance

- Remove key prop from View children when using FlatList/FlashList
- Keep key prop only for ScrollView children
- Improves FlashList performance by allowing proper item reuse
- Follows FlashList official performance guidelines

Refs: https://shopify.github.io/flash-list/docs/fundamentals/performance#remove-key-prop
8 changes: 5 additions & 3 deletions src/GestureViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export function GestureViewer<T = any, LC = typeof FlatList>({

const loopData = useMemo(() => createLoopData(dataRef, enableLoop), [enableLoop]);

const isScrollView = isScrollViewLike(Component);

const {
listRef,
isZoomed,
Expand Down Expand Up @@ -71,7 +73,7 @@ export function GestureViewer<T = any, LC = typeof FlatList>({
({ item, index }: { item: T; index: number }) => {
return (
<View
key={keyExtractor(item, index)}
key={isScrollView ? keyExtractor(item, index) : undefined}
style={[
{
width,
Expand All @@ -86,7 +88,7 @@ export function GestureViewer<T = any, LC = typeof FlatList>({
</View>
);
},
[width, itemSpacing, renderItemProp, keyExtractor],
[width, itemSpacing, renderItemProp, keyExtractor, isScrollView],
);

const getItemLayout = useCallback(
Expand Down Expand Up @@ -141,7 +143,7 @@ export function GestureViewer<T = any, LC = typeof FlatList>({
{...(Platform.OS === 'web' &&
isFlashListLike(Component) && { dataSet: { 'flash-list-paging-enabled-fix': true } })}
>
{isScrollViewLike(Component) ? (
{isScrollView ? (
<Component ref={listRef} {...commonProps} {...listProps}>
{loopData.map((item, index) => renderItem({ item, index }))}
</Component>
Expand Down