Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AndroidHomeFab.tsx

51 lines1.4 KB

1import type { ReactNode } from "react";
2import { Platform, Pressable, View } from "react-native";
3import { useSafeAreaInsets } from "react-native-safe-area-context";
4​
5import { SymbolView } from "../../components/AppSymbol";
6import { useThemeColor } from "../../lib/useThemeColor";
7​
8/**
9 * Android-only wrapper that overlays a bottom-right new-task FAB on the home
10 * screen. Other platforms render children unchanged.
11 */
12export function AndroidHomeFabLayout(props: {
13 readonly onStartNewTask: () => void;
14 readonly children: ReactNode;
15}) {
16 if (Platform.OS !== "android") {
17 return <>{props.children}</>;
18 }
19​
20 return <AndroidHomeFab {...props} />;
22​
23function AndroidHomeFab(props: {
24 readonly onStartNewTask: () => void;
25 readonly children: ReactNode;
26}) {
27 const insets = useSafeAreaInsets();
28 const primaryForegroundColor = useThemeColor("--color-primary-foreground");
29​
30 return (
31 <View className="flex-1">
32 {props.children}
33 <Pressable
34 accessibilityLabel="New task"
35 accessibilityRole="button"
36 onPress={props.onStartNewTask}
37 className="absolute right-5 size-14 items-center justify-center rounded-full bg-primary shadow-lg"
38 style={{
39 bottom: Math.max(insets.bottom, 16) + 16,
40 }}
41 >
42 <SymbolView
43 name="square.and.pencil"
44 size={22}
45 tintColor={primaryForegroundColor}
46 type="monochrome"
47 />
48 </Pressable>
49 </View>
50 );