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 { useThemeColor } from "../lib/useThemeColor";
6import { useFontFamily } from "../lib/useFontFamily";
7import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
8import { useNativePaste } from "../lib/useNativePaste";
9import type { ComposerEditorProps } from "./T3ComposerEditor.types";
10
11export function ComposerEditor({
12 ref,
13 skills: _skills,
14 selection,
15 onPasteImages,
16 style,
17 textStyle,
18 contentInsetVertical = 0,
19 singleLineCentered: _singleLineCentered,
20 ...props
21}: ComposerEditorProps) {
22 const inputRef = useRef<RNTextInput>(null);
23 const bodyText = useScaledTextRole("body");
24 const foregroundColor = useThemeColor("--color-foreground");
25 const placeholderColor = useThemeColor("--color-placeholder");
26 const fontFamily = useFontFamily("regular");
27 const handlePaste = useNativePaste((uris) => onPasteImages?.(uris));
28
29 useImperativeHandle(
30 ref,
31 () => ({
32 focus: () => inputRef.current?.focus(),
33 blur: () => inputRef.current?.blur(),
34 setSelection: (nextSelection) =>
35 inputRef.current?.setSelection(nextSelection.start, nextSelection.end),
36 }),
37 [],
38 );
39
40 return (
41 <TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}>
42 <TextInput
43 ref={inputRef}
44 {...props}
45 selection={selection}
46 onSelectionChange={(event) => props.onSelectionChange?.(event.nativeEvent.selection)}
47 multiline={props.multiline ?? true}
48 placeholderTextColor={placeholderColor}
49 style={[
50 {
51 flex: 1,
52 minHeight: 0,
53 color: foregroundColor,
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} from "./T3ComposerEditor.types";