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 readOnly = false,
20 ...props
21}: ComposerEditorProps) {
22 const inputRef = useRef<RNTextInput>(null);
23 const bodyText = useScaledTextRole("body");
24 const fontFamily = useFontFamily("regular");
25 const handlePaste = useNativePaste((uris) => onPasteImages?.(uris));
26
27 useImperativeHandle(
28 ref,
29 () => ({
30 focus: () => inputRef.current?.focus(),
31 blur: () => inputRef.current?.blur(),
32 setSelection: (nextSelection) =>
33 inputRef.current?.setSelection(nextSelection.start, nextSelection.end),
34 }),
35 [],
36 );
37
38 return (
39 <TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}>
40 <TextInput
41 ref={inputRef}
42 {...props}
43 editable={(props.editable ?? true) && !readOnly}
44 selection={selection}
45 onSelectionChange={(event) => props.onSelectionChange?.(event.nativeEvent.selection)}
46 multiline={props.multiline ?? true}
47 placeholderTextColorClassName={"accent-placeholder"}
48 className="text-foreground"
49 style={[
50 {
51 flex: 1,
52 minHeight: 0,
53 fontFamily,
54 ...bodyText,
55 paddingVertical: contentInsetVertical,
56 },
57 textStyle,
58 ]}
59 />
60 </TextInputWrapper>
61 );
62}
63
64export type {
65 ComposerEditorHandle,
66 ComposerEditorProps,
67 ComposerEditorSelection,
68} from "./T3ComposerEditor.types";