fix repeated click duplicate pages (#43)
This commit is contained in:
parent
be19a39127
commit
4ef5c1cab9
|
|
@ -1,5 +1,34 @@
|
|||
import { Stack } from "expo-router";
|
||||
import { router, Stack } from "expo-router";
|
||||
import React from "react";
|
||||
|
||||
// ============================================================================
|
||||
// GLOBAL NAVIGATION THROTTLE (Generic Fix for Repeated Click / Double Navigation)
|
||||
// ============================================================================
|
||||
const NAVIGATION_THROTTLE_MS = 700;
|
||||
let lastNavigationTimestamp = 0;
|
||||
|
||||
const originalPush = router.push.bind(router);
|
||||
const originalNavigate = router.navigate.bind(router);
|
||||
|
||||
router.push = ((...args: Parameters<typeof originalPush>) => {
|
||||
const now = Date.now();
|
||||
if (now - lastNavigationTimestamp < NAVIGATION_THROTTLE_MS) {
|
||||
return;
|
||||
}
|
||||
lastNavigationTimestamp = now;
|
||||
return originalPush(...args);
|
||||
}) as typeof router.push;
|
||||
|
||||
router.navigate = ((...args: Parameters<typeof originalNavigate>) => {
|
||||
const now = Date.now();
|
||||
if (now - lastNavigationTimestamp < NAVIGATION_THROTTLE_MS) {
|
||||
return;
|
||||
}
|
||||
lastNavigationTimestamp = now;
|
||||
return originalNavigate(...args);
|
||||
}) as typeof router.navigate;
|
||||
// ============================================================================
|
||||
|
||||
import * as RN from "react-native";
|
||||
import {
|
||||
useFonts,
|
||||
|
|
|
|||
Loading…
Reference in New Issue