Skip to content

Commit 6a287f9

Browse files
committed
Merge branch 'attachment-manager-integration' of github.com:GetStream/stream-chat-react-native into draft-message
2 parents ace7679 + fc00aa4 commit 6a287f9

File tree

8 files changed

+68
-64
lines changed

8 files changed

+68
-64
lines changed

examples/SampleApp/src/screens/ChannelScreen.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ import {
1414
useTypingString,
1515
AITypingIndicatorView,
1616
} from 'stream-chat-react-native';
17-
import { Platform, StyleSheet, View } from 'react-native';
17+
import { Platform, Pressable, StyleSheet, View } from 'react-native';
1818
import type { StackNavigationProp } from '@react-navigation/stack';
1919
import { useSafeAreaInsets } from 'react-native-safe-area-context';
2020

2121
import { useAppContext } from '../context/AppContext';
2222
import { ScreenHeader } from '../components/ScreenHeader';
23-
import { TouchableOpacity } from 'react-native-gesture-handler';
2423
import { useChannelMembersStatus } from '../hooks/useChannelMembersStatus';
2524

2625
import type { StackNavigatorParamList } from '../types';
@@ -49,44 +48,51 @@ const ChannelHeader: React.FC<ChannelHeaderProps> = ({ channel }) => {
4948
const navigation = useNavigation<ChannelScreenNavigationProp>();
5049
const typing = useTypingString();
5150

52-
if (!channel || !chatClient) {
53-
return null;
54-
}
55-
5651
const isOneOnOneConversation =
5752
channel &&
5853
Object.values(channel.state.members).length === 2 &&
5954
channel.id?.indexOf('!members-') === 0;
6055

56+
const onBackPress = useCallback(() => {
57+
if (!navigation.canGoBack()) {
58+
// if no previous screen was present in history, go to the list screen
59+
// this can happen when opened through push notification
60+
navigation.reset({ index: 0, routes: [{ name: 'MessagingScreen' }] });
61+
} else {
62+
navigation.goBack();
63+
}
64+
}, [navigation]);
65+
66+
const onRightContentPress = useCallback(() => {
67+
closePicker();
68+
if (isOneOnOneConversation) {
69+
navigation.navigate('OneOnOneChannelDetailScreen', {
70+
channel,
71+
});
72+
} else {
73+
navigation.navigate('GroupChannelDetailsScreen', {
74+
channel,
75+
});
76+
}
77+
}, [channel, closePicker, isOneOnOneConversation, navigation]);
78+
79+
if (!channel || !chatClient) {
80+
return null;
81+
}
82+
6183
return (
6284
<ScreenHeader
63-
onBack={() => {
64-
if (!navigation.canGoBack()) {
65-
// if no previous screen was present in history, go to the list screen
66-
// this can happen when opened through push notification
67-
navigation.reset({ index: 0, routes: [{ name: 'MessagingScreen' }] });
68-
} else {
69-
navigation.goBack();
70-
}
71-
}}
85+
onBack={onBackPress}
7286
// eslint-disable-next-line react/no-unstable-nested-components
7387
RightContent={() => (
74-
<TouchableOpacity
75-
onPress={() => {
76-
closePicker();
77-
if (isOneOnOneConversation) {
78-
navigation.navigate('OneOnOneChannelDetailScreen', {
79-
channel,
80-
});
81-
} else {
82-
navigation.navigate('GroupChannelDetailsScreen', {
83-
channel,
84-
});
85-
}
86-
}}
88+
<Pressable
89+
onPress={onRightContentPress}
90+
style={({ pressed }) => ({
91+
opacity: pressed ? 0.5 : 1,
92+
})}
8793
>
8894
<ChannelAvatar channel={channel} />
89-
</TouchableOpacity>
95+
</Pressable>
9096
)}
9197
showUnreadCountBadge
9298
Subtitle={isOnline ? undefined : NetworkDownIndicator}

package/src/components/Channel/Channel.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
279279
| 'EmptyStateIndicator'
280280
| 'enableMessageGroupingByUser'
281281
| 'enforceUniqueReaction'
282-
| 'isCommandUIEnabled'
283282
| 'hideStickyDateHeader'
284283
| 'hideDateSeparators'
285284
| 'LoadingIndicator'
@@ -1694,7 +1693,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
16941693
hideStickyDateHeader,
16951694
highlightedMessageId,
16961695
isChannelActive: shouldSyncChannel,
1697-
isCommandUIEnabled: isCommandUIEnabled ?? !!clientChannelConfig?.commands?.length,
16981696
lastRead,
16991697
loadChannelAroundMessage,
17001698
loadChannelAtFirstUnreadMessage,
@@ -1769,7 +1767,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
17691767
FileUploadPreview,
17701768
handleAttachButtonPress,
17711769
hasCameraPicker,
1772-
hasCommands: hasCommands ?? (getChannelConfigSafely()?.commands ?? []).length > 0,
1770+
hasCommands: hasCommands ?? !!clientChannelConfig?.commands?.length,
17731771
hasFilePicker,
17741772
hasImagePicker,
17751773
ImageAttachmentUploadPreview,
@@ -1779,7 +1777,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
17791777
InputButtons,
17801778
InputEditingStateHeader,
17811779
InputReplyStateHeader,
1782-
isCommandUIEnabled,
1780+
isCommandUIEnabled: isCommandUIEnabled ?? !!clientChannelConfig?.commands?.length,
17831781
MoreOptionsButton,
17841782
openPollCreationDialog,
17851783
SendButton,

package/src/components/Channel/hooks/useCreateChannelContext.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const useCreateChannelContext = ({
1010
enableMessageGroupingByUser,
1111
enforceUniqueReaction,
1212
error,
13-
isCommandUIEnabled,
1413
hideDateSeparators,
1514
hideStickyDateHeader,
1615
highlightedMessageId,
@@ -59,7 +58,6 @@ export const useCreateChannelContext = ({
5958
hideStickyDateHeader,
6059
highlightedMessageId,
6160
isChannelActive,
62-
isCommandUIEnabled,
6361
lastRead,
6462
loadChannelAroundMessage,
6563
loadChannelAtFirstUnreadMessage,

package/src/components/MessageInput/InputButtons.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type InputButtonsWithContextProps = Pick<
3636

3737
const textComposerStateSelector = (state: TextComposerState) => ({
3838
command: state.command,
39-
text: state.text,
39+
hasText: !!state.text,
4040
});
4141

4242
export const InputButtonsWithContext = (props: InputButtonsWithContextProps) => {
@@ -51,12 +51,11 @@ export const InputButtonsWithContext = (props: InputButtonsWithContextProps) =>
5151
uploadFile: ownCapabilitiesUploadFile,
5252
} = props;
5353
const { textComposer } = useMessageComposer();
54-
const { command, text } = useStateStore(textComposer.state, textComposerStateSelector);
54+
const { command, hasText } = useStateStore(textComposer.state, textComposerStateSelector);
5555

5656
const [showMoreOptions, setShowMoreOptions] = useState(true);
5757
const { attachments } = useAttachmentManagerState();
5858

59-
const hasText = !!text;
6059
const shouldShowMoreOptions = hasText || !!attachments.length;
6160

6261
useEffect(() => {

package/src/components/MessageInput/components/CommandInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export type CommandInputProps = Partial<
2323
};
2424
const textComposerStateSelector = (state: TextComposerState) => ({
2525
command: state.command,
26-
text: state.text,
2726
});
2827

2928
export const CommandInput = ({

package/src/contexts/channelContext/ChannelContext.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ export type ChannelContextValue = {
4949
*/
5050
enforceUniqueReaction: boolean;
5151
error: boolean | Error;
52-
/**
53-
* When set to false, it will disable giphy command on MessageInput component.
54-
*/
55-
isCommandUIEnabled: boolean;
5652
/**
5753
* Hide inline date separators on channel
5854
*/

package/src/contexts/messageInputContext/MessageInputContext.tsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ import { Alert, Keyboard, Linking, TextInput, TextInputProps } from 'react-nativ
1111

1212
import { BottomSheetHandleProps } from '@gorhom/bottom-sheet';
1313
import {
14-
createCommandInjectionMiddleware,
15-
createCommandStringExtractionMiddleware,
16-
createDraftCommandInjectionMiddleware,
1714
LocalMessage,
1815
Message,
1916
SendMessageOptions,
2017
StreamChat,
2118
Message as StreamMessage,
22-
TextComposerMiddleware,
2319
UpdateMessageOptions,
2420
UploadRequestFn,
2521
UserResponse,
@@ -67,6 +63,7 @@ import {
6763
import { isDocumentPickerAvailable, MediaTypes, NativeHandlers } from '../../native';
6864
import { File } from '../../types/types';
6965
import { compressedImageURI } from '../../utils/compressImage';
66+
import { setupCommandUIMiddleware } from '../../utils/setupCommandUIMiddleware';
7067
import {
7168
AttachmentPickerIconProps,
7269
useAttachmentPickerContext,
@@ -428,7 +425,7 @@ export const MessageInputProvider = ({
428425
useAttachmentPickerContext();
429426
const { client, enableOfflineSupport } = useChatContext();
430427

431-
const { isCommandUIEnabled, uploadAbortControllerRef } = useChannelContext();
428+
const { uploadAbortControllerRef } = useChannelContext();
432429
const { clearEditingState } = useMessageComposerAPIContext();
433430
const { thread } = useThreadContext();
434431
const { t } = useTranslationContext();
@@ -462,21 +459,8 @@ export const MessageInputProvider = ({
462459
attachmentManager.setCustomUploadFn(value.doFileUploadRequest);
463460
}
464461

465-
if (isCommandUIEnabled) {
466-
messageComposer.compositionMiddlewareExecutor.insert({
467-
middleware: [createCommandInjectionMiddleware(messageComposer)],
468-
position: { after: 'stream-io/message-composer-middleware/attachments' },
469-
});
470-
471-
messageComposer.draftCompositionMiddlewareExecutor.insert({
472-
middleware: [createDraftCommandInjectionMiddleware(messageComposer)],
473-
position: { after: 'stream-io/message-composer-middleware/draft-attachments' },
474-
});
475-
476-
messageComposer.textComposer.middlewareExecutor.insert({
477-
middleware: [createCommandStringExtractionMiddleware() as TextComposerMiddleware],
478-
position: { after: 'stream-io/text-composer/commands-middleware' },
479-
});
462+
if (value.isCommandUIEnabled) {
463+
setupCommandUIMiddleware(messageComposer);
480464
}
481465

482466
if (enableOfflineSupport) {
@@ -490,7 +474,7 @@ export const MessageInputProvider = ({
490474
}
491475
}, [
492476
value.doFileUploadRequest,
493-
isCommandUIEnabled,
477+
value.isCommandUIEnabled,
494478
enableOfflineSupport,
495479
messageComposer,
496480
attachmentManager,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
createCommandInjectionMiddleware,
3+
createCommandStringExtractionMiddleware,
4+
createDraftCommandInjectionMiddleware,
5+
MessageComposer,
6+
TextComposerMiddleware,
7+
} from 'stream-chat';
8+
9+
export const setupCommandUIMiddleware = (messageComposer: MessageComposer) => {
10+
messageComposer.compositionMiddlewareExecutor.insert({
11+
middleware: [createCommandInjectionMiddleware(messageComposer)],
12+
position: { after: 'stream-io/message-composer-middleware/attachments' },
13+
});
14+
15+
messageComposer.draftCompositionMiddlewareExecutor.insert({
16+
middleware: [createDraftCommandInjectionMiddleware(messageComposer)],
17+
position: { after: 'stream-io/message-composer-middleware/draft-attachments' },
18+
});
19+
20+
messageComposer.textComposer.middlewareExecutor.insert({
21+
middleware: [createCommandStringExtractionMiddleware() as TextComposerMiddleware],
22+
position: { after: 'stream-io/text-composer/commands-middleware' },
23+
});
24+
};

0 commit comments

Comments
 (0)