Skip to content

Commit a27f3f5

Browse files
committed
fix: continuous player mode not working
1 parent 50217d4 commit a27f3f5

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

example/src/components/ContinuousPalette.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Animated, {
88
clamp,
99
} from 'react-native-reanimated';
1010
import {
11+
createContinuousPlayer,
1112
startContinuousPlayer,
1213
stopContinuousPlayer,
1314
updateContinuousPlayer,
@@ -45,6 +46,8 @@ const normalizeCoordinates = (x: number, y: number, size: number) => {
4546
};
4647
};
4748

49+
createContinuousPlayer(INITIAL_INTENSITY, INITIAL_SHARPNESS);
50+
4851
export default function ContinuousPalette({
4952
size,
5053
colors,

example/src/components/MiniContinuousPalette.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Animated, {
99
type SharedValue,
1010
} from 'react-native-reanimated';
1111
import {
12+
createContinuousPlayer,
1213
startContinuousPlayer,
1314
stopContinuousPlayer,
1415
updateContinuousPlayer,
@@ -18,6 +19,8 @@ const TOUCH_INDICATOR_SIZE = 30;
1819
const INITIAL_INTENSITY = 1.0;
1920
const INITIAL_SHARPNESS = 0.5;
2021

22+
createContinuousPlayer(INITIAL_INTENSITY, INITIAL_SHARPNESS);
23+
2124
interface MiniContinuousPaletteProps {
2225
size: number;
2326
resetTrigger?: SharedValue<number>;

example/src/schemas/recordingSchema.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,27 @@ const hapticEventParameterSchema = z.object({
66
value: z.number().min(0).max(1),
77
});
88

9-
// Schema for haptic events
10-
const hapticEventSchema = z.object({
11-
type: z.enum(['transient', 'continuous']),
9+
// Schema for transient haptic event
10+
const transientHapticEventSchema = z.object({
11+
type: z.literal('transient'),
1212
parameters: z.array(hapticEventParameterSchema),
1313
relativeTime: z.number().min(0),
14-
duration: z.number().min(0).optional(),
1514
});
1615

16+
// Schema for continuous haptic event
17+
const continuousHapticEventSchema = z.object({
18+
type: z.literal('continuous'),
19+
parameters: z.array(hapticEventParameterSchema),
20+
relativeTime: z.number().min(0),
21+
duration: z.number().min(0),
22+
});
23+
24+
// Discriminated union for haptic events
25+
const hapticEventSchema = z.discriminatedUnion('type', [
26+
transientHapticEventSchema,
27+
continuousHapticEventSchema,
28+
]);
29+
1730
// Schema for haptic curve control points
1831
const hapticCurveControlPointSchema = z.object({
1932
relativeTime: z.number().min(0),

example/src/types/recording.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { HapticEvent, HapticCurve } from 'react-native-ahaps';
1+
import type { HapticCurve, HapticEvent } from 'react-native-ahaps';
22

33
export interface RecordedHaptic {
44
id: string;
55
name: string;
66
createdAt: number;
7-
duration: number; // in seconds
7+
duration: number;
88
events: HapticEvent[];
99
curves: HapticCurve[];
1010
}
@@ -15,7 +15,7 @@ export interface RecordingEvent {
1515
| 'continuous_start'
1616
| 'continuous_update'
1717
| 'continuous_end';
18-
timestamp: number; // relative to recording start in seconds
18+
timestamp: number;
1919
intensity: number;
2020
sharpness: number;
2121
}

0 commit comments

Comments
 (0)