Skip to content

Commit 3384d2f

Browse files
committed
fix(mobile): keep Android undo notices above the FAB
1 parent f9d61c8 commit 3384d2f

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

‎apps/mobile/src/features/home/AndroidHomeFab.android.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "react-native";
88
import { useSafeAreaInsets } from "react-native-safe-area-context";
99
import { NewThreadButton } from "../../components/NewThreadButton";
10+
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
1011
import {
1112
androidHomeFabPosition,
1213
type AndroidHomeFabLayout as SharedAndroidHomeFabLayout,
@@ -15,14 +16,14 @@ import { useWorkspaceState } from "../../state/workspace";
1516
import { FabScrollContext } from "./FabScrollContext";
1617
import { updateFabScroll } from "./fab-scroll";
1718
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
18-
import { ThreadUndoNoticeHeightContext } from "./thread-undo-notice-layout";
19+
import { ThreadUndoNoticeBottomContext } from "./thread-undo-notice-layout";
1920

2021
export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidHomeFabLayout>) {
2122
const insets = useSafeAreaInsets();
2223
const { appearance } = useAppearancePreferences();
2324
const { fontScale } = useWindowDimensions();
2425
const [layoutWidth, setLayoutWidth] = useState<number | null>(null);
25-
const [undoNoticeHeight, setUndoNoticeHeight] = useState(0);
26+
const { fabSize } = useAndroidControlSizing();
2627
const { state } = useWorkspaceState();
2728
const [expanded, setExpanded] = useState(true);
2829
const scrollState = useRef({ anchor: 0, expanded: true });
@@ -36,26 +37,25 @@ export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidH
3637
if (next.expanded !== scrollState.current.expanded) setExpanded(next.expanded);
3738
scrollState.current = next;
3839
}, []);
40+
const showFab = !props.disabled && !props.sidebar && state.hasConnections && layoutWidth !== null;
41+
const fabPosition = androidHomeFabPosition(insets.bottom, props.sidebar);
3942

4043
// Remount only the FAB when its font or pane changes to clear the cached expanded width.
4144
// The split-view sidebar has no FAB: the navigation rail carries New thread. On phones it
4245
// keeps Material's 16dp corner margin; the bottom bar already consumes the gesture inset.
4346
return (
4447
<View className="flex-1" onLayout={(event) => setLayoutWidth(event.nativeEvent.layout.width)}>
45-
<ThreadUndoNoticeHeightContext value={setUndoNoticeHeight}>
48+
<ThreadUndoNoticeBottomContext value={showFab ? fabPosition.bottom + fabSize + 12 : null}>
4649
<FabScrollContext value={onScroll}>{props.children}</FabScrollContext>
47-
</ThreadUndoNoticeHeightContext>
48-
{!props.disabled && !props.sidebar && state.hasConnections && layoutWidth !== null ? (
50+
</ThreadUndoNoticeBottomContext>
51+
{showFab ? (
4952
<NewThreadButton
5053
key={`${appearance.baseFontSize}:${fontScale}:${layoutWidth}`}
5154
extended
5255
expanded={expanded}
5356
onPress={props.onStartNewTask}
5457
className="absolute"
55-
style={[
56-
androidHomeFabPosition(insets.bottom, props.sidebar),
57-
undoNoticeHeight > 0 ? { bottom: insets.bottom + undoNoticeHeight + 24 } : null,
58-
]}
58+
style={fabPosition}
5959
/>
6060
) : null}
6161
</View>

‎apps/mobile/src/features/home/ThreadUndoNotice.android.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
readThreadUndoNotice,
1717
useThreadUndoNotice,
1818
} from "./thread-undo-notice";
19-
import { ThreadUndoNoticeHeightContext } from "./thread-undo-notice-layout";
19+
import { ThreadUndoNoticeBottomContext } from "./thread-undo-notice-layout";
2020

2121
const SWIPE_TIMING = { duration: 160, reduceMotion: ReduceMotion.System };
2222

@@ -34,16 +34,15 @@ function SwipeableUndoNotice(props: {
3434
}) {
3535
const { notice } = props;
3636
const insets = useSafeAreaInsets();
37-
const setHeight = use(ThreadUndoNoticeHeightContext);
37+
const bottom = use(ThreadUndoNoticeBottomContext);
3838
const translation = useSharedValue(0);
3939
const width = useSharedValue(0);
4040

4141
useLayoutEffect(
4242
() => () => {
4343
cancelAnimation(translation);
44-
setHeight?.(0);
4544
},
46-
[setHeight, translation],
45+
[translation],
4746
);
4847

4948
const dismiss = () => {
@@ -80,16 +79,17 @@ function SwipeableUndoNotice(props: {
8079
return (
8180
<View
8281
className="absolute inset-x-3 z-[100]"
83-
style={{ bottom: insets.bottom + 12 }}
82+
style={{ bottom: bottom ?? insets.bottom + 12 }}
8483
pointerEvents="box-none"
8584
onLayout={(event) => {
8685
width.set(event.nativeEvent.layout.width);
87-
setHeight?.(event.nativeEvent.layout.height);
8886
}}
8987
>
9088
<GestureDetector gesture={gesture}>
9189
<Animated.View
9290
collapsable={false}
91+
accessible
92+
accessibilityLabel={`${notice.action} thread`}
9393
style={animatedStyle}
9494
accessibilityActions={[{ name: "dismiss", label: "Dismiss message" }]}
9595
onAccessibilityAction={({ nativeEvent }) => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { createContext } from "react";
22

3-
export const ThreadUndoNoticeHeightContext = createContext<((height: number) => void) | null>(null);
3+
export const ThreadUndoNoticeBottomContext = createContext<number | null>(null);

0 commit comments

Comments
 (0)