@umituz/react-native-photo-editor 2.0.22 → 2.0.24

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 (28) hide show
  1. package/package.json +1 -1
  2. package/src/PhotoEditor.tsx +56 -44
  3. package/src/application/hooks/useEditor.ts +67 -0
  4. package/src/application/hooks/useEditorUI.ts +145 -0
  5. package/src/application/stores/EditorStore.ts +137 -0
  6. package/src/constants.ts +5 -52
  7. package/src/domain/entities/Filters.ts +72 -0
  8. package/src/domain/entities/Layer.ts +126 -0
  9. package/src/domain/entities/Transform.ts +55 -0
  10. package/src/domain/services/HistoryService.ts +60 -0
  11. package/src/domain/services/LayerService.ts +105 -0
  12. package/src/index.ts +25 -5
  13. package/src/infrastructure/gesture/types.ts +27 -0
  14. package/src/infrastructure/gesture/useTransformGesture.ts +136 -0
  15. package/src/infrastructure/history/HistoryManager.ts +38 -0
  16. package/src/presentation/components/DraggableLayer.tsx +114 -0
  17. package/src/presentation/components/EditorCanvas.tsx +90 -0
  18. package/src/presentation/components/EditorToolbar.tsx +192 -0
  19. package/src/presentation/components/FontControls.tsx +99 -0
  20. package/src/presentation/components/sheets/AIMagicSheet.tsx +99 -0
  21. package/src/presentation/components/sheets/AdjustmentsSheet.tsx +113 -0
  22. package/src/presentation/components/sheets/FilterSheet.tsx +128 -0
  23. package/src/presentation/components/sheets/LayerManager.tsx +151 -0
  24. package/src/presentation/components/sheets/StickerPicker.tsx +67 -0
  25. package/src/presentation/components/sheets/TextEditorSheet.tsx +159 -0
  26. package/src/presentation/components/ui/ColorPicker.tsx +78 -0
  27. package/src/presentation/components/ui/Slider.tsx +116 -0
  28. package/src/types.ts +13 -58
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Filter Sheet Component
3
+ * Bottom sheet for selecting preset filters
4
+ */
5
+
6
+ import React, { memo } from "react";
7
+ import { View, TouchableOpacity, StyleSheet } from "react-native";
8
+ import { AtomicText, AtomicIcon } from "@umituz/react-native-design-system/atoms";
9
+ import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
10
+
11
+ export interface FilterOption {
12
+ id: string;
13
+ name: string;
14
+ icon: string;
15
+ filters: Record<string, number>;
16
+ }
17
+
18
+ interface FilterSheetProps {
19
+ selectedFilter: string;
20
+ onSelectFilter: (option: FilterOption) => void;
21
+ filters?: FilterOption[];
22
+ }
23
+
24
+ const DEFAULT_FILTERS: FilterOption[] = [
25
+ {
26
+ id: "none",
27
+ name: "None",
28
+ icon: "close",
29
+ filters: { brightness: 1, contrast: 1, saturation: 1, sepia: 0, grayscale: 0 },
30
+ },
31
+ {
32
+ id: "sepia",
33
+ name: "Sepia",
34
+ icon: "brush",
35
+ filters: { sepia: 0.7, saturation: 0.8 },
36
+ },
37
+ {
38
+ id: "grayscale",
39
+ name: "B&W",
40
+ icon: "swap-horizontal",
41
+ filters: { grayscale: 1, saturation: 0 },
42
+ },
43
+ {
44
+ id: "vintage",
45
+ name: "Vintage",
46
+ icon: "flash",
47
+ filters: { sepia: 0.3, contrast: 1.1, brightness: 0.9 },
48
+ },
49
+ {
50
+ id: "warm",
51
+ name: "Warm",
52
+ icon: "sparkles",
53
+ filters: { brightness: 1.05, saturation: 1.2 },
54
+ },
55
+ {
56
+ id: "cool",
57
+ name: "Cool",
58
+ icon: "image",
59
+ filters: { contrast: 1.05, brightness: 1.02, saturation: 0.85 },
60
+ },
61
+ ];
62
+
63
+ export const FilterSheet = memo<FilterSheetProps>(({
64
+ selectedFilter,
65
+ onSelectFilter,
66
+ filters = DEFAULT_FILTERS,
67
+ }) => {
68
+ const tokens = useAppDesignTokens();
69
+
70
+ return (
71
+ <View style={styles.container}>
72
+ <AtomicText type="headlineSmall">Filters</AtomicText>
73
+ <View style={styles.grid}>
74
+ {filters.map((f) => {
75
+ const isActive = selectedFilter === f.id;
76
+ return (
77
+ <TouchableOpacity
78
+ key={f.id}
79
+ style={[
80
+ styles.filter,
81
+ {
82
+ backgroundColor: tokens.colors.surfaceVariant,
83
+ borderColor: isActive ? tokens.colors.primary : "transparent",
84
+ },
85
+ ]}
86
+ onPress={() => onSelectFilter(f)}
87
+ accessibilityLabel={f.name}
88
+ accessibilityRole="button"
89
+ accessibilityState={{ selected: isActive }}
90
+ >
91
+ <AtomicIcon
92
+ name={f.icon as "close"}
93
+ size="lg"
94
+ color={isActive ? "primary" : "textSecondary"}
95
+ />
96
+ <AtomicText
97
+ type="labelSmall"
98
+ color={isActive ? "primary" : "textSecondary"}
99
+ >
100
+ {f.name}
101
+ </AtomicText>
102
+ </TouchableOpacity>
103
+ );
104
+ })}
105
+ </View>
106
+ </View>
107
+ );
108
+ });
109
+
110
+ FilterSheet.displayName = "FilterSheet";
111
+
112
+ const styles = StyleSheet.create({
113
+ container: { padding: 16, gap: 16 },
114
+ grid: {
115
+ flexDirection: "row",
116
+ flexWrap: "wrap",
117
+ gap: 12,
118
+ },
119
+ filter: {
120
+ width: 75,
121
+ height: 75,
122
+ borderRadius: 8,
123
+ alignItems: "center",
124
+ justifyContent: "center",
125
+ borderWidth: 2,
126
+ gap: 4,
127
+ },
128
+ });
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Layer Manager Sheet Component
3
+ * Bottom sheet for managing layers
4
+ */
5
+
6
+ import React, { memo } from "react";
7
+ import { View, ScrollView, TouchableOpacity } from "react-native";
8
+ import { AtomicText, AtomicIcon } from "@umituz/react-native-design-system/atoms";
9
+ import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
10
+ import { Layer, isTextLayer } from "../../../domain/entities/Layer";
11
+
12
+ interface LayerManagerProps {
13
+ layers: Layer[];
14
+ activeLayerId: string | null;
15
+ onSelectLayer: (id: string) => void;
16
+ onDeleteLayer: (id: string) => void;
17
+ onDuplicateLayer?: (id: string) => void;
18
+ onMoveLayerUp?: (id: string) => void;
19
+ onMoveLayerDown?: (id: string) => void;
20
+ t: (key: string) => string;
21
+ }
22
+
23
+ export const LayerManager = memo<LayerManagerProps>(({
24
+ layers,
25
+ activeLayerId,
26
+ onSelectLayer,
27
+ onDeleteLayer,
28
+ onDuplicateLayer,
29
+ onMoveLayerUp,
30
+ onMoveLayerDown,
31
+ t,
32
+ }) => {
33
+ const tokens = useAppDesignTokens();
34
+ const sortedLayers = [...layers].reverse();
35
+
36
+ return (
37
+ <View style={{ padding: tokens.spacing.md, gap: tokens.spacing.md }}>
38
+ <AtomicText type="headlineSmall">Layers</AtomicText>
39
+ <ScrollView showsVerticalScrollIndicator={false}>
40
+ {sortedLayers.length === 0 ? (
41
+ <AtomicText
42
+ color="textSecondary"
43
+ style={{ textAlign: "center", padding: tokens.spacing.xl }}
44
+ >
45
+ No layers yet
46
+ </AtomicText>
47
+ ) : (
48
+ sortedLayers.map((layer, idx) => {
49
+ const isActive = activeLayerId === layer.id;
50
+ const label = isTextLayer(layer)
51
+ ? layer.text || t("photo_editor.untitled") || "Untitled"
52
+ : "Sticker";
53
+ const isTop = idx === 0;
54
+ const isBottom = idx === sortedLayers.length - 1;
55
+
56
+ return (
57
+ <TouchableOpacity
58
+ key={layer.id}
59
+ style={{
60
+ flexDirection: "row",
61
+ alignItems: "center",
62
+ padding: tokens.spacing.sm,
63
+ backgroundColor: tokens.colors.surfaceVariant,
64
+ borderRadius: tokens.borders.radius.md,
65
+ marginBottom: tokens.spacing.xs,
66
+ borderWidth: 2,
67
+ borderColor: isActive ? tokens.colors.primary : "transparent",
68
+ backgroundColor: isActive ? tokens.colors.primary + "10" : tokens.colors.surfaceVariant,
69
+ }}
70
+ onPress={() => onSelectLayer(layer.id)}
71
+ accessibilityLabel={`${layer.type} layer: ${label}`}
72
+ accessibilityRole="button"
73
+ accessibilityState={{ selected: isActive }}
74
+ >
75
+ <AtomicIcon
76
+ name={layer.type === "text" ? "edit" : "image"}
77
+ size="sm"
78
+ color={isActive ? "primary" : "textSecondary"}
79
+ />
80
+ <View style={{ flex: 1, marginLeft: tokens.spacing.sm }}>
81
+ <AtomicText type="labelSmall" color="textSecondary">
82
+ {layer.type.toUpperCase()}
83
+ </AtomicText>
84
+ <AtomicText fontWeight="bold" numberOfLines={1}>
85
+ {label}
86
+ </AtomicText>
87
+ </View>
88
+
89
+ <View style={{ flexDirection: "row", alignItems: "center", gap: tokens.spacing.xs }}>
90
+ {onMoveLayerUp && (
91
+ <TouchableOpacity
92
+ style={{ padding: tokens.spacing.xs, borderRadius: tokens.borders.radius.sm }}
93
+ onPress={() => onMoveLayerUp(layer.id)}
94
+ disabled={isTop}
95
+ accessibilityLabel="Move layer up"
96
+ accessibilityRole="button"
97
+ >
98
+ <AtomicIcon
99
+ name="chevron-forward"
100
+ size="sm"
101
+ color={isTop ? "textSecondary" : "textPrimary"}
102
+ />
103
+ </TouchableOpacity>
104
+ )}
105
+
106
+ {onMoveLayerDown && (
107
+ <TouchableOpacity
108
+ style={{ padding: tokens.spacing.xs, borderRadius: tokens.borders.radius.sm }}
109
+ onPress={() => onMoveLayerDown(layer.id)}
110
+ disabled={isBottom}
111
+ accessibilityLabel="Move layer down"
112
+ accessibilityRole="button"
113
+ >
114
+ <AtomicIcon
115
+ name="chevron-back"
116
+ size="sm"
117
+ color={isBottom ? "textSecondary" : "textPrimary"}
118
+ />
119
+ </TouchableOpacity>
120
+ )}
121
+
122
+ {onDuplicateLayer && (
123
+ <TouchableOpacity
124
+ style={{ padding: tokens.spacing.xs, borderRadius: tokens.borders.radius.sm }}
125
+ onPress={() => onDuplicateLayer(layer.id)}
126
+ accessibilityLabel={`Duplicate ${label}`}
127
+ accessibilityRole="button"
128
+ >
129
+ <AtomicIcon name="copy" size="sm" color="textSecondary" />
130
+ </TouchableOpacity>
131
+ )}
132
+
133
+ <TouchableOpacity
134
+ style={{ padding: tokens.spacing.xs, borderRadius: tokens.borders.radius.sm }}
135
+ onPress={() => onDeleteLayer(layer.id)}
136
+ accessibilityLabel={`Delete ${label}`}
137
+ accessibilityRole="button"
138
+ >
139
+ <AtomicIcon name="trash-outline" size="sm" color="error" />
140
+ </TouchableOpacity>
141
+ </View>
142
+ </TouchableOpacity>
143
+ );
144
+ })
145
+ )}
146
+ </ScrollView>
147
+ </View>
148
+ );
149
+ });
150
+
151
+ LayerManager.displayName = "LayerManager";
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Sticker Picker Sheet Component
3
+ * Bottom sheet for selecting stickers
4
+ */
5
+
6
+ import React, { memo } from "react";
7
+ import { View, TouchableOpacity, StyleSheet } from "react-native";
8
+ import { AtomicText } from "@umituz/react-native-design-system/atoms";
9
+ import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
10
+
11
+ const DEFAULT_STICKERS = [
12
+ "😀", "😂", "🤣", "😍", "🥰", "😎", "🤯", "🥳", "😤", "💀",
13
+ "🔥", "❤️", "💯", "✨", "🎉", "🤡", "👀", "🙌", "👏", "💪",
14
+ "🤝", "🙈", "🐶", "🐱", "🦊", "🐸", "🌟", "⭐", "🌈", "☀️",
15
+ "🌙", "💫",
16
+ ];
17
+
18
+ interface StickerPickerProps {
19
+ onSelectSticker: (sticker: string) => void;
20
+ stickers?: readonly string[];
21
+ }
22
+
23
+ export const StickerPicker = memo<StickerPickerProps>(({
24
+ onSelectSticker,
25
+ stickers = DEFAULT_STICKERS,
26
+ }) => {
27
+ const tokens = useAppDesignTokens();
28
+
29
+ return (
30
+ <View style={styles.container}>
31
+ <AtomicText type="headlineSmall" style={{ marginBottom: tokens.spacing.md }}>
32
+ Stickers
33
+ </AtomicText>
34
+ <View style={styles.grid}>
35
+ {stickers.map((sticker) => (
36
+ <TouchableOpacity
37
+ key={sticker}
38
+ style={{
39
+ width: 60,
40
+ height: 60,
41
+ borderRadius: tokens.borders.radius.md,
42
+ backgroundColor: tokens.colors.surfaceVariant,
43
+ alignItems: "center",
44
+ justifyContent: "center",
45
+ }}
46
+ onPress={() => onSelectSticker(sticker)}
47
+ accessibilityLabel={`Sticker ${sticker}`}
48
+ accessibilityRole="button"
49
+ >
50
+ <AtomicText style={{ fontSize: 36 }}>{sticker}</AtomicText>
51
+ </TouchableOpacity>
52
+ ))}
53
+ </View>
54
+ </View>
55
+ );
56
+ });
57
+
58
+ StickerPicker.displayName = "StickerPicker";
59
+
60
+ const styles = StyleSheet.create({
61
+ container: { padding: 16, gap: 16 },
62
+ grid: {
63
+ flexDirection: "row",
64
+ flexWrap: "wrap",
65
+ gap: 12,
66
+ },
67
+ });
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Text Editor Sheet Component
3
+ * Bottom sheet for editing text layers
4
+ */
5
+
6
+ import React, { memo } from "react";
7
+ import { View, TextInput, TouchableOpacity, StyleSheet } from "react-native";
8
+ import { AtomicText, AtomicButton } from "@umituz/react-native-design-system/atoms";
9
+ import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
10
+ import { ColorPicker } from "../ui/ColorPicker";
11
+ import type { TextAlign } from "../../../domain/entities/Layer";
12
+
13
+ interface TextEditorSheetProps {
14
+ value: string;
15
+ onChange: (text: string) => void;
16
+ onSave: () => void;
17
+ t: (key: string) => string;
18
+ color?: string;
19
+ onColorChange?: (color: string) => void;
20
+ textAlign?: TextAlign;
21
+ onTextAlignChange?: (align: TextAlign) => void;
22
+ isBold?: boolean;
23
+ onBoldChange?: (bold: boolean) => void;
24
+ isItalic?: boolean;
25
+ onItalicChange?: (italic: boolean) => void;
26
+ }
27
+
28
+ const ALIGN_OPTIONS: { value: TextAlign; icon: string }[] = [
29
+ { value: "left", icon: "«" },
30
+ { value: "center", icon: "≡" },
31
+ { value: "right", icon: "»" },
32
+ ];
33
+
34
+ const StyleButton = memo<{ label: string; isActive: boolean; onPress: () => void; children: React.ReactNode }>(
35
+ ({ label, isActive, onPress, children }) => {
36
+ const tokens = useAppDesignTokens();
37
+
38
+ return (
39
+ <TouchableOpacity
40
+ style={{
41
+ width: 44,
42
+ height: 44,
43
+ borderRadius: tokens.borders.radius.sm,
44
+ borderWidth: 1.5,
45
+ borderColor: isActive ? tokens.colors.primary : tokens.colors.border,
46
+ alignItems: "center",
47
+ justifyContent: "center",
48
+ backgroundColor: isActive ? tokens.colors.primary + "20" : tokens.colors.surfaceVariant,
49
+ }}
50
+ onPress={onPress}
51
+ accessibilityLabel={label}
52
+ accessibilityRole="button"
53
+ accessibilityState={{ selected: isActive }}
54
+ >
55
+ {children}
56
+ </TouchableOpacity>
57
+ );
58
+ }
59
+ );
60
+
61
+ StyleButton.displayName = "StyleButton";
62
+
63
+ export const TextEditorSheet = memo<TextEditorSheetProps>(({
64
+ value,
65
+ onChange,
66
+ onSave,
67
+ t,
68
+ color = "#FFFFFF",
69
+ onColorChange,
70
+ textAlign = "center",
71
+ onTextAlignChange,
72
+ isBold = false,
73
+ onBoldChange,
74
+ isItalic = false,
75
+ onItalicChange,
76
+ }) => {
77
+ const tokens = useAppDesignTokens();
78
+
79
+ return (
80
+ <View style={styles.container}>
81
+ <AtomicText type="headlineSmall">{t("photo_editor.add_text") || "Edit Text"}</AtomicText>
82
+
83
+ <TextInput
84
+ value={value}
85
+ onChangeText={onChange}
86
+ placeholder={t("photo_editor.tap_to_edit") || "Enter text…"}
87
+ placeholderTextColor={tokens.colors.textSecondary}
88
+ style={styles.input}
89
+ multiline
90
+ autoFocus
91
+ />
92
+
93
+ <View style={styles.row}>
94
+ {onBoldChange && (
95
+ <StyleButton label="Bold" isActive={isBold} onPress={() => onBoldChange(!isBold)}>
96
+ <AtomicText fontWeight="bold" color={isBold ? "primary" : "textSecondary"}>
97
+ B
98
+ </AtomicText>
99
+ </StyleButton>
100
+ )}
101
+
102
+ {onItalicChange && (
103
+ <StyleButton label="Italic" isActive={isItalic} onPress={() => onItalicChange(!isItalic)}>
104
+ <AtomicText color={isItalic ? "primary" : "textSecondary"} style={{ fontStyle: "italic" }}>
105
+ I
106
+ </AtomicText>
107
+ </StyleButton>
108
+ )}
109
+
110
+ {onTextAlignChange && (
111
+ <View style={[styles.row, { marginLeft: tokens.spacing.sm }]}>
112
+ {ALIGN_OPTIONS.map(({ value: align, icon }) => (
113
+ <StyleButton
114
+ key={align}
115
+ label={`Align ${align}`}
116
+ isActive={textAlign === align}
117
+ onPress={() => onTextAlignChange(align)}
118
+ >
119
+ <AtomicText color={textAlign === align ? "primary" : "textSecondary"}>{icon}</AtomicText>
120
+ </StyleButton>
121
+ ))}
122
+ </View>
123
+ )}
124
+ </View>
125
+
126
+ {onColorChange && (
127
+ <ColorPicker
128
+ label="Text Color"
129
+ selectedColor={color}
130
+ onSelectColor={onColorChange}
131
+ />
132
+ )}
133
+
134
+ <AtomicButton variant="primary" onPress={onSave}>
135
+ {t("common.save") || "Save"}
136
+ </AtomicButton>
137
+ </View>
138
+ );
139
+ });
140
+
141
+ TextEditorSheet.displayName = "TextEditorSheet";
142
+
143
+ const styles = StyleSheet.create({
144
+ container: { padding: 16, gap: 16 },
145
+ input: {
146
+ backgroundColor: "#F5F5F5",
147
+ borderRadius: 8,
148
+ padding: 16,
149
+ fontSize: 18,
150
+ color: "#000",
151
+ textAlign: "center",
152
+ minHeight: 90,
153
+ },
154
+ row: {
155
+ flexDirection: "row",
156
+ alignItems: "center",
157
+ gap: 8,
158
+ },
159
+ });
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Color Picker Component
3
+ * Grid of color options
4
+ */
5
+
6
+ import React, { memo } from "react";
7
+ import { View, TouchableOpacity, StyleSheet } from "react-native";
8
+ import { AtomicText } from "@umituz/react-native-design-system/atoms";
9
+ import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
10
+
11
+ const DEFAULT_COLORS = [
12
+ "#FFFFFF", "#000000", "#888888", "#CCCCCC",
13
+ "#FF3B30", "#FF9500", "#FFCC00", "#FF2D55",
14
+ "#34C759", "#30B0C7", "#007AFF", "#5AC8FA",
15
+ "#5856D6", "#AF52DE", "#FF6B6B", "#FFD93D",
16
+ "#6BCB77", "#4D96FF", "#C77DFF", "#F72585",
17
+ ];
18
+
19
+ interface ColorPickerProps {
20
+ label?: string;
21
+ selectedColor: string;
22
+ onSelectColor: (color: string) => void;
23
+ colors?: readonly string[];
24
+ }
25
+
26
+ export const ColorPicker = memo<ColorPickerProps>(({
27
+ label,
28
+ selectedColor,
29
+ onSelectColor,
30
+ colors = DEFAULT_COLORS,
31
+ }) => {
32
+ const tokens = useAppDesignTokens();
33
+
34
+ return (
35
+ <View style={styles.container}>
36
+ {label && (
37
+ <AtomicText type="labelMedium" color="textSecondary" style={{ marginBottom: tokens.spacing.sm }}>
38
+ {label}
39
+ </AtomicText>
40
+ )}
41
+ <View style={styles.grid}>
42
+ {colors.map((color) => (
43
+ <TouchableOpacity
44
+ key={color}
45
+ style={[
46
+ styles.color,
47
+ {
48
+ backgroundColor: color,
49
+ borderWidth: selectedColor === color ? 3 : 1,
50
+ borderColor: selectedColor === color ? tokens.colors.primary : "#E0E0E0",
51
+ },
52
+ ]}
53
+ onPress={() => onSelectColor(color)}
54
+ accessibilityLabel={`Color ${color}`}
55
+ accessibilityRole="button"
56
+ accessibilityState={{ selected: selectedColor === color }}
57
+ />
58
+ ))}
59
+ </View>
60
+ </View>
61
+ );
62
+ });
63
+
64
+ ColorPicker.displayName = "ColorPicker";
65
+
66
+ const styles = StyleSheet.create({
67
+ container: { gap: 8 },
68
+ grid: {
69
+ flexDirection: "row",
70
+ flexWrap: "wrap",
71
+ gap: 12,
72
+ },
73
+ color: {
74
+ width: 36,
75
+ height: 36,
76
+ borderRadius: 18,
77
+ },
78
+ });
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Slider Component
3
+ * Custom slider for numeric values
4
+ */
5
+
6
+ import React, { memo, useRef, useState } from "react";
7
+ import { View } from "react-native";
8
+ import { Gesture, GestureDetector } from "react-native-gesture-handler";
9
+ import { AtomicText } from "@umituz/react-native-design-system/atoms";
10
+ import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
11
+
12
+ interface SliderProps {
13
+ label: string;
14
+ value: number;
15
+ min: number;
16
+ max: number;
17
+ step?: number;
18
+ onValueChange: (val: number) => void;
19
+ formatValue?: (val: number) => string;
20
+ }
21
+
22
+ export const Slider = memo<SliderProps>(({
23
+ label,
24
+ value,
25
+ min,
26
+ max,
27
+ step = 0.05,
28
+ onValueChange,
29
+ formatValue,
30
+ }) => {
31
+ const tokens = useAppDesignTokens();
32
+ const [trackWidth, setTrackWidth] = useState(200);
33
+ const trackWidthRef = useRef(200);
34
+ const startValueRef = useRef(value);
35
+ const valueRef = useRef(value);
36
+ valueRef.current = value;
37
+
38
+ const clamp = (v: number) => Math.max(min, Math.min(max, v));
39
+ const snap = (v: number) => parseFloat((Math.round(v / step) * step).toFixed(4));
40
+
41
+ const panGesture = Gesture.Pan()
42
+ .runOnJS(true)
43
+ .onStart(() => {
44
+ startValueRef.current = valueRef.current;
45
+ })
46
+ .onUpdate((e) => {
47
+ const ratio = e.translationX / trackWidthRef.current;
48
+ const delta = ratio * (max - min);
49
+ onValueChange(snap(clamp(startValueRef.current + delta)));
50
+ });
51
+
52
+ const percent = Math.max(0, Math.min(1, (value - min) / (max - min)));
53
+ const thumbOffset = percent * trackWidth - 12;
54
+ const displayValue = formatValue ? formatValue(value) : value.toFixed(1);
55
+
56
+ return (
57
+ <View style={{ gap: tokens.spacing.xs }}>
58
+ <View
59
+ style={{
60
+ flexDirection: "row",
61
+ justifyContent: "space-between",
62
+ alignItems: "center",
63
+ }}
64
+ >
65
+ <AtomicText type="labelMedium" color="textSecondary">
66
+ {label}
67
+ </AtomicText>
68
+ <AtomicText type="labelMedium" color="primary" fontWeight="bold">
69
+ {displayValue}
70
+ </AtomicText>
71
+ </View>
72
+ <GestureDetector gesture={panGesture}>
73
+ <View
74
+ style={{ height: 44, justifyContent: "center", paddingHorizontal: 12 }}
75
+ onLayout={(e) => {
76
+ const w = Math.max(1, e.nativeEvent.layout.width - 24);
77
+ setTrackWidth(w);
78
+ trackWidthRef.current = w;
79
+ }}
80
+ >
81
+ <View
82
+ style={{
83
+ height: 4,
84
+ backgroundColor: tokens.colors.surfaceVariant,
85
+ borderRadius: 2,
86
+ }}
87
+ >
88
+ <View
89
+ style={{
90
+ width: `${percent * 100}%`,
91
+ height: "100%",
92
+ backgroundColor: tokens.colors.primary,
93
+ borderRadius: 2,
94
+ }}
95
+ />
96
+ </View>
97
+ <View
98
+ style={{
99
+ position: "absolute",
100
+ left: thumbOffset + 12,
101
+ width: 24,
102
+ height: 24,
103
+ borderRadius: 12,
104
+ backgroundColor: tokens.colors.primary,
105
+ borderWidth: 2.5,
106
+ borderColor: tokens.colors.surface,
107
+ top: 10,
108
+ }}
109
+ />
110
+ </View>
111
+ </GestureDetector>
112
+ </View>
113
+ );
114
+ });
115
+
116
+ Slider.displayName = "Slider";