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