Skip to content

Commit 048f823

Browse files
authored
fix: improve Apple Watch detection with multi-heuristic approach (#285)
* fix: expand Apple Watch detection to cover all model resolutions * fix: improve Apple Watch detection with multi-heuristic approach * fix: add proper dependencies to Map2D useMemo to prevent stale route data
1 parent 09fe47f commit 048f823

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/components/Charts/Map2D/Map2D.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function Map2DChartComponent({
287287
series,
288288
};
289289
// eslint-disable-next-line react-hooks/exhaustive-deps
290-
}, [mapLoaded]); // Only recalculate when map loads - after that we update via setOption
290+
}, [mapLoaded, routes, showEffect, lineColor, title]); // Recalculate when key props change
291291

292292
// Don't render until map is loaded
293293
if (!mapLoaded) {

src/routes/__root.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,28 @@ function RootComponent(): JSX.Element {
120120
const [isAppleWatch, setIsAppleWatch] = useState(false);
121121
const router = useRouter();
122122

123-
// Detect Apple Watch screen size (312-416px wide across all models)
123+
// Detect Apple Watch using multiple heuristics
124+
// Apple Watch reports as iPhone but has distinctive screen dimensions
124125
useEffect(() => {
125-
const checkScreenSize = (): void => {
126-
setIsAppleWatch(window.innerWidth <= 416);
126+
const checkIsAppleWatch = (): void => {
127+
const isIOS = /iPhone/.test(navigator.userAgent);
128+
const screenWidth = window.innerWidth;
129+
const screenHeight = window.innerHeight;
130+
131+
// Apple Watch specific dimensions (all models: 312-416px wide, 340-502px tall)
132+
// Exclude iPhone dimensions which start at 375px wide minimum (iPhone SE)
133+
const isWatchWidth = screenWidth >= 312 && screenWidth <= 416;
134+
const isWatchHeight = screenHeight >= 340 && screenHeight <= 502;
135+
const isTooSmallForPhone = screenWidth < 375; // iPhones are 375px+ wide
136+
137+
setIsAppleWatch(isIOS && isWatchWidth && isWatchHeight && isTooSmallForPhone);
127138
};
128139

129-
checkScreenSize();
130-
window.addEventListener('resize', checkScreenSize);
140+
checkIsAppleWatch();
141+
window.addEventListener('resize', checkIsAppleWatch);
131142

132143
return () => {
133-
window.removeEventListener('resize', checkScreenSize);
144+
window.removeEventListener('resize', checkIsAppleWatch);
134145
};
135146
}, []);
136147

0 commit comments

Comments
 (0)