Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

T3ComposerEditor.tsx

65 lines1.9 KB

1import { TextInputWrapper } from "expo-paste-input";
2import { useImperativeHandle, useRef } from "react";
3import { TextInput, type TextInput as RNTextInput } from "react-native";
4​
5import { MOBILE_TYPOGRAPHY } from "../lib/typography";
6import { useThemeColor } from "../lib/useThemeColor";
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 ...props
19}: ComposerEditorProps) {
20 const inputRef = useRef<RNTextInput>(null);
21 const foregroundColor = useThemeColor("--color-foreground");
22 const placeholderColor = useThemeColor("--color-placeholder");
23 const handlePaste = useNativePaste((uris) => onPasteImages?.(uris));
24​
25 useImperativeHandle(
26 ref,
27 () => ({
28 focus: () => inputRef.current?.focus(),
29 blur: () => inputRef.current?.blur(),
30 setSelection: (nextSelection) =>
31 inputRef.current?.setSelection(nextSelection.start, nextSelection.end),
32 }),
33 [],
34 );
35​
36 return (
37 <TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}>
38 <TextInput
39 ref={inputRef}
40 {...props}
41 selection={selection}
42 onSelectionChange={(event) => props.onSelectionChange?.(event.nativeEvent.selection)}
43 multiline={props.multiline ?? true}
44 placeholderTextColor={placeholderColor}
45 style={[
46 {
47 flex: 1,
48 minHeight: 0,
49 color: foregroundColor,
50 fontFamily: "DMSans_400Regular",
51 ...MOBILE_TYPOGRAPHY.composer,
52 paddingVertical: contentInsetVertical,
53 },
54 textStyle,
55 ]}
56 />
57 </TextInputWrapper>
58 );
60​
61export type {
62 ComposerEditorHandle,
63 ComposerEditorProps,
64 ComposerEditorSelection,
65} from "./T3ComposerEditor.types";