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