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 // Scale the native 56dp minimum; keep text and icons at their requested sizes.
28 const nativeSize = Math.max(56, fabSize);
29 const scale = fabSize / nativeSize;
30 const nativeIconSize = Math.round(iconSize / scale);
31 const [buttonWidth, setButtonWidth] = useState(nativeSize);
32 const rememberWidth = useCallback(({ width }: { width: number }) => {
33 setButtonWidth((previous) => Math.max(previous, width));
34 }, []);
35 return (
36 <View
37 pointerEvents="box-none"
38 className={props.className}
39 style={[props.style, { left: 20, height: fabSize }]}
40 >
41 <View pointerEvents="none" importantForAccessibility="no-hide-descendants">
42 <NativeThemeHost
43 matchContents={{ vertical: true }}
44 ignoreSafeAreaKeyboardInsets
45 style={{ width: "100%" }}
46 >
47 <Box modifiers={[fillMaxWidth()]} contentAlignment="centerEnd">
48 <ExtendedFloatingActionButton
49 expanded={props.expanded}
50 containerColor={colors["--color-primary"]}
51 modifiers={[
52 defaultMinSize({ minWidth: nativeSize }),
53 height(nativeSize),
54 graphicsLayer({
55 scaleX: scale,
56 scaleY: scale,
57 transformOriginX: 1,
58 transformOriginY: 0,
59 }),
60 onSizeChanged(rememberWidth),
61 ]}
62 >
63 <ExtendedFloatingActionButton.Icon>
64 <Box modifiers={[size(nativeIconSize, nativeIconSize)]}>
65 <Icon
66 source={require("../../assets/icons/compose.xml")}
67 size={nativeIconSize}
68 tint={colors["--color-primary-foreground"]}
69 />
70 </Box>
71 </ExtendedFloatingActionButton.Icon>
72 <ExtendedFloatingActionButton.Text>
73 <Text
74 color={colors["--color-primary-foreground"]}
75 style={{
76 fontSize: typography.fontSize / scale,
77 lineHeight: typography.lineHeight / scale,
78 fontWeight: "500",
79 }}
80 >
81 New thread
82 </Text>
83 </ExtendedFloatingActionButton.Text>
84 </ExtendedFloatingActionButton>
85 </Box>
86 </NativeThemeHost>
87 </View>
88 {/* The visual host is wider than the button; only this target intercepts list touches. */}
89 <Pressable
90 onPress={props.onPress}
91 accessibilityRole="button"
92 accessibilityLabel="New thread"
93 android_ripple={{ foreground: true }}
94 style={{
95 position: "absolute",
96 right: 0,
97 top: 0,
98 bottom: 0,
99 // Release the label area as soon as collapse starts, before native measurements arrive.
100 width: props.expanded ? buttonWidth * scale : fabSize,
101 borderRadius: 16 * scale,
102 overflow: "hidden",
103 }}
104 />
105 </View>
106 );
107}