Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import Animated, {
useSharedValue,
useAnimatedStyle,
runOnJS,
withTiming,
} from 'react-native-reanimated';

Expand Down Expand Up @@ -42,7 +41,6 @@ interface JoystickData {
}

const getDirection = (angleDeg: number): string => {
'worklet';
if (
(angleDeg >= 337.5 && angleDeg <= 360) ||
(angleDeg >= 0 && angleDeg < 22.5)
Expand Down Expand Up @@ -104,14 +102,13 @@ export const Joystick: React.FC<JoystickProps> = React.memo(
const panGesture = useMemo(
() =>
Gesture.Pan()
.runOnJS(true)
.onBegin(() => {
'worklet';
if (haptics && Haptics) {
runOnJS(Haptics.impactAsync)(Haptics.ImpactFeedbackStyle.Heavy);
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy);
}
})
.onUpdate((event: { translationX: any; translationY: any }) => {
'worklet';
const rawX = event.translationX;
const rawY = event.translationY;
const distance = Math.sqrt(rawX ** 2 + rawY ** 2);
Expand All @@ -136,7 +133,7 @@ export const Joystick: React.FC<JoystickProps> = React.memo(
const normalizedX = (newX / BOUNDARY_RADIUS) * size;
const normalizedY = -(newY / BOUNDARY_RADIUS) * size;

runOnJS(debouncedOnMove)({
debouncedOnMove({
position: {
x: Math.max(-size, Math.min(size, normalizedX)),
y: Math.max(-size, Math.min(size, normalizedY)),
Expand All @@ -155,7 +152,7 @@ export const Joystick: React.FC<JoystickProps> = React.memo(
translateX.value = withTiming(0, { duration: 300 });
translateY.value = withTiming(0, { duration: 300 });
if (onEnd) {
runOnJS(onEnd)();
onEnd();
}
}),
[
Expand Down
Loading