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 height,
7 onSizeChanged,
8 size,
9} from "@expo/ui/jetpack-compose/modifiers";
10import { useState } from "react";
11import { I18nManager, Pressable, View, type StyleProp, type ViewStyle } from "react-native";
12import { useAndroidControlSizing } from "./ui/useAndroidControlSizing";
13import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
14import { resolveScaledTextRole } from "../lib/appearancePreferences";
15
16/** Keep the animated width and icon positioning entirely inside Compose, not Yoga. */
17export function ScrollComposeButton(props: {
18 readonly expanded: boolean;
19 readonly onPress: () => void;
20 readonly className?: string;
21 readonly style?: StyleProp<ViewStyle>;
22}) {
23 const { appearance, themeVariables: colors } = useAppearancePreferences();
24 const typography = resolveScaledTextRole("footnote", appearance.baseFontSize);
25 const { iconSize, fabSize } = useAndroidControlSizing();
26 const nativeSize = Math.max(56, fabSize);
27 const scale = fabSize / nativeSize;
28 const nativeIconSize = Math.round(iconSize / scale);
29 const [buttonWidth, setButtonWidth] = useState(nativeSize);
30 const rememberWidth = ({ width }: { width: number }) => {
31 setButtonWidth((previous) => Math.max(previous, width));
32 };
33 return (
34 <View
35 pointerEvents="box-none"
36 className={props.className}
37 style={[props.style, { left: 20, height: fabSize }]}
38 >
39 <View
40 pointerEvents="none"
41 importantForAccessibility="no-hide-descendants"
42 style={{
43 transform: [{ scale }],
44 transformOrigin: I18nManager.isRTL ? "top left" : "top right",
45 }}
46 >
47 <NativeThemeHost
48 matchContents={{ vertical: true }}
49 ignoreSafeAreaKeyboardInsets
50 style={{ width: "100%" }}
51 >
52 <Box modifiers={[fillMaxWidth()]} contentAlignment="centerEnd">
53 <ExtendedFloatingActionButton
54 expanded={props.expanded}
55 containerColor={colors["--color-primary"]}
56 modifiers={[
57 defaultMinSize({ minWidth: nativeSize }),
58 height(nativeSize),
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}