@comergehq/studio 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/dist/index.d.mts +2 -10
  2. package/dist/index.d.ts +2 -10
  3. package/dist/index.js +293 -264
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +251 -222
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +8 -5
  8. package/src/components/chat/ChatComposer.tsx +277 -0
  9. package/src/components/chat/ChatHeader.tsx +31 -0
  10. package/src/components/chat/ChatMessageBubble.tsx +69 -0
  11. package/src/components/chat/ChatMessageList.tsx +137 -0
  12. package/src/components/chat/ChatPage.tsx +69 -0
  13. package/src/components/chat/ForkNoticeBanner.tsx +66 -0
  14. package/src/components/chat/MultilineTextInput.tsx +46 -0
  15. package/src/components/chat/ScrollToBottomButton.tsx +78 -0
  16. package/src/components/chat/TypingIndicator.tsx +54 -0
  17. package/src/components/chat/index.ts +28 -0
  18. package/src/components/comments/AppCommentsSheet.tsx +213 -0
  19. package/src/components/comments/CommentRow.tsx +63 -0
  20. package/src/components/comments/formatTimeAgo.ts +3 -0
  21. package/src/components/comments/index.ts +3 -0
  22. package/src/components/comments/useAppComments.ts +74 -0
  23. package/src/components/comments/useAppDetails.ts +35 -0
  24. package/src/components/comments/useIosKeyboardSnapFix.ts +24 -0
  25. package/src/components/dialogs/ConfirmMergeRequestDialog.tsx +156 -0
  26. package/src/components/dialogs/index.ts +4 -0
  27. package/src/components/draw/DrawColorPicker.tsx +77 -0
  28. package/src/components/draw/DrawModeOverlay.tsx +144 -0
  29. package/src/components/draw/DrawSurface.tsx +127 -0
  30. package/src/components/draw/DrawToolbar.tsx +253 -0
  31. package/src/components/draw/index.ts +15 -0
  32. package/src/components/draw/optionalHaptics.ts +15 -0
  33. package/src/components/draw/strokes.ts +21 -0
  34. package/src/components/draw/types.ts +9 -0
  35. package/src/components/floating-draggable-button/FloatingDraggableButton.tsx +323 -0
  36. package/src/components/floating-draggable-button/constants.ts +17 -0
  37. package/src/components/floating-draggable-button/index.ts +4 -0
  38. package/src/components/floating-draggable-button/types.ts +63 -0
  39. package/src/components/icons/MergeIcon.tsx +14 -0
  40. package/src/components/icons/StudioIcons.tsx +66 -0
  41. package/src/components/index.ts +17 -0
  42. package/src/components/merge-requests/MergeRequestStatusCard.tsx +179 -0
  43. package/src/components/merge-requests/ReviewMergeRequestActionButton.tsx +62 -0
  44. package/src/components/merge-requests/ReviewMergeRequestCard.tsx +192 -0
  45. package/src/components/merge-requests/ReviewMergeRequestCarousel.tsx +132 -0
  46. package/src/components/merge-requests/index.ts +7 -0
  47. package/src/components/merge-requests/mergeRequestStatusDisplay.ts +23 -0
  48. package/src/components/merge-requests/toIsoString.ts +9 -0
  49. package/src/components/merge-requests/useControlledExpansion.ts +16 -0
  50. package/src/components/models/index.ts +9 -0
  51. package/src/components/models/types.ts +43 -0
  52. package/src/components/overlays/EdgeGlowFrame.tsx +105 -0
  53. package/src/components/overlays/index.ts +4 -0
  54. package/src/components/preview/PreviewHeroCard.tsx +58 -0
  55. package/src/components/preview/PreviewImage.tsx +22 -0
  56. package/src/components/preview/PreviewMetaRow.tsx +70 -0
  57. package/src/components/preview/PreviewPage.tsx +36 -0
  58. package/src/components/preview/PreviewPlaceholder.tsx +72 -0
  59. package/src/components/preview/PreviewStatusBadge.tsx +63 -0
  60. package/src/components/preview/StatsBar.tsx +109 -0
  61. package/src/components/preview/index.ts +22 -0
  62. package/src/components/primitives/Avatar.tsx +68 -0
  63. package/src/components/primitives/Button.tsx +102 -0
  64. package/src/components/primitives/Card.tsx +30 -0
  65. package/src/components/primitives/Divider.tsx +17 -0
  66. package/src/components/primitives/Icon.tsx +40 -0
  67. package/src/components/primitives/MarkdownText.tsx +72 -0
  68. package/src/components/primitives/Modal.tsx +53 -0
  69. package/src/components/primitives/Surface.tsx +42 -0
  70. package/src/components/primitives/Text.tsx +83 -0
  71. package/src/components/primitives/index.ts +35 -0
  72. package/src/components/primitives/types.ts +30 -0
  73. package/src/components/studio-sheet/StudioBottomSheet.tsx +114 -0
  74. package/src/components/studio-sheet/StudioSheetBackground.tsx +63 -0
  75. package/src/components/studio-sheet/StudioSheetHeader.tsx +35 -0
  76. package/src/components/studio-sheet/StudioSheetHeaderIconButton.tsx +109 -0
  77. package/src/components/studio-sheet/StudioSheetPager.tsx +66 -0
  78. package/src/components/studio-sheet/index.ts +18 -0
  79. package/src/components/studio-sheet/types.ts +5 -0
  80. package/src/components/utils/color.ts +25 -0
  81. package/src/components/utils/formatTimeAgo.ts +19 -0
  82. package/src/core/logger.ts +42 -0
  83. package/src/core/services/http/baseUrl.ts +3 -0
  84. package/src/core/services/http/index.ts +128 -0
  85. package/src/core/services/http/public.ts +33 -0
  86. package/src/core/services/supabase/auth.ts +41 -0
  87. package/src/core/services/supabase/client.ts +43 -0
  88. package/src/core/services/supabase/index.ts +7 -0
  89. package/src/data/agent/remote.ts +30 -0
  90. package/src/data/agent/repository.ts +34 -0
  91. package/src/data/agent/types.ts +28 -0
  92. package/src/data/apps/bundles/remote.ts +47 -0
  93. package/src/data/apps/bundles/repository.ts +35 -0
  94. package/src/data/apps/bundles/types.ts +27 -0
  95. package/src/data/apps/images/remote.ts +61 -0
  96. package/src/data/apps/images/repository.ts +47 -0
  97. package/src/data/apps/remote.ts +97 -0
  98. package/src/data/apps/repository.ts +185 -0
  99. package/src/data/apps/types.ts +206 -0
  100. package/src/data/attachment/remote.ts +32 -0
  101. package/src/data/attachment/repository.ts +40 -0
  102. package/src/data/attachment/types.ts +42 -0
  103. package/src/data/base-remote.ts +3 -0
  104. package/src/data/base-repository.ts +11 -0
  105. package/src/data/comments/likes/remote.ts +87 -0
  106. package/src/data/comments/likes/repository.ts +61 -0
  107. package/src/data/comments/likes/types.ts +47 -0
  108. package/src/data/comments/remote.ts +71 -0
  109. package/src/data/comments/repository.ts +53 -0
  110. package/src/data/comments/types.ts +60 -0
  111. package/src/data/github/remote.ts +23 -0
  112. package/src/data/github/repository.ts +35 -0
  113. package/src/data/github/types.ts +23 -0
  114. package/src/data/home/remote.ts +24 -0
  115. package/src/data/home/repository.ts +28 -0
  116. package/src/data/home/types.ts +70 -0
  117. package/src/data/index.ts +3 -0
  118. package/src/data/likes/remote.ts +57 -0
  119. package/src/data/likes/repository.ts +47 -0
  120. package/src/data/likes/types.ts +46 -0
  121. package/src/data/me/remote.ts +28 -0
  122. package/src/data/me/repository.ts +30 -0
  123. package/src/data/me/types.ts +14 -0
  124. package/src/data/merge-requests/remote.ts +76 -0
  125. package/src/data/merge-requests/repository.ts +66 -0
  126. package/src/data/merge-requests/types.ts +33 -0
  127. package/src/data/messages/remote.ts +21 -0
  128. package/src/data/messages/repository.ts +104 -0
  129. package/src/data/messages/types.ts +20 -0
  130. package/src/data/public/studio-config/remote.ts +19 -0
  131. package/src/data/public/studio-config/repository.ts +23 -0
  132. package/src/data/public/studio-config/types.ts +6 -0
  133. package/src/data/ratings/remote.ts +76 -0
  134. package/src/data/ratings/repository.ts +63 -0
  135. package/src/data/ratings/types.ts +57 -0
  136. package/src/data/threads/remote.ts +40 -0
  137. package/src/data/threads/repository.ts +41 -0
  138. package/src/data/threads/types.ts +25 -0
  139. package/src/data/types.ts +8 -0
  140. package/src/data/users/remote.ts +31 -0
  141. package/src/data/users/repository.ts +45 -0
  142. package/src/data/users/types.ts +15 -0
  143. package/src/index.ts +6 -0
  144. package/src/studio/ComergeStudio.tsx +239 -0
  145. package/src/studio/bootstrap/StudioBootstrap.tsx +45 -0
  146. package/src/studio/bootstrap/useStudioBootstrap.ts +55 -0
  147. package/src/studio/hooks/useApp.ts +83 -0
  148. package/src/studio/hooks/useAppStats.ts +111 -0
  149. package/src/studio/hooks/useAttachmentUpload.ts +59 -0
  150. package/src/studio/hooks/useBundleManager.ts +389 -0
  151. package/src/studio/hooks/useMergeRequests.ts +173 -0
  152. package/src/studio/hooks/useStudioActions.ts +96 -0
  153. package/src/studio/hooks/useThreadMessages.ts +85 -0
  154. package/src/studio/lib/chat.ts +34 -0
  155. package/src/studio/ui/ChatPanel.tsx +154 -0
  156. package/src/studio/ui/ConfirmMergeFlow.tsx +55 -0
  157. package/src/studio/ui/PreviewPanel.tsx +131 -0
  158. package/src/studio/ui/RuntimeRenderer.tsx +40 -0
  159. package/src/studio/ui/StudioOverlay.tsx +257 -0
  160. package/src/studio/ui/preview-panel/PressableCardRow.tsx +49 -0
  161. package/src/studio/ui/preview-panel/PreviewCollaborateSection.tsx +174 -0
  162. package/src/studio/ui/preview-panel/PreviewCustomizeSection.tsx +160 -0
  163. package/src/studio/ui/preview-panel/PreviewHeroSection.tsx +56 -0
  164. package/src/studio/ui/preview-panel/PreviewMetaSection.tsx +67 -0
  165. package/src/studio/ui/preview-panel/PreviewPanelHeader.tsx +48 -0
  166. package/src/studio/ui/preview-panel/SectionTitle.tsx +31 -0
  167. package/src/studio/ui/preview-panel/usePreviewPanelData.ts +132 -0
  168. package/src/studio/ui/preview-panel/utils.ts +29 -0
  169. package/src/theme/index.ts +5 -0
  170. package/src/theme/tokens.ts +118 -0
  171. package/src/theme/types.ts +90 -0
  172. package/src/theme/useTheme.ts +11 -0
  173. package/dist/assets/images/merge.svg +0 -3
  174. package/dist/merge-72UG27QV.svg +0 -3
@@ -0,0 +1,253 @@
1
+ import * as React from 'react';
2
+ import {
3
+ ActivityIndicator,
4
+ Animated,
5
+ PanResponder,
6
+ Pressable,
7
+ View,
8
+ useWindowDimensions,
9
+ type ViewStyle,
10
+ } from 'react-native';
11
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
12
+ import { Check, GripVertical, Undo2, X } from 'lucide-react-native';
13
+
14
+ import { impact } from './optionalHaptics';
15
+ import { DrawColorPicker } from './DrawColorPicker';
16
+
17
+ export type DrawToolbarProps = {
18
+ colors: string[];
19
+ selectedColor: string;
20
+ onSelectColor: (color: string) => void;
21
+ canUndo: boolean;
22
+ onUndo: () => void;
23
+ onCancel: () => void;
24
+ onDone: () => void;
25
+ capturing?: boolean;
26
+ hidden?: boolean;
27
+ renderUndoIcon?: () => React.ReactNode;
28
+ renderCancelIcon?: () => React.ReactNode;
29
+ renderDoneIcon?: () => React.ReactNode;
30
+ renderDragHandle?: () => React.ReactNode;
31
+ style?: ViewStyle;
32
+ };
33
+
34
+ export function DrawToolbar({
35
+ colors,
36
+ selectedColor,
37
+ onSelectColor,
38
+ canUndo,
39
+ onUndo,
40
+ onCancel,
41
+ onDone,
42
+ capturing = false,
43
+ hidden = false,
44
+ renderUndoIcon,
45
+ renderCancelIcon,
46
+ renderDoneIcon,
47
+ renderDragHandle,
48
+ style,
49
+ }: DrawToolbarProps) {
50
+ const insets = useSafeAreaInsets();
51
+ const { width: screenWidth, height: screenHeight } = useWindowDimensions();
52
+
53
+ const [expanded, setExpanded] = React.useState(false);
54
+
55
+ const pos = React.useRef(new Animated.ValueXY({ x: screenWidth / 2 - 110, y: -140 })).current;
56
+ const start = React.useRef({ x: 0, y: 0 });
57
+ const currentPos = React.useRef({ x: 0, y: 0 });
58
+
59
+ React.useEffect(() => {
60
+ if (hidden) return;
61
+ Animated.spring(pos.y, {
62
+ toValue: insets.top + 60,
63
+ useNativeDriver: true,
64
+ damping: 12,
65
+ stiffness: 120,
66
+ mass: 0.8,
67
+ }).start();
68
+ }, [hidden, insets.top, pos.y]);
69
+
70
+ React.useEffect(() => {
71
+ const id = pos.addListener((v) => {
72
+ currentPos.current = { x: v.x ?? 0, y: v.y ?? 0 };
73
+ });
74
+ return () => {
75
+ pos.removeListener(id);
76
+ };
77
+ }, [pos]);
78
+
79
+ const clamp = React.useCallback(
80
+ (x: number, y: number) => {
81
+ const minX = 10;
82
+ const maxX = Math.max(10, screenWidth - 230);
83
+ const minY = insets.top + 10;
84
+ const maxY = Math.max(minY, screenHeight - 180);
85
+ return { x: Math.max(minX, Math.min(maxX, x)), y: Math.max(minY, Math.min(maxY, y)) };
86
+ },
87
+ [insets.top, screenHeight, screenWidth]
88
+ );
89
+
90
+ const panResponder = React.useMemo(
91
+ () =>
92
+ PanResponder.create({
93
+ onStartShouldSetPanResponder: () => false,
94
+ onMoveShouldSetPanResponder: (_e, g) => Math.abs(g.dx) > 5 || Math.abs(g.dy) > 5,
95
+ onPanResponderGrant: () => {
96
+ start.current = { ...currentPos.current };
97
+ },
98
+ onPanResponderMove: (_e, g) => {
99
+ const next = clamp(start.current.x + g.dx, start.current.y + g.dy);
100
+ pos.setValue(next);
101
+ },
102
+ onPanResponderRelease: () => {
103
+ const next = clamp(currentPos.current.x, currentPos.current.y);
104
+ Animated.spring(pos, { toValue: next, useNativeDriver: true }).start();
105
+ },
106
+ }),
107
+ [clamp, pos]
108
+ );
109
+
110
+ if (hidden) return null;
111
+
112
+ function CircleActionButton({
113
+ accessibilityLabel,
114
+ disabled,
115
+ capturingDisabled,
116
+ backgroundColor,
117
+ onPress,
118
+ children,
119
+ }: {
120
+ accessibilityLabel: string;
121
+ disabled?: boolean;
122
+ capturingDisabled?: boolean;
123
+ backgroundColor: string;
124
+ onPress: () => void;
125
+ children: React.ReactNode;
126
+ }) {
127
+ const isDisabled = Boolean(disabled) || Boolean(capturingDisabled);
128
+ const [pressed, setPressed] = React.useState(false);
129
+ return (
130
+ <View
131
+ style={{
132
+ width: 28,
133
+ height: 28,
134
+ borderRadius: 14,
135
+ alignItems: 'center',
136
+ justifyContent: 'center',
137
+ backgroundColor,
138
+ opacity: isDisabled ? 0.5 : pressed ? 0.85 : 1,
139
+ }}
140
+ >
141
+ <Pressable
142
+ accessibilityRole="button"
143
+ accessibilityLabel={accessibilityLabel}
144
+ disabled={isDisabled}
145
+ onPress={onPress}
146
+ onPressIn={() => setPressed(true)}
147
+ onPressOut={() => setPressed(false)}
148
+ style={{ width: '100%', height: '100%', alignItems: 'center', justifyContent: 'center' }}
149
+ hitSlop={8}
150
+ >
151
+ {children}
152
+ </Pressable>
153
+ </View>
154
+ );
155
+ }
156
+
157
+ return (
158
+ <Animated.View
159
+ style={[
160
+ {
161
+ position: 'absolute',
162
+ zIndex: 100,
163
+ transform: [{ translateX: pos.x }, { translateY: pos.y }],
164
+ shadowColor: '#000',
165
+ shadowOffset: { width: 0, height: 4 },
166
+ shadowOpacity: 0.3,
167
+ shadowRadius: 8,
168
+ elevation: 8,
169
+ },
170
+ style,
171
+ ]}
172
+ {...panResponder.panHandlers}
173
+ >
174
+ <View
175
+ style={{
176
+ backgroundColor: '#F43F5E',
177
+ borderRadius: 16,
178
+ padding: 12,
179
+ minWidth: 220,
180
+ }}
181
+ >
182
+ <View style={{ flexDirection: 'row', alignItems: 'center', gap: 8 }}>
183
+ {renderDragHandle ? (
184
+ renderDragHandle()
185
+ ) : (
186
+ <GripVertical size={20} color="rgba(255, 255, 255, 0.6)" />
187
+ )}
188
+
189
+ <DrawColorPicker
190
+ colors={colors}
191
+ selected={selectedColor}
192
+ expanded={expanded}
193
+ onToggle={() => {
194
+ void impact('light');
195
+ setExpanded((v) => !v);
196
+ }}
197
+ onSelect={(c) => {
198
+ void impact('light');
199
+ onSelectColor(c);
200
+ }}
201
+ />
202
+
203
+ <View style={{ width: 1, height: 20, backgroundColor: 'rgba(255, 255, 255, 0.3)', marginHorizontal: 4 }} />
204
+
205
+ <CircleActionButton
206
+ accessibilityLabel="Undo"
207
+ disabled={!canUndo}
208
+ capturingDisabled={capturing}
209
+ backgroundColor={!canUndo || capturing ? 'rgba(255, 255, 255, 0.1)' : 'rgba(255, 255, 255, 0.25)'}
210
+ onPress={() => {
211
+ void impact('light');
212
+ onUndo();
213
+ }}
214
+ >
215
+ {renderUndoIcon ? renderUndoIcon() : <Undo2 size={16} color={canUndo ? '#FFFFFF' : 'rgba(255,255,255,0.4)'} />}
216
+ </CircleActionButton>
217
+
218
+ <CircleActionButton
219
+ accessibilityLabel="Cancel"
220
+ capturingDisabled={capturing}
221
+ backgroundColor="rgba(255, 255, 255, 0.15)"
222
+ onPress={() => {
223
+ void impact('medium');
224
+ onCancel();
225
+ }}
226
+ >
227
+ {renderCancelIcon ? renderCancelIcon() : <X size={16} color="#FFFFFF" />}
228
+ </CircleActionButton>
229
+
230
+ <CircleActionButton
231
+ accessibilityLabel="Done"
232
+ capturingDisabled={capturing}
233
+ backgroundColor="rgba(255, 255, 255, 0.35)"
234
+ onPress={() => {
235
+ void impact('medium');
236
+ onDone();
237
+ }}
238
+ >
239
+ {capturing ? (
240
+ <ActivityIndicator color="#FFFFFF" size="small" />
241
+ ) : renderDoneIcon ? (
242
+ renderDoneIcon()
243
+ ) : (
244
+ <Check size={16} color="#FFFFFF" />
245
+ )}
246
+ </CircleActionButton>
247
+ </View>
248
+ </View>
249
+ </Animated.View>
250
+ );
251
+ }
252
+
253
+
@@ -0,0 +1,15 @@
1
+ export { DrawModeOverlay } from './DrawModeOverlay';
2
+ export type { DrawModeOverlayProps } from './DrawModeOverlay';
3
+
4
+ export { DrawSurface } from './DrawSurface';
5
+ export type { DrawSurfaceProps } from './DrawSurface';
6
+
7
+ export { DrawToolbar } from './DrawToolbar';
8
+ export type { DrawToolbarProps } from './DrawToolbar';
9
+
10
+ export { DrawColorPicker } from './DrawColorPicker';
11
+ export type { DrawColorPickerProps } from './DrawColorPicker';
12
+
13
+ export type { Point, Stroke } from './types';
14
+
15
+
@@ -0,0 +1,15 @@
1
+ type ImpactStyle = 'light' | 'medium' | 'heavy';
2
+
3
+ export async function impact(style: ImpactStyle) {
4
+ try {
5
+ const Haptics = require('expo-haptics') as typeof import('expo-haptics');
6
+ const map: Record<ImpactStyle, any> = {
7
+ light: Haptics.ImpactFeedbackStyle.Light,
8
+ medium: Haptics.ImpactFeedbackStyle.Medium,
9
+ heavy: Haptics.ImpactFeedbackStyle.Heavy,
10
+ };
11
+ await Haptics.impactAsync(map[style]);
12
+ } catch {}
13
+ }
14
+
15
+
@@ -0,0 +1,21 @@
1
+ import type { Point } from './types';
2
+
3
+ export function pointsToSmoothPath(points: Point[]): string {
4
+ if (points.length === 0) return '';
5
+ if (points.length === 1) return `M${points[0].x},${points[0].y}`;
6
+ if (points.length === 2) return `M${points[0].x},${points[0].y} L${points[1].x},${points[1].y}`;
7
+
8
+ let path = `M${points[0].x},${points[0].y}`;
9
+ for (let i = 1; i < points.length - 1; i++) {
10
+ const p1 = points[i];
11
+ const p2 = points[i + 1];
12
+ const midX = (p1.x + p2.x) / 2;
13
+ const midY = (p1.y + p2.y) / 2;
14
+ path += ` Q${p1.x},${p1.y} ${midX},${midY}`;
15
+ }
16
+ const last = points[points.length - 1];
17
+ path += ` L${last.x},${last.y}`;
18
+ return path;
19
+ }
20
+
21
+
@@ -0,0 +1,9 @@
1
+ export type Point = { x: number; y: number };
2
+
3
+ export type Stroke = {
4
+ points: Point[];
5
+ color: string;
6
+ width: number;
7
+ };
8
+
9
+
@@ -0,0 +1,323 @@
1
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
2
+ import {
3
+ PanResponder,
4
+ Pressable,
5
+ StyleSheet,
6
+ Text,
7
+ type GestureResponderEvent,
8
+ useWindowDimensions,
9
+ View,
10
+ } from 'react-native';
11
+ import * as Haptics from 'expo-haptics';
12
+ import Animated, {
13
+ Easing,
14
+ interpolateColor,
15
+ runOnJS,
16
+ useAnimatedStyle,
17
+ useSharedValue,
18
+ withRepeat,
19
+ withSequence,
20
+ withSpring,
21
+ withTiming,
22
+ } from 'react-native-reanimated';
23
+ import { LiquidGlassView, isLiquidGlassSupported } from '@callstack/liquid-glass';
24
+
25
+ import { DEFAULT_EDGE_PADDING, DEFAULT_OFFSET, DEFAULT_SIZE, ENTER_ROTATION_FROM_DEG, ENTER_SCALE_FROM, HIDDEN_OPACITY, PULSE_DURATION_MS } from './constants';
26
+ import type { FloatingDraggableButtonProps } from './types';
27
+ import { useTheme } from '../../theme';
28
+
29
+ const HIDDEN_OFFSET_X = 20;
30
+
31
+ const SPRING_POSITION = { damping: 12, stiffness: 100, mass: 0.8 } as const;
32
+ const SPRING_SCALE_IN = { damping: 10, stiffness: 200 } as const;
33
+ const SPRING_SCALE_OUT = { damping: 12, stiffness: 150 } as const;
34
+ const SPRING_ROTATION_IN = { damping: 15, stiffness: 80 } as const;
35
+ const SPRING_ROTATION_GRAB = { damping: 20 } as const;
36
+ const SPRING_SCALE_GRAB = { damping: 15, stiffness: 200 } as const;
37
+
38
+ const TIMING_OPACITY_IN = { duration: 300, easing: Easing.out(Easing.ease) } as const;
39
+ const TIMING_OPACITY_OUT = { duration: 250, easing: Easing.in(Easing.ease) } as const;
40
+
41
+ function clamp(value: number, min: number, max: number) {
42
+ 'worklet';
43
+ return Math.max(min, Math.min(max, value));
44
+ }
45
+
46
+ function getHiddenTranslateX(size: number) {
47
+ return -size - HIDDEN_OFFSET_X;
48
+ }
49
+
50
+ function getHiddenTranslateY(height: number) {
51
+ return height;
52
+ }
53
+
54
+ function getFinalTranslateY(height: number, size: number, bottomOffset: number) {
55
+ return height - size - bottomOffset;
56
+ }
57
+
58
+ export function FloatingDraggableButton({
59
+ onPress,
60
+ size = DEFAULT_SIZE,
61
+ disabled = false,
62
+ ariaLabel,
63
+ isLoading = false,
64
+ visible = true,
65
+ badgeCount = 0,
66
+ offset = DEFAULT_OFFSET,
67
+ variant = 'default',
68
+ forceShowTrigger = 0,
69
+ children,
70
+ style,
71
+ testID,
72
+ edgePadding = DEFAULT_EDGE_PADDING,
73
+ backgroundColor,
74
+ }: FloatingDraggableButtonProps) {
75
+ const theme = useTheme();
76
+ const { width, height } = useWindowDimensions();
77
+ const isDanger = variant === 'danger';
78
+
79
+ const onPressRef = useRef(onPress);
80
+ useEffect(() => {
81
+ onPressRef.current = onPress;
82
+ }, [onPress]);
83
+
84
+ const fallbackBgColor = useMemo(() => {
85
+ if (backgroundColor) return backgroundColor;
86
+ if (isDanger) return 'rgba(239, 68, 68, 0.9)';
87
+ return theme.scheme === 'dark' ? 'rgba(0, 0, 0, 0.6)' : 'rgba(255, 255, 255, 0.6)';
88
+ }, [backgroundColor, isDanger, theme.scheme]);
89
+
90
+ const translateX = useSharedValue(getHiddenTranslateX(size));
91
+ const translateY = useSharedValue(getHiddenTranslateY(height));
92
+ const scale = useSharedValue(ENTER_SCALE_FROM);
93
+ const rotation = useSharedValue(ENTER_ROTATION_FROM_DEG);
94
+ const opacity = useSharedValue(1);
95
+ const borderPulse = useSharedValue(0);
96
+ const startPos = useRef({ x: 0, y: 0 });
97
+ const isAnimatingOut = useRef(false);
98
+
99
+ const animateToHidden = useCallback(
100
+ (options?: { onFinish?: () => void }) => {
101
+ // Animate back to starting position (reverse of entrance)
102
+ translateX.value = withSpring(getHiddenTranslateX(size), SPRING_POSITION);
103
+ translateY.value = withSpring(getHiddenTranslateY(height), SPRING_POSITION);
104
+ scale.value = withSpring(ENTER_SCALE_FROM, SPRING_SCALE_IN);
105
+ rotation.value = withSpring(ENTER_ROTATION_FROM_DEG, SPRING_ROTATION_IN);
106
+
107
+ const finish = options?.onFinish;
108
+ if (!finish) {
109
+ opacity.value = withTiming(HIDDEN_OPACITY, TIMING_OPACITY_OUT);
110
+ return;
111
+ }
112
+
113
+ opacity.value = withTiming(
114
+ HIDDEN_OPACITY as unknown as number,
115
+ TIMING_OPACITY_OUT,
116
+ (finished?: boolean) => {
117
+ if (finished) runOnJS(finish)();
118
+ }
119
+ );
120
+ },
121
+ [height, opacity, rotation, scale, size, translateX, translateY]
122
+ );
123
+
124
+ const animateOut = useCallback(() => {
125
+ if (isAnimatingOut.current) return;
126
+ isAnimatingOut.current = true;
127
+
128
+ try {
129
+ void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
130
+ } catch {
131
+ // noop
132
+ }
133
+
134
+ animateToHidden({
135
+ onFinish: () => {
136
+ onPressRef.current?.();
137
+ },
138
+ });
139
+ }, [animateToHidden]);
140
+
141
+ useEffect(() => {
142
+ if (isLoading) {
143
+ borderPulse.value = withRepeat(
144
+ withSequence(
145
+ withTiming(1, { duration: PULSE_DURATION_MS, easing: Easing.out(Easing.ease) }),
146
+ withTiming(0, { duration: PULSE_DURATION_MS, easing: Easing.in(Easing.ease) })
147
+ ),
148
+ -1,
149
+ true
150
+ );
151
+ } else {
152
+ borderPulse.value = withTiming(0, { duration: 200 });
153
+ }
154
+ }, [borderPulse, isLoading]);
155
+
156
+ const animateIn = useCallback(() => {
157
+ isAnimatingOut.current = false;
158
+ translateX.value = withSpring(offset.left ?? DEFAULT_OFFSET.left, SPRING_POSITION);
159
+ const finalY = getFinalTranslateY(height, size, offset.bottom ?? DEFAULT_OFFSET.bottom);
160
+ translateY.value = withSpring(finalY, SPRING_POSITION);
161
+ scale.value = withSequence(
162
+ withSpring(1.2, SPRING_SCALE_IN),
163
+ withSpring(1, SPRING_SCALE_OUT)
164
+ );
165
+ rotation.value = withSpring(0, SPRING_ROTATION_IN);
166
+ opacity.value = withTiming(1, TIMING_OPACITY_IN);
167
+ }, [height, offset.bottom, offset.left, opacity, rotation, scale, size, translateX, translateY]);
168
+
169
+ // Initial animation on mount
170
+ useEffect(() => {
171
+ const timer = setTimeout(() => {
172
+ if (visible) {
173
+ animateIn();
174
+ }
175
+ }, 100);
176
+
177
+ return () => clearTimeout(timer);
178
+ }, []);
179
+
180
+ useEffect(() => {
181
+ if (visible && isAnimatingOut.current) {
182
+ animateIn();
183
+ } else if (!visible && !isAnimatingOut.current) {
184
+ animateToHidden();
185
+ isAnimatingOut.current = true;
186
+ }
187
+ }, [visible, animateIn, animateToHidden]);
188
+
189
+ useEffect(() => {
190
+ if (forceShowTrigger > 0 && visible) {
191
+ isAnimatingOut.current = false;
192
+ animateIn();
193
+ }
194
+ }, [forceShowTrigger, visible, animateIn]);
195
+
196
+ const panResponder = useRef(
197
+ PanResponder.create({
198
+ onStartShouldSetPanResponder: () => true,
199
+ onMoveShouldSetPanResponder: () => true,
200
+ onPanResponderGrant: () => {
201
+ startPos.current = {
202
+ x: translateX.value,
203
+ y: translateY.value,
204
+ };
205
+ scale.value = withSpring(1.1, SPRING_SCALE_GRAB);
206
+ rotation.value = withSpring(0, SPRING_ROTATION_GRAB);
207
+ },
208
+ onPanResponderMove: (_: GestureResponderEvent, gesture) => {
209
+ const newX = startPos.current.x + gesture.dx;
210
+ const newY = startPos.current.y + gesture.dy;
211
+ translateX.value = clamp(newX, edgePadding, width - size - edgePadding);
212
+ translateY.value = clamp(newY, edgePadding, height - size - edgePadding);
213
+ },
214
+ onPanResponderRelease: (_evt, gesture) => {
215
+ scale.value = withSpring(1, SPRING_SCALE_GRAB);
216
+ const distance = Math.sqrt(gesture.dx ** 2 + gesture.dy ** 2);
217
+ if (distance < 5 && !disabled) {
218
+ animateOut();
219
+ }
220
+ },
221
+ })
222
+ ).current;
223
+
224
+ const animatedStyle = useAnimatedStyle(() => ({
225
+ transform: [
226
+ { translateX: translateX.value },
227
+ { translateY: translateY.value },
228
+ { scale: scale.value },
229
+ { rotate: `${rotation.value}deg` },
230
+ ],
231
+ opacity: opacity.value,
232
+ }));
233
+
234
+ const borderAnimatedStyle = useAnimatedStyle(() => {
235
+ const borderColor = interpolateColor(
236
+ borderPulse.value,
237
+ [0, 1],
238
+ isDanger
239
+ ? ['rgba(239,68,68,0.4)', 'rgba(239,68,68,1)']
240
+ : theme.scheme === 'dark'
241
+ ? ['rgba(255,255,255,0.2)', 'rgba(255,255,255,0.9)']
242
+ : ['rgba(55,0,179,0.2)', 'rgba(55,0,179,0.9)']
243
+ );
244
+ return {
245
+ borderWidth: isLoading ? 2 : 0,
246
+ borderColor,
247
+ borderRadius: size / 2,
248
+ };
249
+ });
250
+
251
+ return (
252
+ <Animated.View
253
+ {...panResponder.panHandlers}
254
+ testID={testID}
255
+ style={[styles.floatingButton, { width: size, height: size, borderRadius: size / 2 }, style, animatedStyle]}
256
+ accessibilityRole="button"
257
+ accessibilityLabel={ariaLabel}
258
+ >
259
+ <Animated.View style={[{ width: size, height: size, borderRadius: size / 2 }, borderAnimatedStyle]}>
260
+ <LiquidGlassView
261
+ style={[{ flex: 1, borderRadius: size / 2 }, !isLiquidGlassSupported && { backgroundColor: fallbackBgColor }]}
262
+ interactive
263
+ effect="clear"
264
+ >
265
+ <Pressable
266
+ onPress={() => {
267
+ if (!disabled) animateOut();
268
+ }}
269
+ style={styles.buttonInner}
270
+ android_ripple={{ color: 'rgba(255, 255, 255, 0.3)', borderless: true }}
271
+ >
272
+ {children ?? <View />}
273
+ </Pressable>
274
+ </LiquidGlassView>
275
+ </Animated.View>
276
+
277
+ {badgeCount > 0 && (
278
+ <View style={[styles.badge, { backgroundColor: theme.colors.danger }]}>
279
+ <Text style={[styles.badgeText, { color: theme.colors.onDanger }]}>
280
+ {badgeCount > 99 ? '99+' : badgeCount}
281
+ </Text>
282
+ </View>
283
+ )}
284
+ </Animated.View>
285
+ );
286
+ }
287
+
288
+ const styles = StyleSheet.create({
289
+ floatingButton: {
290
+ position: 'absolute',
291
+ justifyContent: 'center',
292
+ alignItems: 'center',
293
+ shadowColor: '#000',
294
+ shadowOffset: { width: 0, height: 2 },
295
+ shadowOpacity: 0.25,
296
+ shadowRadius: 3.84,
297
+ elevation: 5,
298
+ },
299
+ buttonInner: {
300
+ width: '100%',
301
+ height: '100%',
302
+ justifyContent: 'center',
303
+ alignItems: 'center',
304
+ borderRadius: 999,
305
+ },
306
+ badge: {
307
+ position: 'absolute',
308
+ top: -4,
309
+ right: -4,
310
+ minWidth: 20,
311
+ height: 20,
312
+ borderRadius: 10,
313
+ justifyContent: 'center',
314
+ alignItems: 'center',
315
+ paddingHorizontal: 5,
316
+ },
317
+ badgeText: {
318
+ fontSize: 11,
319
+ fontWeight: '700',
320
+ },
321
+ });
322
+
323
+
@@ -0,0 +1,17 @@
1
+ import type { FloatingButtonOffset } from './types';
2
+
3
+ export const DEFAULT_SIZE = 48;
4
+ export const DEFAULT_EDGE_PADDING = 10;
5
+
6
+ export const DEFAULT_OFFSET: Required<FloatingButtonOffset> = {
7
+ left: 20,
8
+ bottom: 60,
9
+ };
10
+
11
+ export const ENTER_SCALE_FROM = 0.3;
12
+ export const ENTER_ROTATION_FROM_DEG = -180;
13
+ export const HIDDEN_OPACITY = 0.3;
14
+
15
+ export const PULSE_DURATION_MS = 900;
16
+
17
+
@@ -0,0 +1,4 @@
1
+ export { FloatingDraggableButton } from './FloatingDraggableButton';
2
+ export type { FloatingDraggableButtonProps, FloatingButtonOffset } from './types';
3
+
4
+