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