Skip to content

Commit a48311b

Browse files
committed
Make Chat Kit text input controlled on fabric so it grows in height
1 parent f9f3863 commit a48311b

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

  • FabricExample/src/screens/Examples/KeyboardChatScrollView

FabricExample/src/screens/Examples/KeyboardChatScrollView/index.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ function KeyboardChatScrollViewPlayground() {
4747
const flashRef = useRef<FlashListRef<MessageProps>>(null);
4848
const flatRef = useRef<FlatList<MessageProps>>(null);
4949
const scrollRef = useRef<VirtualizedListScrollViewRef>(null);
50-
const textInputRef = useRef<TextInput>(null);
51-
const textRef = useRef("");
50+
const [text, setText] = useState("");
5251
const [inputHeight, setInputHeight] = useState(TEXT_INPUT_HEIGHT);
5352
const extraContentPadding = useSharedValue(0);
5453
const { inverted, messages, reversedMessages, addMessage, mode } =
@@ -70,20 +69,19 @@ function KeyboardChatScrollViewPlayground() {
7069
},
7170
[extraContentPadding],
7271
);
73-
const onInput = useCallback((text: string) => {
74-
textRef.current = text;
72+
const onInput = useCallback((value: string) => {
73+
setText(value);
7574
}, []);
7675
const onSend = useCallback(() => {
77-
const message = textRef.current.trim();
76+
const message = text.trim();
7877

7978
if (message === "") {
8079
return;
8180
}
8281

8382
addMessage({ text: message, sender: true });
84-
textInputRef.current?.clear();
85-
textRef.current = "";
86-
}, [addMessage]);
83+
setText("");
84+
}, [addMessage, text]);
8785

8886
useEffect(() => {
8987
legendRef.current?.scrollToOffset({
@@ -177,11 +175,11 @@ function KeyboardChatScrollViewPlayground() {
177175
/>
178176
</View>
179177
<TextInput
180-
ref={textInputRef}
181178
multiline
182179
nativeID="chat-input"
183180
style={styles.input}
184181
testID="chat.input"
182+
value={text}
185183
onChangeText={onInput}
186184
onLayout={onInputLayoutChanged}
187185
/>

0 commit comments

Comments
 (0)