// src/components/HiddenDevMenu/index.tsx import React, { useState, useRef } from 'react'; import { View, Modal, TouchableOpacity, Dimensions, SafeAreaView, GestureResponderEvent } from 'react-native'; import { ThemedText } from '../ThemedText'; import Settings from '../../modules/core/settings'; import { styles } from './styles'; interface HiddenDevMenuProps { children: React.ReactNode; } const HiddenDevMenu: React.FC = ({ children }) => { const [isDevMenuVisible, setIsDevMenuVisible] = useState(false); const [gestureMode, setGestureMode] = useState(false); const [leftTaps, setLeftTaps] = useState(0); const [rightTaps, setRightTaps] = useState(0); const [showDebugInfo, setShowDebugInfo] = useState(false); // Get screen dimensions const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); // Gesture zone settings - very narrow edge zones const edgeZoneWidth = 16; // Width of left/right zones (just the padding area) const edgeZoneHeight = 120; // Height of zones // Refs for timeouts const gestureModeTimeoutRef = useRef(null); const sequenceTimeoutRef = useRef(null); // Reset gesture mode const resetGestureMode = () => { setGestureMode(false); setLeftTaps(0); setRightTaps(0); if (gestureModeTimeoutRef.current) { clearTimeout(gestureModeTimeoutRef.current); } if (sequenceTimeoutRef.current) { clearTimeout(sequenceTimeoutRef.current); } }; // Activate gesture mode for 3 seconds const activateGestureMode = () => { setGestureMode(true); setLeftTaps(0); setRightTaps(0); if (showDebugInfo) { console.log('Gesture mode activated'); } // Clear existing timeout if (gestureModeTimeoutRef.current) { clearTimeout(gestureModeTimeoutRef.current); } // Set 3-second timeout gestureModeTimeoutRef.current = setTimeout(() => { resetGestureMode(); if (showDebugInfo) { console.log('Gesture mode timeout'); } }, 3000); }; // Handle dead taps (taps that don't hit interactive elements) const handleBackgroundTap = (event: GestureResponderEvent) => { // Only activate gesture mode if we're not already in it if (!gestureMode) { activateGestureMode(); } }; // Handle left edge taps const handleLeftTap = () => { if (!gestureMode) return; const newLeftTaps = leftTaps + 1; setLeftTaps(newLeftTaps); if (showDebugInfo) { console.log(`Left taps: ${newLeftTaps}`); } // Clear ALL existing timeouts and reset the main 3-second timer if (gestureModeTimeoutRef.current) { clearTimeout(gestureModeTimeoutRef.current); } if (sequenceTimeoutRef.current) { clearTimeout(sequenceTimeoutRef.current); } // Reset the main 3-second gesture mode timeout gestureModeTimeoutRef.current = setTimeout(() => { resetGestureMode(); if (showDebugInfo) { console.log('Gesture mode timeout after left tap'); } }, 3000); // Check if we completed left sequence if (newLeftTaps >= 3) { if (showDebugInfo) { console.log('Left sequence complete, waiting for right taps...'); } } }; // Handle right edge taps const handleRightTap = () => { if (!gestureMode || leftTaps < 3) return; const newRightTaps = rightTaps + 1; setRightTaps(newRightTaps); if (showDebugInfo) { console.log(`Right taps: ${newRightTaps}`); } // Clear ALL existing timeouts and reset the main 3-second timer if (gestureModeTimeoutRef.current) { clearTimeout(gestureModeTimeoutRef.current); } if (sequenceTimeoutRef.current) { clearTimeout(sequenceTimeoutRef.current); } // Check if sequence is complete if (newRightTaps >= 3) { if (showDebugInfo) { console.log('Sequence complete! Opening dev menu...'); } setIsDevMenuVisible(true); resetGestureMode(); } else { // Reset the main 3-second gesture mode timeout gestureModeTimeoutRef.current = setTimeout(() => { resetGestureMode(); if (showDebugInfo) { console.log('Gesture mode timeout after right tap'); } }, 3000); } }; const closeDevMenu = () => { setIsDevMenuVisible(false); }; return ( {/* Main app content - no touch interference */} {children} {/* Larger activation zones - top corners for manual gesture mode activation */} {!gestureMode && ( <> )} {/* Left gesture zone - only visible when gesture mode is active */} {gestureMode && ( )} {/* Right gesture zone - only visible when gesture mode is active */} {gestureMode && ( )} {/* Debug indicator */} {gestureMode && showDebugInfo && ( Gesture Mode: L:{leftTaps}/3 R:{rightTaps}/3 )} {/* Developer Menu Modal */} ); }; export default HiddenDevMenu;