@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
tsx 75 lines 2.26 KB
Raw
1 import { TextInputWrapper } from "expo-paste-input";
2 import { useImperativeHandle, useRef } from "react";
3 import { TextInput, type TextInputInstance } from "react-native";
4
5 import { FONT_FAMILIES } from "../lib/fontFamilies";
6 import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
7 import { useNativePaste } from "../lib/useNativePaste";
8 import type { ComposerEditorProps } from "./T3ComposerEditor.types";
9
10 export 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 enterBehavior: _enterBehavior,
21 readResetGeneration: _readResetGeneration,
22 readOnly = false,
23 onContentSizeChange,
24 ...props
25 }: ComposerEditorProps) {
26 const inputRef = useRef<TextInputInstance>(null);
27 const bodyText = useScaledTextRole("body");
28 const fontFamily = FONT_FAMILIES.regular;
29 const handlePaste = useNativePaste((uris) => onPasteImages?.(uris));
30
31 useImperativeHandle(
32 ref,
33 () => ({
34 focus: () => inputRef.current?.focus(),
35 blur: () => inputRef.current?.blur(),
36 setSelection: (nextSelection) =>
37 inputRef.current?.setSelection(nextSelection.start, nextSelection.end),
38 flushPendingInput: async () => {},
39 }),
40 [],
41 );
42
43 return (
44 <TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}>
45 <TextInput
46 ref={inputRef}
47 {...props}
48 editable={(props.editable ?? true) && !readOnly}
49 selection={selection}
50 onSelectionChange={(event) => props.onSelectionChange?.(event.nativeEvent.selection)}
51 onContentSizeChange={(event) => onContentSizeChange?.(event.nativeEvent.contentSize)}
52 multiline={props.multiline ?? true}
53 placeholderTextColorClassName={"accent-placeholder"}
54 className="text-foreground"
55 style={[
56 {
57 flex: 1,
58 minHeight: 0,
59 fontFamily,
60 ...bodyText,
61 paddingVertical: contentInsetVertical,
62 },
63 textStyle,
64 ]}
65 />
66 </TextInputWrapper>
67 );
68 }
69
70 export type {
71 ComposerEditorHandle,
72 ComposerEditorProps,
73 ComposerEditorSelection,
74 ComposerTextPaste,
75 } from "./T3ComposerEditor.types";