Skip to content

Commit 6c19b24

Browse files
authored
Merge pull request #231 from sendbird/fix/support-metro-0.81.3
[CLNP-6534] fix: resolve FlatList-related error on Metro 0.81.3
2 parents 119150f + 4d8d88f commit 6c19b24

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed
Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
import type { ForwardedRef, ReactElement } from 'react';
2-
import type { FlatListProps, FlatList as RNFlatList, ScrollViewProps } from 'react-native';
31
import { Platform } from 'react-native';
42

5-
import type { SendbirdMessage } from '@sendbird/uikit-utils';
6-
7-
type FlatListBidirectional<T = SendbirdMessage> = (props: FlatListProps<T> & BidirectionalProps<T>) => ReactElement;
8-
type BidirectionalProps<T> = {
9-
onStartReached?: ((info: { distanceFromStart: number }) => void) | null | undefined;
10-
onStartReachedThreshold?: number | null | undefined;
11-
onEndReached?: ((info: { distanceFromEnd: number }) => void) | null | undefined;
12-
onEndReachedThreshold?: number | null | undefined;
13-
maintainVisibleContentPosition?: ScrollViewProps['maintainVisibleContentPosition'];
14-
ref: ForwardedRef<RNFlatList<T>>;
15-
};
16-
173
function shouldUseScrollViewEnhancer() {
184
if (Platform.constants.reactNativeVersion?.major < 1) {
195
if (Platform.constants.reactNativeVersion?.minor < 72) {
@@ -22,17 +8,14 @@ function shouldUseScrollViewEnhancer() {
228
}
239
return false;
2410
}
25-
function getFlatList(): FlatListBidirectional {
26-
if (shouldUseScrollViewEnhancer()) {
27-
try {
28-
return require('@sendbird/react-native-scrollview-enhancer').FlatList;
29-
} catch {
30-
return require('react-native').FlatList;
31-
}
32-
} else {
33-
return require('react-native').FlatList;
11+
12+
let FlatListInternal = require('react-native').FlatList;
13+
if (shouldUseScrollViewEnhancer()) {
14+
try {
15+
FlatListInternal = require('@sendbird/react-native-scrollview-enhancer').FlatList;
16+
} catch {
17+
FlatListInternal = require('react-native').FlatList;
3418
}
3519
}
3620

37-
const FlatListInternal = getFlatList();
3821
export default FlatListInternal;

0 commit comments

Comments
 (0)