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

main
tsx 109 lines 4.02 KB
Raw
1 import { NativeThemeHost } from "./ui/NativeThemeHost.android";
2 import { Box, ExtendedFloatingActionButton, Icon, Text } from "@expo/ui/jetpack-compose";
3 import {
4 defaultMinSize,
5 fillMaxWidth,
6 height,
7 onSizeChanged,
8 size,
9 } from "@expo/ui/jetpack-compose/modifiers";
10 import { useGT } from "gt-react-native";
11 import { useState } from "react";
12 import { I18nManager, Pressable, View, type StyleProp, type ViewStyle } from "react-native";
13 import { useAndroidControlSizing } from "./ui/useAndroidControlSizing";
14 import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
15 import { resolveScaledTextRole } from "../lib/appearancePreferences";
16
17 /** Keep the animated width and icon positioning entirely inside Compose, not Yoga. */
18 export function ScrollComposeButton(props: {
19 readonly expanded: boolean;
20 readonly onPress: () => void;
21 readonly size?: number;
22 readonly className?: string;
23 readonly style?: StyleProp<ViewStyle>;
24 }) {
25 const gt = useGT();
26 const { appearance, themeVariables: colors } = useAppearancePreferences();
27 const typography = resolveScaledTextRole("footnote", appearance.baseFontSize);
28 const { iconSize, fabSize: scaledFabSize } = useAndroidControlSizing();
29 const fabSize = props.size ?? scaledFabSize;
30 const nativeSize = Math.max(56, fabSize);
31 const scale = fabSize / nativeSize;
32 const nativeIconSize = Math.round(iconSize / scale);
33 const [buttonWidth, setButtonWidth] = useState(nativeSize);
34 const rememberWidth = ({ width }: { width: number }) => {
35 setButtonWidth((previous) => Math.max(previous, width));
36 };
37 return (
38 <View
39 pointerEvents="box-none"
40 className={props.className}
41 style={[props.style, { left: 20, height: fabSize }]}
42 >
43 <View
44 pointerEvents="none"
45 importantForAccessibility="no-hide-descendants"
46 style={{
47 transform: [{ scale }],
48 transformOrigin: I18nManager.isRTL ? "top left" : "top right",
49 }}
50 >
51 <NativeThemeHost
52 matchContents={{ vertical: true }}
53 ignoreSafeAreaKeyboardInsets
54 style={{ width: "100%" }}
55 >
56 <Box modifiers={[fillMaxWidth()]} contentAlignment="centerEnd">
57 <ExtendedFloatingActionButton
58 expanded={props.expanded}
59 containerColor={colors["--color-primary"]}
60 modifiers={[
61 defaultMinSize({ minWidth: nativeSize }),
62 height(nativeSize),
63 onSizeChanged(rememberWidth),
64 ]}
65 >
66 <ExtendedFloatingActionButton.Icon>
67 <Box modifiers={[size(nativeIconSize, nativeIconSize)]}>
68 <Icon
69 source={require("../../assets/icons/compose.xml")}
70 size={nativeIconSize}
71 tint={colors["--color-primary-foreground"]}
72 />
73 </Box>
74 </ExtendedFloatingActionButton.Icon>
75 <ExtendedFloatingActionButton.Text>
76 <Text
77 color={colors["--color-primary-foreground"]}
78 style={{
79 fontSize: typography.fontSize / scale,
80 lineHeight: typography.lineHeight / scale,
81 fontWeight: "500",
82 }}
83 >
84 {gt("New thread")}
85 </Text>
86 </ExtendedFloatingActionButton.Text>
87 </ExtendedFloatingActionButton>
88 </Box>
89 </NativeThemeHost>
90 </View>
91 {/* The visual host is wider than the button; only this target intercepts list touches. */}
92 <Pressable
93 onPress={props.onPress}
94 accessibilityRole="button"
95 accessibilityLabel={gt("New thread")}
96 android_ripple={{ foreground: true }}
97 style={{
98 position: "absolute",
99 right: 0,
100 top: 0,
101 bottom: 0,
102 width: props.expanded ? buttonWidth * scale : fabSize,
103 borderRadius: 16 * scale,
104 overflow: "hidden",
105 }}
106 />
107 </View>
108 );
109 }