Skip to content

Commit

Permalink
fix: make the chat example better
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySerfaty committed Feb 2, 2024
1 parent 3a214e2 commit 2e9ac39
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions example/src/Examples/EditorStickToKeyboardExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ export const EditorStickToKeyboardExample = ({}: NativeStackScreenProps<
>) => {
const editor = useEditor({
plugins: [TenTapStartKit, CoreBridge],
initialContent: '<p>hehehe<u>ssss</u></p>',
initialContent: '<p>Initial lovely message...</p>',
});
const MessagesScrollViewRef = useRef<ScrollView>(null);
const TapRef = useRef(null);
const [messages, setMessages] =
React.useState<{ text: string; date: number }[]>(defaultMessages);
Expand All @@ -72,11 +73,20 @@ export const EditorStickToKeyboardExample = ({}: NativeStackScreenProps<
const content = await editor.getContent();
setMessages((prev) => [...prev, { text: content, date: Date.now() }]);
editor.setContent('');
if (MessagesScrollViewRef.current) {
setTimeout(() => {
MessagesScrollViewRef.current!.scrollToEnd({ animated: true });
}, 100);
}
};

return (
<SafeAreaView style={exampleStyles.fullScreen} ref={TapRef}>
<ScrollView>
<ScrollView
automaticallyAdjustKeyboardInsets={true}
ref={MessagesScrollViewRef}
contentContainerStyle={{ paddingBottom: 120 }}
>
{messages.map((message) => (
<View style={exampleStyles.messageBox}>
<WebView
Expand Down

0 comments on commit 2e9ac39

Please sign in to comment.