expo-running-kit
Version:
Expo native module for tracking running and walking workouts — GPS, pace, cadence, auto-pause, and laps.
37 lines • 1.34 kB
JavaScript
import { useEffect, useRef } from "react";
import RunningKit from "../RunningKitModule";
export function useAutoPause({ enabled, cadence, sessionState, sessionStateRef, delay, resumeThreshold, }) {
const timerRef = useRef(null);
useEffect(() => {
if (!enabled)
return;
const state = sessionStateRef.current;
// Cadence dropped to zero → start auto-pause countdown
if (cadence === 0 && state === "active") {
if (!timerRef.current) {
timerRef.current = setTimeout(() => {
RunningKit.autoPauseWorkout();
timerRef.current = null;
}, delay * 1000);
}
}
// Movement detected → cancel pending countdown, or auto-resume
if (cadence >= resumeThreshold) {
if (timerRef.current) {
clearTimeout(timerRef.current);
timerRef.current = null;
}
if (state === "auto-paused") {
RunningKit.resumeWorkout();
}
}
}, [cadence, sessionState]);
function cancelAutoPause() {
if (timerRef.current) {
clearTimeout(timerRef.current);
timerRef.current = null;
}
}
return { cancelAutoPause };
}
//# sourceMappingURL=useAutoPause.js.map