Skip to content

Commit ab33e21

Browse files
committed
fix(#1968): moved the flashlist optional import into the component body
1 parent 2a1b2d4 commit ab33e21

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/components/bottomSheetScrollable/BottomSheetFlashList.tsx

+16-9
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@ import type {
99
BottomSheetScrollableProps,
1010
} from './types';
1111

12-
let FlashList: React.FC;
13-
12+
let FlashList: {
13+
FlashList: React.FC;
14+
};
15+
// since FlashList is not a dependency for the library
16+
// we try to import it using metro optional import
1417
try {
15-
FlashList = require('@shopify/flash-list').FlashList as never;
16-
} catch (_) {
17-
throw 'You need to install FlashList first, `yarn install @shopify/flash-list`';
18-
}
18+
FlashList = require('@shopify/flash-list') as never;
19+
} catch (_) {}
1920

2021
export type BottomSheetFlashListProps<T> = Omit<
2122
Animated.AnimateProps<FlashListProps<T>>,
2223
'decelerationRate' | 'onScroll' | 'scrollEventThrottle'
2324
> &
2425
BottomSheetScrollableProps & {
25-
ref?: Ref<typeof FlashList>;
26+
ref?: Ref<React.FC>;
2627
};
2728

2829
const BottomSheetFlashListComponent = forwardRef<
29-
typeof FlashList,
30+
React.FC,
3031
// biome-ignore lint/suspicious/noExplicitAny: to be addressed
3132
BottomSheetFlashListProps<any>
3233
>((props, ref) => {
@@ -40,6 +41,12 @@ const BottomSheetFlashListComponent = forwardRef<
4041
}: any = props;
4142
//#endregion
4243

44+
useMemo(() => {
45+
if (!FlashList) {
46+
throw 'You need to install FlashList first, `yarn install @shopify/flash-list`';
47+
}
48+
}, []);
49+
4350
//#region render
4451
const renderScrollComponent = useMemo(
4552
() =>
@@ -61,7 +68,7 @@ const BottomSheetFlashListComponent = forwardRef<
6168
[focusHook, scrollEventsHandlersHook, enableFooterMarginAdjustment]
6269
);
6370
return (
64-
<FlashList
71+
<FlashList.FlashList
6572
ref={ref}
6673
renderScrollComponent={renderScrollComponent}
6774
{...rest}

0 commit comments

Comments
 (0)