-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
69 lines (52 loc) · 2.3 KB
/
Copy pathindex.tsx
File metadata and controls
69 lines (52 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
const rootElement = document.getElementById('root');
if (!rootElement) {
throw new Error("Could not find root element to mount to");
}
const root = ReactDOM.createRoot(rootElement);
root.render(
<App />
);
// Custom touch-to-click handler for iOS (FastClick replacement)
// Run on Native Platform OR on Mobile Web (iPhone/Android)
const isMobileWeb = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
const isNative = typeof window !== 'undefined' && (window as any).Capacitor?.isNativePlatform?.();
if (isNative || isMobileWeb) {
console.log('🔍 DIAGNOSTIC: Enabling custom touch handler (isNative:', isNative, 'isMobileWeb:', isMobileWeb, ')');
//Modern touch-to-click converter
let touchStartTime = 0;
let touchStartTarget: EventTarget | null = null;
document.addEventListener('touchstart', (e) => {
touchStartTime = Date.now();
touchStartTarget = e.target;
console.log('👆 TOUCHSTART:', (e.target as HTMLElement)?.tagName);
}, true);
document.addEventListener('touchend', (e) => {
const touchDuration = Date.now() - touchStartTime;
console.log('✋ TOUCHEND:', (e.target as HTMLElement)?.tagName, `Duration: ${touchDuration}ms`);
// Only fire click if it was a quick tap (< 200ms) and on the same element
if (touchDuration < 200 && touchStartTarget === e.target) {
const target = e.target as HTMLElement;
const tagName = target.tagName.toLowerCase();
// Don't prevent default for input elements - they need native focus behavior
const isInputElement = tagName === 'input' || tagName === 'textarea' || tagName === 'select';
if (isInputElement) {
console.log('⌨️ ALLOWING NATIVE FOCUS for:', target.tagName);
return; // Let native behavior handle inputs
}
e.preventDefault(); // Prevent the delayed click for non-input elements
// Create and dispatch a synthetic click event
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window,
composed: true
});
target.dispatchEvent(clickEvent);
console.log('🔵 SYNTHETIC CLICK fired for:', target.tagName);
}
}, true);
console.log('✅ Custom touch-to-click handler initialized');
}