Skip to content

Commit 070e146

Browse files
authored
fix: resolve Metro bundler error for optional FlashList dependency (cherry pick) (#123)
- Separate optional library imports into dedicated file - Fix "Requiring unknown module" error when FlashList is not installed
1 parent 8cfd432 commit 070e146

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"react-native-gesture-image-viewer": patch
3+
---
4+
5+
fix: resolve Metro bundler error for optional FlashList dependency (cherry pick)
6+
7+
- Separate optional library imports into dedicated file
8+
- Fix "Requiring unknown module" error when FlashList is not installed

src/utils/FlashList.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export let FlashList: any = null;
2+
3+
try {
4+
FlashList = require('@shopify/flash-list').FlashList;
5+
} catch {
6+
FlashList = null;
7+
}

src/utils.ts renamed to src/utils/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FlatList as RNFlatList, ScrollView as RNScrollView } from 'react-native';
22
import { FlatList as GestureFlatList, ScrollView as GestureScrollView } from 'react-native-gesture-handler';
3-
import type { FlatListComponent, ScrollViewComponent } from './types';
3+
import type { FlatListComponent, ScrollViewComponent } from '../types';
4+
import { FlashList } from './FlashList';
45

56
export const isScrollViewLike = (component: React.ComponentType<any>): component is ScrollViewComponent => {
67
return component === RNScrollView || component === GestureScrollView;
@@ -15,14 +16,8 @@ export const isFlatListLike = (component: React.ComponentType<any>): component i
1516
};
1617

1718
export const isFlashListLike = (component: React.ComponentType<any>): boolean => {
18-
try {
19-
const FlashList = require('@shopify/flash-list')?.FlashList;
20-
21-
if (FlashList && component === FlashList) {
22-
return true;
23-
}
24-
} catch {
25-
// do nothing
19+
if (FlashList && component === FlashList) {
20+
return true;
2621
}
2722

2823
return component?.displayName === 'FlashList' || component?.name === 'FlashList';

0 commit comments

Comments
 (0)