Skip to content

Commit d65e06e

Browse files
committed
fix(mobile): animate Android undo notice entry and exit
1 parent 71960d1 commit d65e06e

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
import { useLayoutEffect, useState } from "react";
2-
import { View } from "react-native";
32
import { GestureDetector, usePanGesture } from "react-native-gesture-handler";
43
import Animated, {
54
cancelAnimation,
5+
Easing,
6+
FadeOut,
67
ReduceMotion,
78
runOnJS,
89
useAnimatedStyle,
910
useSharedValue,
1011
withTiming,
12+
type EntryAnimationsValues,
1113
} from "react-native-reanimated";
1214
import { useSafeAreaInsets } from "react-native-safe-area-context";
1315
import { Toast } from "../../components/ui/Toast";
16+
import { MOBILE_MOTION } from "../../lib/designTokens";
1417
import {
1518
dismissThreadUndoNotice,
1619
readThreadUndoNotice,
1720
useThreadUndoNotice,
1821
} from "./thread-undo-notice";
1922

2023
const SWIPE_TIMING = { duration: 160, reduceMotion: ReduceMotion.System };
24+
const ENTER_TIMING = {
25+
duration: MOBILE_MOTION.enter,
26+
easing: Easing.out(Easing.cubic),
27+
reduceMotion: ReduceMotion.System,
28+
};
29+
const NOTICE_EXITING = FadeOut.duration(MOBILE_MOTION.exit).reduceMotion(ReduceMotion.System);
30+
const noticeEntering = (values: EntryAnimationsValues) => {
31+
"worklet";
32+
return {
33+
initialValues: { originY: values.targetOriginY + values.targetHeight + 12 },
34+
animations: { originY: withTiming(values.targetOriginY, ENTER_TIMING) },
35+
};
36+
};
2137

2238
export function ThreadUndoNotice(props: { readonly visible: boolean }) {
2339
const notice = useThreadUndoNotice();
@@ -74,18 +90,21 @@ function SwipeableUndoNotice(props: {
7490
transform: [{ translateX: translation.value }],
7591
}));
7692

93+
// Clip the entrance above navigation; the notice intentionally covers the anchored FAB.
7794
return (
78-
<View
79-
className="absolute inset-x-3 z-[100]"
95+
<Animated.View
96+
className="absolute inset-x-3 z-[100] overflow-hidden"
8097
style={{ bottom: insets.bottom + 12 }}
8198
pointerEvents="box-none"
99+
exiting={NOTICE_EXITING}
82100
onLayout={(event) => {
83101
width.set(event.nativeEvent.layout.width);
84102
}}
85103
>
86104
<GestureDetector gesture={gesture}>
87105
<Animated.View
88106
collapsable={false}
107+
entering={noticeEntering}
89108
accessible
90109
accessibilityRole="alert"
91110
accessibilityLiveRegion="assertive"
@@ -102,6 +121,6 @@ function SwipeableUndoNotice(props: {
102121
/>
103122
</Animated.View>
104123
</GestureDetector>
105-
</View>
124+
</Animated.View>
106125
);
107126
}

0 commit comments

Comments
 (0)