Open History to see the last commit
1import { TextInputWrapper } from "expo-paste-input";
2import { useImperativeHandle, useRef } from "react";
3import { TextInput, type TextInput as RNTextInput } from "react-native";
4
5import { useFontFamily } from "../lib/useFontFamily";
6import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
7import { useNativePaste } from "../lib/useNativePaste";
8import type { ComposerEditorProps } from "./T3ComposerEditor.types";
9
10export function ComposerEditor({
11 ref,
12 skills: _skills,
13 selection,
14 onPasteImages,
15 style,
16 textStyle,
17 contentInsetVertical = 0,
18 singleLineCentered: _singleLineCentered,
19 ...props
20}: ComposerEditorProps) {
21 const inputRef = useRef<RNTextInput>(null);
22 const bodyText = useScaledTextRole("body");
23 const fontFamily = useFontFamily("regular");
24 const handlePaste = useNativePaste((uris) => onPasteImages?.(uris));
25
26 useImperativeHandle(
27 ref,
28 () => ({
29 focus: () => inputRef.current?.focus(),
30 blur: () => inputRef.current?.blur(),
31 setSelection: (nextSelection) =>
32 inputRef.current?.setSelection(nextSelection.start, nextSelection.end),
33 }),
34 [],
35 );
36
37 return (
38 <TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}>
39 <TextInput
40 ref={inputRef}
41 {...props}
42 selection={selection}
43 onSelectionChange={(event) => props.onSelectionChange?.(event.nativeEvent.selection)}
44 multiline={props.multiline ?? true}
45 placeholderTextColorClassName={"accent-placeholder"}
46 className="text-foreground"
47 style={[
48 {
49 flex: 1,
50 minHeight: 0,
51 fontFamily,
52 ...bodyText,
53 paddingVertical: contentInsetVertical,
54 },
55 textStyle,
56 ]}
57 />
58 </TextInputWrapper>
59 );
60}
61
62export type {
63 ComposerEditorHandle,
64 ComposerEditorProps,
65 ComposerEditorSelection,
66} from "./T3ComposerEditor.types";