1
- import type { ForwardedRef , ReactElement } from 'react' ;
2
- import type { FlatListProps , FlatList as RNFlatList , ScrollViewProps } from 'react-native' ;
3
1
import { Platform } from 'react-native' ;
4
2
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
-
17
3
function shouldUseScrollViewEnhancer ( ) {
18
4
if ( Platform . constants . reactNativeVersion ?. major < 1 ) {
19
5
if ( Platform . constants . reactNativeVersion ?. minor < 72 ) {
@@ -22,17 +8,14 @@ function shouldUseScrollViewEnhancer() {
22
8
}
23
9
return false ;
24
10
}
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 ;
34
18
}
35
19
}
36
20
37
- const FlatListInternal = getFlatList ( ) ;
38
21
export default FlatListInternal ;
0 commit comments