Skip to content

Commit 110c677

Browse files
committed
feat: optionally override TextInput inside AutoCompleteInput completely using props
1 parent 8a69a74 commit 110c677

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

package/src/components/AutoCompleteInput/AutoCompleteInput.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React, { useCallback, useEffect, useMemo, useState } from 'react';
22
import {
33
I18nManager,
4-
NativeSyntheticEvent,
4+
TextInput as RNTextInput,
55
StyleSheet,
6-
TextInput,
7-
TextInputContentSizeChangeEventData,
6+
TextInputContentSizeChangeEvent,
87
TextInputProps,
9-
TextInputSelectionChangeEventData,
8+
TextInputSelectionChangeEvent,
109
} from 'react-native';
1110

1211
import { MessageComposerConfig, TextComposerState } from 'stream-chat';
@@ -37,6 +36,7 @@ type AutoCompleteInputPropsWithContext = TextInputProps &
3736
* that would happen if we put this in the MessageInputContext
3837
*/
3938
cooldownActive?: boolean;
39+
TextInputComponent?: React.ComponentType<TextInputProps>;
4040
};
4141

4242
type AutoCompleteInputProps = Partial<AutoCompleteInputPropsWithContext>;
@@ -53,7 +53,7 @@ const configStateSelector = (state: MessageComposerConfig) => ({
5353
const MAX_NUMBER_OF_LINES = 5;
5454

5555
const AutoCompleteInputWithContext = (props: AutoCompleteInputPropsWithContext) => {
56-
const { channel, cooldownActive = false, setInputBoxRef, t, ...rest } = props;
56+
const { channel, cooldownActive = false, setInputBoxRef, t, TextInputComponent, ...rest } = props;
5757
const [localText, setLocalText] = useState('');
5858
const [textHeight, setTextHeight] = useState(0);
5959
const messageComposer = useMessageComposer();
@@ -74,7 +74,7 @@ const AutoCompleteInputWithContext = (props: AutoCompleteInputPropsWithContext)
7474
}, [text]);
7575

7676
const handleSelectionChange = useCallback(
77-
(e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
77+
(e: TextInputSelectionChangeEvent) => {
7878
const { selection } = e.nativeEvent;
7979
textComposer.setSelection(selection);
8080
},
@@ -108,16 +108,18 @@ const AutoCompleteInputWithContext = (props: AutoCompleteInputPropsWithContext)
108108
}, [command, cooldownActive, t]);
109109

110110
const handleContentSizeChange = useCallback(
111-
({
112-
nativeEvent: { contentSize },
113-
}: NativeSyntheticEvent<TextInputContentSizeChangeEventData>) => {
111+
({ nativeEvent: { contentSize } }: TextInputContentSizeChangeEvent) => {
114112
setTextHeight(contentSize.height);
115113
},
116114
[],
117115
);
118116

117+
if (TextInputComponent) {
118+
return <TextInputComponent {...rest} />;
119+
}
120+
119121
return (
120-
<TextInput
122+
<RNTextInput
121123
autoFocus={!!command}
122124
editable={enabled}
123125
maxLength={maxMessageLength}

package/src/components/MessageInput/MessageInput.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useEffect, useMemo, useState } from 'react';
2-
import { Modal, SafeAreaView, StyleSheet, View } from 'react-native';
2+
import { Modal, SafeAreaView, StyleSheet, TextInputProps, View } from 'react-native';
33

44
import {
55
Gesture,
@@ -151,7 +151,10 @@ type MessageInputPropsWithContext = Pick<
151151
> &
152152
Pick<MessagesContextValue, 'Reply'> &
153153
Pick<TranslationContextValue, 't'> &
154-
Pick<MessageComposerAPIContextValue, 'clearEditingState'> & { editing: boolean };
154+
Pick<MessageComposerAPIContextValue, 'clearEditingState'> & {
155+
editing: boolean;
156+
TextInputComponent?: React.ComponentType<TextInputProps>;
157+
};
155158

156159
const textComposerStateSelector = (state: TextComposerState) => ({
157160
command: state.command,
@@ -207,6 +210,7 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
207210
ShowThreadMessageInChannelButton,
208211
StartAudioRecordingButton,
209212
StopMessageStreamingButton,
213+
TextInputComponent,
210214
watchers,
211215
} = props;
212216

@@ -504,6 +508,7 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
504508
<View style={[styles.autoCompleteInputContainer, autoCompleteInputContainer]}>
505509
<AutoCompleteInput
506510
cooldownActive={!!cooldownRemainingSeconds}
511+
TextInputComponent={TextInputComponent}
507512
{...additionalTextInputProps}
508513
/>
509514
</View>

0 commit comments

Comments
 (0)