Skip to content

Commit 4be768c

Browse files
committed
chore: resolution error when trying module fallback with ts source imports
1 parent a00b089 commit 4be768c

File tree

4 files changed

+56
-43
lines changed

4 files changed

+56
-43
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { FastImageProps } from 'react-native-fast-image';
2+
3+
let FastImageInternal: (props: FastImageProps) => JSX.Element | null = () => null;
4+
5+
try {
6+
FastImageInternal = require('react-native-fast-image') as (props: FastImageProps) => JSX.Element;
7+
} catch {}
8+
9+
export default FastImageInternal;

packages/uikit-react-native-foundation/src/components/Image/Image.fastimage.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import type { FastImageProps, ResizeMode, Source } from 'react-native-fast-image';
33

4+
import FastImageInternal from './FastImageInternal';
45
import type { SendbirdImageComponent, SendbirdImageProps } from './index';
56

67
function convertCache(
@@ -53,12 +54,6 @@ function convertResizeMode(mode?: SendbirdImageProps['resizeMode']): ResizeMode
5354
}
5455
}
5556

56-
let FastImage: (props: FastImageProps) => JSX.Element | null = () => null;
57-
58-
try {
59-
FastImage = require('react-native-fast-image') as (props: FastImageProps) => JSX.Element;
60-
} catch {}
61-
6257
const Image_FastImage: SendbirdImageComponent = ({
6358
source,
6459
defaultSource,
@@ -69,7 +64,7 @@ const Image_FastImage: SendbirdImageComponent = ({
6964
...props
7065
}) => {
7166
return (
72-
<FastImage
67+
<FastImageInternal
7368
{...props}
7469
onLoad={onLoad && ((e) => onLoad(e.nativeEvent))}
7570
onError={onError && (() => onError({}))}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* */
3+
import type { ForwardedRef, ReactElement } from 'react';
4+
import type { FlatListProps, FlatList as RNFlatList, ScrollViewProps } from 'react-native';
5+
import { Platform } from 'react-native';
6+
7+
import type { SendbirdMessage } from '@sendbird/uikit-utils';
8+
9+
type FlatListBidirectional<T = SendbirdMessage> = (props: FlatListProps<T> & BidirectionalProps<T>) => ReactElement;
10+
type BidirectionalProps<T> = {
11+
onStartReached?: ((info: { distanceFromStart: number }) => void) | null | undefined;
12+
onStartReachedThreshold?: number | null | undefined;
13+
onEndReached?: ((info: { distanceFromEnd: number }) => void) | null | undefined;
14+
onEndReachedThreshold?: number | null | undefined;
15+
maintainVisibleContentPosition?: ScrollViewProps['maintainVisibleContentPosition'];
16+
ref: ForwardedRef<RNFlatList<T>>;
17+
};
18+
19+
function shouldUseScrollViewEnhancer() {
20+
if (Platform.constants.reactNativeVersion.major < 1) {
21+
if (Platform.constants.reactNativeVersion.minor < 72) {
22+
return true;
23+
}
24+
}
25+
return false;
26+
}
27+
function getFlatList(): FlatListBidirectional {
28+
if (shouldUseScrollViewEnhancer()) {
29+
try {
30+
return require('@sendbird/react-native-scrollview-enhancer').FlatList;
31+
} catch {
32+
return require('react-native').FlatList;
33+
}
34+
} else {
35+
return require('react-native').FlatList;
36+
}
37+
}
38+
39+
const FlatListInternal = getFlatList();
40+
export default FlatListInternal;

packages/uikit-react-native/src/components/ChatFlatList.tsx renamed to packages/uikit-react-native/src/components/ChatFlatList/index.tsx

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,15 @@
1-
import React, { ForwardedRef, forwardRef, useRef } from 'react';
2-
import { FlatListProps, Platform, FlatList as RNFlatList, ScrollViewProps, StyleSheet } from 'react-native';
1+
import React, { forwardRef, useRef } from 'react';
2+
import { FlatListProps, Platform, FlatList as RNFlatList, StyleSheet } from 'react-native';
33

44
import { useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
55
import { NOOP, SendbirdMessage, getMessageUniqId, useFreshCallback } from '@sendbird/uikit-utils';
66

7+
import FlatListInternal from './FlatListInternal';
8+
79
let ANDROID_BUG_ALERT_SHOWED = Platform.OS !== 'android';
810
const BOTTOM_DETECT_THRESHOLD = 25;
911
const UNREACHABLE_THRESHOLD = Number.MIN_SAFE_INTEGER;
1012

11-
type FlatListBidirectional<T = SendbirdMessage> = (
12-
props: FlatListProps<T> & BidirectionalProps<T>,
13-
) => React.ReactElement;
14-
type BidirectionalProps<T> = {
15-
onStartReached?: ((info: { distanceFromStart: number }) => void) | null | undefined;
16-
onStartReachedThreshold?: number | null | undefined;
17-
onEndReached?: ((info: { distanceFromEnd: number }) => void) | null | undefined;
18-
onEndReachedThreshold?: number | null | undefined;
19-
maintainVisibleContentPosition?: ScrollViewProps['maintainVisibleContentPosition'];
20-
ref: ForwardedRef<RNFlatList<T>>;
21-
};
22-
23-
function shouldUseScrollViewEnhancer() {
24-
if (Platform.constants.reactNativeVersion.major < 1) {
25-
if (Platform.constants.reactNativeVersion.minor < 72) {
26-
return true;
27-
}
28-
}
29-
return false;
30-
}
31-
32-
function getFlatList(): FlatListBidirectional {
33-
try {
34-
return !shouldUseScrollViewEnhancer()
35-
? require('@sendbird/react-native-scrollview-enhancer').FlatList
36-
: require('react-native').FlatList;
37-
} catch {
38-
return require('react-native').FlatList;
39-
}
40-
}
41-
42-
const FlatList = getFlatList();
43-
4413
type Props = Omit<FlatListProps<SendbirdMessage>, 'onEndReached'> & {
4514
onBottomReached: () => void;
4615
onTopReached: () => void;
@@ -81,7 +50,7 @@ const ChatFlatList = forwardRef<RNFlatList, Props>(function CustomFlatList(
8150
}
8251

8352
return (
84-
<FlatList
53+
<FlatListInternal
8554
bounces={false}
8655
removeClippedSubviews
8756
keyboardDismissMode={'on-drag'}

0 commit comments

Comments
 (0)