Skip to content

Commit 4f8dbad

Browse files
committed
fix: add check for handlers in native.ts
1 parent d6741b8 commit 4f8dbad

File tree

17 files changed

+72
-38
lines changed

17 files changed

+72
-38
lines changed

package/expo-package/src/optionalDependencies/triggerHaptic.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ export const triggerHaptic = Haptics
4545
Haptics.selectionAsync();
4646
}
4747
}
48-
: // eslint-disable-next-line @typescript-eslint/no-empty-function
49-
() => {};
48+
: () => {};

package/src/components/Attachment/Attachment.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
MessagesContextValue,
1212
useMessagesContext,
1313
} from '../../contexts/messagesContext/MessagesContext';
14-
import { Video } from '../../native';
14+
import { isVideoPlayerAvailable } from '../../native';
1515

1616
import type { DefaultStreamChatGenerics } from '../../types/types';
1717

@@ -75,7 +75,7 @@ const AttachmentWithContext = <
7575
}
7676

7777
if (attachment.type === 'video' && !attachment.og_scrape_url) {
78-
return Video ? (
78+
return isVideoPlayerAvailable() ? (
7979
<>
8080
<Gallery videos={[attachment]} />
8181
{hasAttachmentActions && (

package/src/components/Attachment/Gallery.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
} from '../../contexts/overlayContext/OverlayContext';
3232
import { useTheme } from '../../contexts/themeContext/ThemeContext';
3333
import { useLoadingImage } from '../../hooks/useLoadingImage';
34-
import { Video } from '../../native';
34+
import { isVideoPlayerAvailable } from '../../native';
3535
import type { DefaultStreamChatGenerics } from '../../types/types';
3636
import { getUrlWithoutParams } from '../../utils/utils';
3737

@@ -311,7 +311,7 @@ const GalleryThumbnail = <
311311
const defaultOnPress = () => {
312312
// If the url is defined then only try to open the file.
313313
if (thumbnail.url) {
314-
if (thumbnail.type === 'video' && !Video) {
314+
if (thumbnail.type === 'video' && !isVideoPlayerAvailable()) {
315315
// This condition is kinda unreachable, since we render videos as file attachment if the video
316316
// library is not installed. But doesn't hurt to have extra safeguard, in case of some customizations.
317317
openUrlSafely(thumbnail.url);

package/src/components/Attachment/__tests__/Attachment.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Attachment } from '../Attachment';
2121
import { AttachmentActions } from '../AttachmentActions';
2222

2323
jest.mock('../../../native.ts', () => ({
24-
Video: null,
24+
isVideoPlayerAvailable: jest.fn(() => false),
2525
}));
2626

2727
const getAttachmentComponent = (props) => {

package/src/components/Channel/Channel.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ import {
8181
ThumbsUpReaction,
8282
WutReaction,
8383
} from '../../icons';
84-
import { Audio, pickDocument, takePhoto } from '../../native';
84+
import {
85+
isAudioRecorderAvailable,
86+
isDocumentPickerAvailable,
87+
isImagePickerAvailable,
88+
} from '../../native';
8589
import * as dbApi from '../../store/apis';
8690
import type { DefaultStreamChatGenerics } from '../../types/types';
8791
import { addReactionToLocalState } from '../../utils/addReactionToLocalState';
@@ -439,7 +443,7 @@ const ChannelWithContext = <
439443
AudioAttachment = AudioAttachmentDefault,
440444
AudioAttachmentUploadPreview = AudioAttachmentDefault,
441445
AudioRecorder = AudioRecorderDefault,
442-
audioRecordingEnabled = Audio !== null,
446+
audioRecordingEnabled = isAudioRecorderAvailable(),
443447
AudioRecordingInProgress = AudioRecordingInProgressDefault,
444448
AudioRecordingLockIndicator = AudioRecordingLockIndicatorDefault,
445449
AudioRecordingPreview = AudioRecordingPreviewDefault,
@@ -497,10 +501,10 @@ const ChannelWithContext = <
497501
handleReaction,
498502
handleRetry,
499503
handleThreadReply,
500-
hasCameraPicker = takePhoto !== null,
504+
hasCameraPicker = isImagePickerAvailable(),
501505
hasCommands = true,
502506
// If pickDocument isn't available, default to hiding the file picker
503-
hasFilePicker = pickDocument !== null,
507+
hasFilePicker = isDocumentPickerAvailable(),
504508
hasImagePicker = true,
505509
hideDateSeparators = false,
506510
hideStickyDateHeader = false,

package/src/components/ImageGallery/ImageGallery.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { useImageGalleryContext } from '../../contexts/imageGalleryContext/Image
4040
import { OverlayProviderProps } from '../../contexts/overlayContext/OverlayContext';
4141
import { useTheme } from '../../contexts/themeContext/ThemeContext';
4242
import { useViewport } from '../../hooks/useViewport';
43-
import { Video, VideoType } from '../../native';
43+
import { isVideoPlayerAvailable, VideoType } from '../../native';
4444
import type { DefaultStreamChatGenerics } from '../../types/types';
4545
import { getResizedImageUrl } from '../../utils/getResizedImageUrl';
4646
import { getUrlOfImageAttachment } from '../../utils/getUrlOfImageAttachment';
@@ -229,7 +229,7 @@ export const ImageGallery = <
229229
!attachment.title_link &&
230230
!attachment.og_scrape_url &&
231231
getUrlOfImageAttachment(attachment)) ||
232-
(Video && attachment.type === 'video'),
232+
(isVideoPlayerAvailable() && attachment.type === 'video'),
233233
)
234234
.reverse() || [];
235235

package/src/components/ImageGallery/__tests__/ImageGallery.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { ImageGallery } from '../ImageGallery';
2424
jest.mock('../../../native.ts', () => {
2525
const View = require('react-native/Libraries/Components/View/View');
2626
return {
27+
isFileSystemAvailable: jest.fn(() => true),
28+
isShareImageAvailable: jest.fn(() => true),
29+
isVideoPlayerAvailable: jest.fn(() => true),
2730
Video: View,
2831
};
2932
});

package/src/components/ImageGallery/__tests__/ImageGalleryFooter.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jest.mock('../../../native.ts', () => {
2828
const View = require('react-native/Libraries/Components/View/View');
2929
return {
3030
deleteFile: jest.fn(),
31+
isFileSystemAvailable: jest.fn(() => true),
32+
isShareImageAvailable: jest.fn(() => true),
33+
isVideoPlayerAvailable: jest.fn(() => true),
3134
saveFile: jest.fn(),
3235
shareImage: jest.fn(),
3336
Video: View,

package/src/components/ImageGallery/__tests__/ImageGalleryHeader.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import { ImageGallery, ImageGalleryCustomComponents } from '../ImageGallery';
3030
jest.mock('../../../native.ts', () => {
3131
const View = require('react-native/Libraries/Components/View/View');
3232
return {
33+
isFileSystemAvailable: jest.fn(() => true),
34+
isShareImageAvailable: jest.fn(() => true),
35+
isVideoPlayerAvailable: jest.fn(() => true),
3336
Video: View,
3437
};
3538
});

package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Animated, { useAnimatedStyle } from 'react-native-reanimated';
55

66
import { useViewport } from '../../../hooks/useViewport';
77
import {
8+
isVideoPlayerAvailable,
89
PlaybackStatus,
910
Video,
1011
VideoPayloadData,
@@ -186,7 +187,7 @@ export const AnimatedGalleryVideo = React.memo(
186187
},
187188
]}
188189
>
189-
{Video ? (
190+
{isVideoPlayerAvailable() ? (
190191
<Video
191192
onBuffer={onBuffer}
192193
onEnd={onEnd}

0 commit comments

Comments
 (0)