Skip to content

Commit 746ee6c

Browse files
committed
fix: message input resizing
1 parent aa3c6d1 commit 746ee6c

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

package/src/components/AutoCompleteInput/AutoCompleteInput.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
TextInputSelectionChangeEvent,
88
} from 'react-native';
99

10+
import Animated, { LinearTransition } from 'react-native-reanimated';
11+
1012
import { MessageComposerConfig, TextComposerState } from 'stream-chat';
1113

1214
import {
@@ -27,6 +29,21 @@ import {
2729
import { useStateStore } from '../../hooks/useStateStore';
2830
import { useCooldownRemaining } from '../MessageInput/hooks/useCooldownRemaining';
2931

32+
export type TextInputOverrideComponent =
33+
| typeof RNTextInput
34+
| React.ComponentClass<TextInputProps>
35+
| React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<RNTextInput>>;
36+
37+
type AnimatedTextInputRendererProps = TextInputProps & {
38+
TextInputComponent: TextInputOverrideComponent;
39+
};
40+
41+
const TextInputRenderer = React.forwardRef<RNTextInput, AnimatedTextInputRendererProps>(
42+
({ TextInputComponent: Component, ...props }, ref) => <Component {...props} ref={ref} />,
43+
);
44+
45+
const AnimatedTextInputRenderer = Animated.createAnimatedComponent(TextInputRenderer);
46+
3047
type AutoCompleteInputPropsWithContext = TextInputProps &
3148
Pick<ChannelContextValue, 'channel'> &
3249
Pick<MessageInputContextValue, 'setInputBoxRef'> &
@@ -36,11 +53,7 @@ type AutoCompleteInputPropsWithContext = TextInputProps &
3653
* that would happen if we put this in the MessageInputContext
3754
*/
3855
cooldownRemainingSeconds?: number;
39-
TextInputComponent?: React.ComponentType<
40-
TextInputProps & {
41-
ref: React.Ref<RNTextInput> | undefined;
42-
}
43-
>;
56+
TextInputComponent?: TextInputOverrideComponent;
4457
};
4558

4659
type AutoCompleteInputProps = Partial<AutoCompleteInputPropsWithContext>;
@@ -136,7 +149,9 @@ const AutoCompleteInputWithContext = (props: AutoCompleteInputPropsWithContext)
136149
}, [command, cooldownRemainingSeconds, t, placeholder]);
137150

138151
return (
139-
<TextInputComponent
152+
<AnimatedTextInputRenderer
153+
TextInputComponent={TextInputComponent}
154+
layout={LinearTransition.duration(200)}
140155
autoFocus={!!command}
141156
editable={enabled}
142157
maxLength={maxMessageLength}

package/src/components/MessageInput/MessageInput.tsx

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

44
import { GestureHandlerRootView } from 'react-native-gesture-handler';
55
import Animated, {
@@ -54,7 +54,10 @@ import { useStateStore } from '../../hooks/useStateStore';
5454
import { AudioRecorderManagerState } from '../../state-store/audio-recorder-manager';
5555
import { MessageInputHeightState } from '../../state-store/message-input-height-store';
5656
import { primitives } from '../../theme';
57-
import { AutoCompleteInput } from '../AutoCompleteInput/AutoCompleteInput';
57+
import {
58+
AutoCompleteInput,
59+
type TextInputOverrideComponent,
60+
} from '../AutoCompleteInput/AutoCompleteInput';
5861
import { CreatePoll } from '../Poll/CreatePollContent';
5962
import { PortalWhileClosingView } from '../UIComponents/PortalWhileClosingView';
6063
import { SafeAreaViewWrapper } from '../UIComponents/SafeAreaViewWrapper';
@@ -196,11 +199,7 @@ type MessageInputPropsWithContext = Pick<ChatContextValue, 'isOnline'> &
196199
Pick<AudioRecorderManagerState, 'micLocked'> & {
197200
editing: boolean;
198201
isKeyboardVisible: boolean;
199-
TextInputComponent?: React.ComponentType<
200-
TextInputProps & {
201-
ref: React.Ref<TextInput> | undefined;
202-
}
203-
>;
202+
TextInputComponent?: TextInputOverrideComponent;
204203
isRecordingStateIdle?: boolean;
205204
recordingStatus?: string;
206205
};
@@ -455,15 +454,10 @@ const MessageInputWithContext = (props: MessageInputPropsWithContext) => {
455454
<>
456455
<MessageInputLeadingView />
457456

458-
<Animated.View
459-
style={styles.autocompleteInputContainer}
460-
layout={LinearTransition.duration(200)}
461-
>
462-
<AutoCompleteInput
463-
TextInputComponent={TextInputComponent}
464-
{...additionalTextInputProps}
465-
/>
466-
</Animated.View>
457+
<AutoCompleteInput
458+
TextInputComponent={TextInputComponent}
459+
{...additionalTextInputProps}
460+
/>
467461
</>
468462
)}
469463

package/src/components/MessageInput/MessageInputLeadingView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect } from 'react';
22
import { StyleSheet } from 'react-native';
33

4-
import Animated, { ZoomIn, ZoomOut } from 'react-native-reanimated';
4+
import Animated, { LinearTransition, ZoomIn, ZoomOut } from 'react-native-reanimated';
55

66
import { textComposerStateSelector } from './utils/messageComposerSelectors';
77

@@ -25,6 +25,7 @@ export const MessageInputLeadingView = () => {
2525
<Animated.View
2626
entering={ZoomIn.duration(200)}
2727
exiting={ZoomOut.duration(200)}
28+
layout={LinearTransition.duration(200)}
2829
style={styles.giphyContainer}
2930
>
3031
<GiphyChip />
@@ -35,5 +36,6 @@ export const MessageInputLeadingView = () => {
3536
const styles = StyleSheet.create({
3637
giphyContainer: {
3738
padding: primitives.spacingXs,
39+
alignSelf: 'flex-end',
3840
},
3941
});

0 commit comments

Comments
 (0)