Skip to content

Commit 15e66a9

Browse files
authored
fix: make camera roll usage optional using a channel prop (#3263)
* fix: make camera roll usage optional using a channel prop * fix: make camera roll usage optional using a channel prop
1 parent 3db3508 commit 15e66a9

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ const debounceOptions = {
260260
};
261261

262262
export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
263-
Partial<Pick<AttachmentPickerContextValue, 'bottomInset' | 'topInset'>> &
263+
Partial<
264+
Pick<AttachmentPickerContextValue, 'bottomInset' | 'topInset' | 'disableAttachmentPicker'>
265+
> &
264266
Partial<
265267
Pick<
266268
AttachmentPickerProps,
@@ -558,6 +560,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
558560
customMessageSwipeAction,
559561
DateHeader = DateHeaderDefault,
560562
deletedMessagesVisibilityType = 'always',
563+
disableAttachmentPicker = !isImageMediaLibraryAvailable(),
561564
disableKeyboardCompatibleView = false,
562565
disableTypingIndicator,
563566
dismissKeyboardOnMessageTouch = true,
@@ -1690,10 +1693,11 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
16901693
bottomInset,
16911694
bottomSheetRef,
16921695
closePicker: () => closePicker(bottomSheetRef),
1696+
disableAttachmentPicker,
16931697
openPicker: () => openPicker(bottomSheetRef),
16941698
topInset,
16951699
}),
1696-
[bottomInset, bottomSheetRef, closePicker, openPicker, topInset],
1700+
[bottomInset, bottomSheetRef, closePicker, openPicker, topInset, disableAttachmentPicker],
16971701
);
16981702

16991703
const ownCapabilitiesContext = useCreateOwnCapabilitiesContext({
@@ -1992,7 +1996,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
19921996
<MessageComposerProvider value={messageComposerContext}>
19931997
<MessageInputProvider value={inputMessageInputContext}>
19941998
<View style={{ height: '100%' }}>{children}</View>
1995-
{isImageMediaLibraryAvailable() && (
1999+
{!disableAttachmentPicker && (
19962000
<AttachmentPicker ref={bottomSheetRef} {...attachmentPickerProps} />
19972001
)}
19982002
</MessageInputProvider>

package/src/components/MessageInput/AttachButton.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@ import { Pressable } from 'react-native';
44

55
import { NativeAttachmentPicker } from './components/NativeAttachmentPicker';
66

7-
import { useAttachmentPickerContext } from '../../contexts/attachmentPickerContext/AttachmentPickerContext';
7+
import {
8+
AttachmentPickerContextValue,
9+
useAttachmentPickerContext,
10+
} from '../../contexts/attachmentPickerContext/AttachmentPickerContext';
811
import {
912
MessageInputContextValue,
1013
useMessageInputContext,
1114
} from '../../contexts/messageInputContext/MessageInputContext';
1215
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1316
import { Attach } from '../../icons/Attach';
1417

15-
import { isImageMediaLibraryAvailable } from '../../native';
16-
1718
type AttachButtonPropsWithContext = Pick<
1819
MessageInputContextValue,
1920
'handleAttachButtonPress' | 'toggleAttachmentPicker'
20-
> & {
21-
disabled?: boolean;
22-
/** Function that opens attachment options bottom sheet */
23-
handleOnPress?: ((event: GestureResponderEvent) => void) & (() => void);
24-
selectedPicker?: 'images';
25-
};
21+
> &
22+
Pick<AttachmentPickerContextValue, 'disableAttachmentPicker' | 'selectedPicker'> & {
23+
disabled?: boolean;
24+
/** Function that opens attachment options bottom sheet */
25+
handleOnPress?: ((event: GestureResponderEvent) => void) & (() => void);
26+
};
2627

2728
const AttachButtonWithContext = (props: AttachButtonPropsWithContext) => {
2829
const [showAttachButtonPicker, setShowAttachButtonPicker] = useState<boolean>(false);
2930
const [attachButtonLayoutRectangle, setAttachButtonLayoutRectangle] = useState<LayoutRectangle>();
3031
const {
32+
disableAttachmentPicker,
3133
disabled = false,
3234
handleAttachButtonPress,
3335
handleOnPress,
@@ -73,7 +75,7 @@ const AttachButtonWithContext = (props: AttachButtonPropsWithContext) => {
7375
handleAttachButtonPress();
7476
return;
7577
}
76-
if (isImageMediaLibraryAvailable()) {
78+
if (!disableAttachmentPicker) {
7779
toggleAttachmentPicker();
7880
} else {
7981
attachButtonHandler();
@@ -132,12 +134,17 @@ export type AttachButtonProps = Partial<AttachButtonPropsWithContext>;
132134
* UI Component for attach button in MessageInput component.
133135
*/
134136
export const AttachButton = (props: AttachButtonProps) => {
135-
const { selectedPicker } = useAttachmentPickerContext();
137+
const { disableAttachmentPicker, selectedPicker } = useAttachmentPickerContext();
136138
const { handleAttachButtonPress, toggleAttachmentPicker } = useMessageInputContext();
137139

138140
return (
139141
<MemoizedAttachButton
140-
{...{ handleAttachButtonPress, selectedPicker, toggleAttachmentPicker }}
142+
{...{
143+
disableAttachmentPicker,
144+
handleAttachButtonPress,
145+
selectedPicker,
146+
toggleAttachmentPicker,
147+
}}
141148
{...props}
142149
/>
143150
);

package/src/components/MessageInput/MessageInput.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ import {
6262
} from '../../contexts/translationContext/TranslationContext';
6363

6464
import { useStateStore } from '../../hooks/useStateStore';
65-
import {
66-
isAudioRecorderAvailable,
67-
isImageMediaLibraryAvailable,
68-
NativeHandlers,
69-
} from '../../native';
65+
import { isAudioRecorderAvailable, NativeHandlers } from '../../native';
7066
import { AIStates, useAIState } from '../AITypingIndicatorView';
7167
import { AutoCompleteInput } from '../AutoCompleteInput/AutoCompleteInput';
7268
import { CreatePoll } from '../Poll/CreatePollContent';
@@ -112,7 +108,7 @@ const styles = StyleSheet.create({
112108

113109
type MessageInputPropsWithContext = Pick<
114110
AttachmentPickerContextValue,
115-
'bottomInset' | 'selectedPicker'
111+
'bottomInset' | 'disableAttachmentPicker' | 'selectedPicker'
116112
> &
117113
Pick<ChatContextValue, 'isOnline'> &
118114
Pick<ChannelContextValue, 'channel' | 'members' | 'threadList' | 'watchers'> &
@@ -207,6 +203,7 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
207203
cooldownEndsAt,
208204
CooldownTimer,
209205
CreatePollContent,
206+
disableAttachmentPicker,
210207
editing,
211208
Input,
212209
inputBoxRef,
@@ -564,7 +561,7 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
564561
<View style={[styles.suggestionsListContainer, { bottom: height }, suggestionListContainer]}>
565562
<AutoCompleteSuggestionList />
566563
</View>
567-
{isImageMediaLibraryAvailable() && selectedPicker ? (
564+
{!disableAttachmentPicker && selectedPicker ? (
568565
<View
569566
style={[
570567
{
@@ -784,7 +781,8 @@ export const MessageInput = (props: MessageInputProps) => {
784781
uploadNewFile,
785782
VideoRecorderSelectorIcon,
786783
} = useMessageInputContext();
787-
const { bottomInset, bottomSheetRef, selectedPicker } = useAttachmentPickerContext();
784+
const { bottomInset, bottomSheetRef, disableAttachmentPicker, selectedPicker } =
785+
useAttachmentPickerContext();
788786
const messageComposer = useMessageComposer();
789787
const editing = !!messageComposer.editedMessage;
790788
const { clearEditingState } = useMessageComposerAPIContext();
@@ -835,6 +833,7 @@ export const MessageInput = (props: MessageInputProps) => {
835833
CooldownTimer,
836834
CreatePollContent,
837835
CreatePollIcon,
836+
disableAttachmentPicker,
838837
editing,
839838
FileSelectorIcon,
840839
ImageSelectorIcon,

package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type AttachmentPickerContextValue = {
2929
topInset: number;
3030

3131
selectedPicker?: 'images';
32+
disableAttachmentPicker?: boolean;
3233
};
3334

3435
export const AttachmentPickerContext = React.createContext(

0 commit comments

Comments
 (0)