Open History to see the last commit
1import * as Haptics from "expo-haptics";
2import { isLiquidGlassSupported, LiquidGlassView } from "@callstack/liquid-glass";
3import { SymbolView } from "../../components/AppSymbol";
4import { useCallback, useEffect, useRef } from "react";
5import { ActivityIndicator, Pressable, StyleSheet, useColorScheme, View } from "react-native";
6import Animated, { FadeIn, FadeOut, LinearTransition } from "react-native-reanimated";
7import { useSafeAreaInsets } from "react-native-safe-area-context";
8
9import { AppText as Text } from "../../components/AppText";
10import { APP_BAR_HEIGHT } from "../../lib/layoutMetrics";
11import { themeColorWithAlpha } from "../../lib/mobileTheme";
12import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
13import { useUniwindTheme } from "../../lib/useUniwindTheme";
14import type { GitActionProgress } from "../../state/use-vcs-action-state";
15
16const OVERLAY_LAYOUT_TRANSITION = LinearTransition.duration(220);
17const OVERLAY_TOP_GAP = 8;
18const AnimatedLiquidGlassView = Animated.createAnimatedComponent(LiquidGlassView);
19
20export function GitActionProgressOverlay(props: {
21 readonly progress: GitActionProgress;
22 readonly onDismiss: () => void;
23}) {
24 const { progress, onDismiss } = props;
25 const insets = useSafeAreaInsets();
26 const prevPhaseRef = useRef(progress.phase);
27
28 useEffect(() => {
29 const prev = prevPhaseRef.current;
30 prevPhaseRef.current = progress.phase;
31
32 if (prev === "running" && progress.phase === "success") {
33 Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
34 } else if (prev === "running" && progress.phase === "error") {
35 Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
36 }
37 }, [progress.phase]);
38
39 const handlePress = useCallback(() => {
40 if (progress.prUrl) {
41 void tryOpenExternalUrl(progress.prUrl, "pull-request");
42 return;
43 }
44 if (progress.phase === "success" || progress.phase === "error") {
45 onDismiss();
46 }
47 }, [onDismiss, progress.phase, progress.prUrl]);
48
49 if (progress.phase === "idle") {
50 return null;
51 }
52
53 return (
54 <Animated.View
55 entering={isLiquidGlassSupported ? undefined : FadeIn.duration(200)}
56 exiting={FadeOut.duration(150)}
57 className="absolute inset-x-3 z-[100]"
58 style={{ top: insets.top + APP_BAR_HEIGHT + OVERLAY_TOP_GAP }}
59 pointerEvents="box-none"
60 >
61 <Pressable onPress={handlePress}>
62 <OverlayContent progress={progress} />
63 </Pressable>
64 </Animated.View>
65 );
66}
67
68function OverlayContent(props: { readonly progress: GitActionProgress }) {
69 const { progress } = props;
70 const colors = useUniwindTheme();
71 const glassSurface = colors["--color-glass-surface"];
72 const foreground = colors["--color-foreground"];
73 const shadowColor = colors["--color-primary-shadow"];
74 const isDarkMode = useColorScheme() === "dark";
75 const glassTint = themeColorWithAlpha(String(glassSurface), isDarkMode ? 0.48 : 0.38);
76 const glassBorder = themeColorWithAlpha(String(foreground), isDarkMode ? 0.18 : 0.12);
77 const content = (
78 <>
79 <OverlayIcon phase={progress.phase} />
80
81 <View className="flex-1 gap-0.5">
82 {progress.label ? (
83 <Text className="text-sm font-t3-bold text-foreground" numberOfLines={1}>
84 {progress.label}
85 </Text>
86 ) : null}
87 {progress.description ? (
88 <Text className="text-2xs text-foreground-muted" numberOfLines={1}>
89 {progress.description}
90 </Text>
91 ) : null}
92 </View>
93
94 {progress.prUrl ? (
95 <SymbolView
96 name="arrow.up.right"
97 size={13}
98 tintColorClassName={"accent-icon"}
99 type="monochrome"
100 />
101 ) : null}
102 </>
103 );
104
105 if (isLiquidGlassSupported) {
106 return (
107 <Animated.View
108 layout={OVERLAY_LAYOUT_TRANSITION}
109 style={{
110 borderCurve: "continuous",
111 borderRadius: 26,
112 elevation: 12,
113 shadowColor,
114 shadowOffset: { width: 0, height: 8 },
115 shadowOpacity: isDarkMode ? 0.42 : 0.2,
116 shadowRadius: 18,
117 }}
118 >
119 <AnimatedLiquidGlassView
120 colorScheme={isDarkMode ? "dark" : "light"}
121 effect="regular"
122 interactive
123 layout={OVERLAY_LAYOUT_TRANSITION}
124 tintColor={glassTint}
125 style={{
126 borderColor: glassBorder,
127 borderCurve: "continuous",
128 borderRadius: 26,
129 borderWidth: StyleSheet.hairlineWidth,
130 overflow: "hidden",
131 }}
132 >
133 <Animated.View
134 entering={FadeIn.delay(60).duration(140)}
135 className="flex-row items-center gap-2.5 px-3.5 py-3"
136 >
137 {content}
138 </Animated.View>
139 </AnimatedLiquidGlassView>
140 </Animated.View>
141 );
142 }
143
144 const bgClass =
145 progress.phase === "error"
146 ? "border-adaptive-red-200-800 bg-adaptive-red-50-950-a80"
147 : "bg-card border-border";
148
149 return (
150 <Animated.View
151 layout={OVERLAY_LAYOUT_TRANSITION}
152 className={`flex-row items-center gap-2.5 rounded-[26px] border border-continuous px-3.5 py-3 shadow-lg shadow-black/10 ${bgClass}`}
153 >
154 {content}
155 </Animated.View>
156 );
157}
158
159function OverlayIcon(props: { readonly phase: GitActionProgress["phase"] }) {
160 switch (props.phase) {
161 case "running":
162 return <ActivityIndicator size="small" colorClassName={"accent-icon"} />;
163 case "success":
164 return (
165 <View className="h-6 w-6 items-center justify-center rounded-full bg-green-500">
166 <SymbolView name="checkmark" size={12} tintColor="white" type="monochrome" />
167 </View>
168 );
169 case "error":
170 return (
171 <View className="h-6 w-6 items-center justify-center rounded-full bg-red-500">
172 <SymbolView
173 name="exclamationmark.triangle"
174 size={12}
175 tintColor="white"
176 type="monochrome"
177 />
178 </View>
179 );
180 default:
181 return null;
182 }
183}