Skip to content

Commit a1c480e

Browse files
committed
feat: add support for react compiler on RN 0.77
1 parent 6a1e9f6 commit a1c480e

31 files changed

+205
-168
lines changed

Diff for: package/expo-package/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -4733,10 +4733,10 @@ stream-buffers@2.2.x, stream-buffers@~2.2.0:
47334733
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
47344734
integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg==
47354735

4736-
stream-chat-react-native-core@6.6.7:
4737-
version "6.6.7"
4738-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-6.6.7.tgz#d887234af18890c3396f1b8b5f169d9b28a793ab"
4739-
integrity sha512-Xc/S92nUBSwfVPZqNjt/zNs/DJcRV1aRa/+yCSBCqjCwo0EuiWEP9yKy3xGxBkehNe4vaIDvkeREduA4dRUGpA==
4736+
stream-chat-react-native-core@6.6.8:
4737+
version "6.6.8"
4738+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-6.6.8.tgz#483ade63ba051426480ab2dfd8ab3b248b90ae88"
4739+
integrity sha512-F8S70DHaiit6BEdKOkSMHq2bjMONhrouvJ+szBQuE430EJDgUlc2VErHk3yJCzqIt5lwfVZktjHuqSIOGVg5LQ==
47404740
dependencies:
47414741
"@gorhom/bottom-sheet" "^5.1.1"
47424742
dayjs "1.10.5"

Diff for: package/native-package/src/optionalDependencies/FlatList.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { FlatList as DefaultFlatList, Platform } from 'react-native';
22
let FlatList;
33

4-
54
if (Platform.constants.reactNativeVersion.minor < 72) {
65
const upgradeLog =
7-
"'@stream-io/flat-list-mvcp' is deprecated, please upgrade your react-native version to >0.71 to get same the benefits on the default FlatList and uninstall the package.";
6+
"'@stream-io/flat-list-mvcp' is deprecated, please upgrade your react-native version to >0.71 to get same the benefits on the default FlatList and uninstall the package.";
87
try {
98
FlatList = require('@stream-io/flat-list-mvcp').FlatList;
109
console.log(upgradeLog);

Diff for: package/native-package/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -3409,10 +3409,10 @@ statuses@~1.5.0:
34093409
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
34103410
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==
34113411

3412-
stream-chat-react-native-core@6.6.7:
3413-
version "6.6.7"
3414-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-6.6.7.tgz#d887234af18890c3396f1b8b5f169d9b28a793ab"
3415-
integrity sha512-Xc/S92nUBSwfVPZqNjt/zNs/DJcRV1aRa/+yCSBCqjCwo0EuiWEP9yKy3xGxBkehNe4vaIDvkeREduA4dRUGpA==
3412+
stream-chat-react-native-core@6.6.8:
3413+
version "6.6.8"
3414+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-6.6.8.tgz#483ade63ba051426480ab2dfd8ab3b248b90ae88"
3415+
integrity sha512-F8S70DHaiit6BEdKOkSMHq2bjMONhrouvJ+szBQuE430EJDgUlc2VErHk3yJCzqIt5lwfVZktjHuqSIOGVg5LQ==
34163416
dependencies:
34173417
"@gorhom/bottom-sheet" "^5.1.1"
34183418
dayjs "1.10.5"

Diff for: package/src/components/Attachment/AudioAttachment.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import { useTheme } from '../../contexts';
88
import { useAudioPlayer } from '../../hooks/useAudioPlayer';
99
import { Audio, Pause, Play } from '../../icons';
1010
import {
11+
NativeHandlers,
1112
PlaybackStatus,
12-
SDK,
13-
Sound,
1413
SoundReturnType,
1514
VideoPayloadData,
1615
VideoProgressData,
@@ -51,7 +50,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
5150
testID,
5251
} = props;
5352
const { changeAudioSpeed, pauseAudio, playAudio, seekAudio } = useAudioPlayer({ soundRef });
54-
const isExpoCLI = SDK === 'stream-chat-expo';
53+
const isExpoCLI = NativeHandlers.SDK === 'stream-chat-expo';
5554
const isVoiceRecording = item.type === FileTypes.VoiceRecording;
5655

5756
/** This is for Native CLI Apps */
@@ -181,8 +180,8 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
181180
useEffect(() => {
182181
if (isExpoCLI) {
183182
const initiateSound = async () => {
184-
if (item && item.file && item.file.uri) {
185-
soundRef.current = await Sound.initializeSound(
183+
if (item && item.file && item.file.uri && NativeHandlers.Sound?.initializeSound) {
184+
soundRef.current = await NativeHandlers.Sound.initializeSound(
186185
{ uri: item.file.uri },
187186
{
188187
progressUpdateIntervalMillis: 100,
@@ -216,7 +215,7 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
216215
}
217216
};
218217
// For expo CLI
219-
if (!Sound.Player) {
218+
if (!NativeHandlers.Sound?.Player) {
220219
initalPlayPause();
221220
}
222221
}, [item.paused, isExpoCLI, pauseAudio, playAudio]);
@@ -344,8 +343,8 @@ export const AudioAttachment = (props: AudioAttachmentProps) => {
344343
</View>
345344
)}
346345
</View>
347-
{Sound.Player && (
348-
<Sound.Player
346+
{NativeHandlers.Sound?.Player && (
347+
<NativeHandlers.Sound.Player
349348
onEnd={handleEnd}
350349
onLoad={handleLoad}
351350
onProgress={handleProgress}

Diff for: package/src/components/AttachmentPicker/AttachmentPicker.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../../contexts/attachmentPickerContext/AttachmentPickerContext';
1818
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1919
import { useScreenDimensions } from '../../hooks/useScreenDimensions';
20-
import { getPhotos, oniOS14GalleryLibrarySelectionChange } from '../../native';
20+
import { NativeHandlers } from '../../native';
2121
import type { Asset } from '../../types/types';
2222
import { BottomSheet } from '../BottomSheetCompatibility/BottomSheet';
2323
import { BottomSheetFlatList } from '../BottomSheetCompatibility/BottomSheetFlatList';
@@ -122,11 +122,12 @@ export const AttachmentPicker = React.forwardRef(
122122
setLoadingPhotos(true);
123123
const endCursor = endCursorRef.current;
124124
try {
125-
if (!getPhotos) {
125+
if (!NativeHandlers.getPhotos) {
126126
setPhotos([]);
127127
setIosLimited(false);
128+
return;
128129
}
129-
const results = await getPhotos({
130+
const results = await NativeHandlers.getPhotos({
130131
after: endCursor,
131132
first: numberOfAttachmentImagesToLoadPerCall ?? 60,
132133
});
@@ -153,11 +154,11 @@ export const AttachmentPicker = React.forwardRef(
153154
return;
154155
}
155156

156-
if (!oniOS14GalleryLibrarySelectionChange) {
157+
if (!NativeHandlers.oniOS14GalleryLibrarySelectionChange) {
157158
return;
158159
}
159160
// ios 14 library selection change event is fired when user reselects the images that are permitted to be readable by the app
160-
const { unsubscribe } = oniOS14GalleryLibrarySelectionChange(() => {
161+
const { unsubscribe } = NativeHandlers.oniOS14GalleryLibrarySelectionChange(() => {
161162
// we reset the cursor and has next page to true to facilitate fetching of the first page of photos again
162163
hasNextPageRef.current = true;
163164
endCursorRef.current = undefined;

Diff for: package/src/components/AttachmentPicker/components/AttachmentPickerIOSSelectMorePhotos.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Pressable, StyleSheet, Text } from 'react-native';
33

44
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
55
import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext';
6-
import { iOS14RefreshGallerySelection } from '../../../native';
6+
import { NativeHandlers } from '../../../native';
77

88
export const AttachmentPickerIOSSelectMorePhotos = () => {
99
const { t } = useTranslationContext();
@@ -13,13 +13,13 @@ export const AttachmentPickerIOSSelectMorePhotos = () => {
1313
},
1414
} = useTheme();
1515

16-
if (!iOS14RefreshGallerySelection) {
16+
if (!NativeHandlers.iOS14RefreshGallerySelection) {
1717
return null;
1818
}
1919

2020
return (
2121
<Pressable
22-
onPress={iOS14RefreshGallerySelection}
22+
onPress={NativeHandlers.iOS14RefreshGallerySelection}
2323
style={[styles.container, { backgroundColor: white }]}
2424
>
2525
<Text style={[styles.text, { color: accent_blue }]}>{t<string>('Select More Photos')}</Text>

Diff for: package/src/components/Channel/Channel.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ import {
8484
WutReaction,
8585
} from '../../icons';
8686
import {
87-
FlatList as FlatListDefault,
8887
isDocumentPickerAvailable,
8988
isImageMediaLibraryAvailable,
9089
isImagePickerAvailable,
90+
NativeHandlers,
9191
} from '../../native';
9292
import * as dbApi from '../../store/apis';
9393
import { ChannelUnreadState, DefaultStreamChatGenerics, FileTypes } from '../../types/types';
@@ -538,7 +538,7 @@ const ChannelWithContext = <
538538
FileAttachmentGroup = FileAttachmentGroupDefault,
539539
FileAttachmentIcon = FileIconDefault,
540540
FileUploadPreview = FileUploadPreviewDefault,
541-
FlatList = FlatListDefault,
541+
FlatList = NativeHandlers.FlatList,
542542
forceAlignMessages,
543543
Gallery = GalleryDefault,
544544
getMessagesGroupStyles,

Diff for: package/src/components/Chat/Chat.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import { useStreami18n } from '../../hooks/useStreami18n';
2424
import init from '../../init';
2525

26-
import { SDK } from '../../native';
26+
import { NativeHandlers } from '../../native';
2727
import { SqliteClient } from '../../store/SqliteClient';
2828
import type { DefaultStreamChatGenerics } from '../../types/types';
2929
import { DBSyncManager } from '../../utils/DBSyncManager';
@@ -187,9 +187,9 @@ const ChatWithContext = <
187187

188188
useEffect(() => {
189189
if (client) {
190-
const sdkName = (SDK ? SDK.replace('stream-chat-', '') : 'react-native') as
191-
| 'react-native'
192-
| 'expo';
190+
const sdkName = (
191+
NativeHandlers.SDK ? NativeHandlers.SDK.replace('stream-chat-', '') : 'react-native'
192+
) as 'react-native' | 'expo';
193193
client.sdkIdentifier = {
194194
name: sdkName,
195195
version,

Diff for: package/src/components/ImageGallery/__tests__/ImageGallery.test.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ jest.mock('../../../native.ts', () => {
2828
isImageMediaLibraryAvailable: jest.fn(() => true),
2929
isShareImageAvailable: jest.fn(() => true),
3030
isVideoPlayerAvailable: jest.fn(() => true),
31-
Video: View,
31+
NativeHandlers: {
32+
Video: View,
33+
},
3234
};
3335
});
3436

Diff for: package/src/components/ImageGallery/__tests__/ImageGalleryFooter.test.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ import {
1919
} from '../../../mock-builders/generator/attachment';
2020
import { generateMessage } from '../../../mock-builders/generator/message';
2121
import { getTestClientWithUser } from '../../../mock-builders/mock';
22-
import * as NativeUtils from '../../../native';
22+
import { NativeHandlers } from '../../../native';
2323
import type { DefaultStreamChatGenerics } from '../../../types/types';
2424
import type { MessageType } from '../../MessageList/hooks/useMessageList';
2525
import { ImageGallery, ImageGalleryCustomComponents } from '../ImageGallery';
2626

2727
jest.mock('../../../native.ts', () => {
2828
const View = require('react-native/Libraries/Components/View/View');
2929
return {
30-
deleteFile: jest.fn(),
3130
isFileSystemAvailable: jest.fn(() => true),
3231
isImageMediaLibraryAvailable: jest.fn(() => true),
3332
isShareImageAvailable: jest.fn(() => true),
3433
isVideoPlayerAvailable: jest.fn(() => true),
35-
saveFile: jest.fn(),
36-
shareImage: jest.fn(),
37-
Video: View,
34+
NativeHandlers: {
35+
deleteFile: jest.fn(),
36+
saveFile: jest.fn(),
37+
shareImage: jest.fn(),
38+
Video: View,
39+
},
3840
};
3941
});
4042

@@ -160,9 +162,9 @@ describe('ImageGalleryFooter', () => {
160162
it('should trigger the share button onPress Handler', async () => {
161163
const user = userEvent.setup();
162164
const chatClient = await getTestClientWithUser({ id: 'testID' });
163-
const saveFileMock = jest.spyOn(NativeUtils, 'saveFile');
164-
const shareImageMock = jest.spyOn(NativeUtils, 'shareImage');
165-
const deleteFileMock = jest.spyOn(NativeUtils, 'deleteFile');
165+
const saveFileMock = jest.spyOn(NativeHandlers, 'saveFile');
166+
const shareImageMock = jest.spyOn(NativeHandlers, 'shareImage');
167+
const deleteFileMock = jest.spyOn(NativeHandlers, 'deleteFile');
166168

167169
render(
168170
<OverlayProvider>

Diff for: package/src/components/ImageGallery/__tests__/ImageGalleryHeader.test.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jest.mock('../../../native.ts', () => {
3434
isImageMediaLibraryAvailable: jest.fn(() => true),
3535
isShareImageAvailable: jest.fn(() => true),
3636
isVideoPlayerAvailable: jest.fn(() => true),
37-
Video: View,
37+
NativeHandlers: {
38+
Video: View,
39+
},
3840
};
3941
});
4042

Diff for: package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import Animated, { SharedValue } from 'react-native-reanimated';
55

66
import {
77
isVideoPlayerAvailable,
8+
NativeHandlers,
89
PlaybackStatus,
9-
Video,
1010
VideoPayloadData,
1111
VideoProgressData,
1212
VideoType,
@@ -156,8 +156,8 @@ export const AnimatedGalleryVideo = React.memo(
156156

157157
return (
158158
<Animated.View accessibilityLabel='Image Gallery Video' style={[...animatedStyles, style]}>
159-
{isVideoPlayerAvailable() ? (
160-
<Video
159+
{isVideoPlayerAvailable() && NativeHandlers.Video ? (
160+
<NativeHandlers.Video
161161
onBuffer={onBuffer}
162162
onEnd={onEnd}
163163
onLoad={onLoad}

Diff for: package/src/components/ImageGallery/components/ImageGalleryFooter.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import { useTheme } from '../../../contexts/themeContext/ThemeContext';
1313
import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext';
1414
import { Grid as GridIconDefault, Share as ShareIconDefault } from '../../../icons';
1515
import {
16-
deleteFile,
1716
isFileSystemAvailable,
1817
isShareImageAvailable,
19-
saveFile,
20-
shareImage,
18+
NativeHandlers,
2119
VideoType,
2220
} from '../../../native';
2321

@@ -138,19 +136,19 @@ export const ImageGalleryFooterWithContext = <
138136
const share = async () => {
139137
setShareMenuOpen(true);
140138
try {
141-
if (!shareImage || !deleteFile) {
139+
if (!NativeHandlers.shareImage || !NativeHandlers.deleteFile) {
142140
return;
143141
}
144142
const extension = photo.mime_type?.split('/')[1] || 'jpg';
145-
const localFile = await saveFile({
143+
const localFile = await NativeHandlers.saveFile({
146144
fileName: `${photo.user?.id || 'ChatPhoto'}-${
147145
photo.messageId
148146
}-${selectedIndex}.${extension}`,
149147
fromUrl: photo.uri,
150148
});
151149
// `image/jpeg` is added for the case where the mime_type isn't available for a file/image
152-
await shareImage({ type: photo.mime_type || 'image/jpeg', url: localFile });
153-
await deleteFile({ uri: localFile });
150+
await NativeHandlers.shareImage({ type: photo.mime_type || 'image/jpeg', url: localFile });
151+
await NativeHandlers.deleteFile({ uri: localFile });
154152
} catch (error) {
155153
console.log(error);
156154
}

Diff for: package/src/components/ImageGallery/hooks/useImageGalleryGestures.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313

1414
import { useImageGalleryContext } from '../../../contexts/imageGalleryContext/ImageGalleryContext';
1515
import { useOverlayContext } from '../../../contexts/overlayContext/OverlayContext';
16-
import { triggerHaptic } from '../../../native';
16+
import { NativeHandlers } from '../../../native';
1717

1818
export enum HasPinched {
1919
FALSE = 0,
@@ -453,6 +453,8 @@ export const useImageGalleryGestures = ({
453453
.simultaneousWithExternalGesture(pinchRef)
454454
.withRef(panRef);
455455

456+
const triggerHaptic = NativeHandlers.triggerHaptic;
457+
456458
/**
457459
* On pinch is run when two or more fingers touch the screen, it then takes over
458460
* all touch handling even if the number of fingers is reduced to one until the

Diff for: package/src/components/Message/Message.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
useTranslationContext,
3232
} from '../../contexts/translationContext/TranslationContext';
3333

34-
import { isVideoPlayerAvailable, triggerHaptic } from '../../native';
34+
import { isVideoPlayerAvailable, NativeHandlers } from '../../native';
3535
import { DefaultStreamChatGenerics, FileTypes } from '../../types/types';
3636
import {
3737
hasOnlyEmojis,
@@ -623,7 +623,7 @@ const MessageWithContext = <
623623
setIsBounceDialogOpen(true);
624624
return;
625625
}
626-
triggerHaptic('impactMedium');
626+
NativeHandlers.triggerHaptic('impactMedium');
627627
showMessageOverlay();
628628
};
629629

Diff for: package/src/components/Message/MessageSimple/MessageSimple.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '../../../contexts/messagesContext/MessagesContext';
2323
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
2424

25-
import { triggerHaptic } from '../../../native';
25+
import { NativeHandlers } from '../../../native';
2626
import type { DefaultStreamChatGenerics } from '../../../types/types';
2727
import { useMessageData } from '../hooks/useMessageData';
2828

@@ -213,6 +213,8 @@ const MessageSimpleWithContext = <
213213

214214
const THRESHOLD = 25;
215215

216+
const triggerHaptic = NativeHandlers.triggerHaptic;
217+
216218
const swipeGesture = Gesture.Pan()
217219
.hitSlop(messageSwipeToReplyHitSlop)
218220
.onBegin((event) => {
@@ -245,7 +247,9 @@ const MessageSimpleWithContext = <
245247
.onEnd(() => {
246248
if (translateX.value >= THRESHOLD) {
247249
runOnJS(onSwipeToReply)();
248-
runOnJS(triggerHaptic)('impactMedium');
250+
if (triggerHaptic) {
251+
runOnJS(triggerHaptic)('impactMedium');
252+
}
249253
}
250254
translateX.value = withSpring(0, {
251255
dampingRatio: 1,

0 commit comments

Comments
 (0)