Skip to content

Commit bf90a1d

Browse files
authored
Merge pull request #60 from sam-mfb/resize-warning
Improve resize hint UX
2 parents 41b13ab + 379e6b8 commit bf90a1d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/game/App.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,32 @@ export const App: React.FC<AppProps> = ({
6565
return
6666
}
6767

68+
// Don't show on mobile devices where window resizing isn't possible
69+
const isTouchDevice =
70+
'ontouchstart' in window || navigator.maxTouchPoints > 0
71+
const isSmallScreen =
72+
window.screen.width < 768 || window.screen.height < 768
73+
const isMobile = isTouchDevice && isSmallScreen
74+
75+
if (isMobile) {
76+
setShowResizeHint(false)
77+
return
78+
}
79+
6880
const availableWidth = window.innerWidth - VIEWPORT_PADDING * 2
6981
const availableHeight = window.innerHeight - VIEWPORT_PADDING * 2
7082

83+
// Don't show if there isn't enough vertical space below the game for the hint
84+
// Calculate space below the game canvas
85+
const spaceBelow = availableHeight - dimensions.totalHeight
86+
// The hint needs about 120px of clearance (bottom: 20px + sufficient space for hint with padding/text)
87+
const hasVerticalSpace = spaceBelow >= 120
88+
89+
if (!hasVerticalSpace) {
90+
setShowResizeHint(false)
91+
return
92+
}
93+
7194
// 25% of the way from 1x to 2x
7295
const widthThreshold = BASE_GAME_WIDTH * 1.25
7396
const heightThreshold = BASE_TOTAL_HEIGHT * 1.25
@@ -90,7 +113,7 @@ export const App: React.FC<AppProps> = ({
90113
window.removeEventListener('resize', checkResizeHint)
91114
window.removeEventListener('orientationchange', checkResizeHint)
92115
}
93-
}, [scaleMode, scale])
116+
}, [scaleMode, scale, dimensions.totalHeight])
94117

95118
// Render the game content based on mode
96119
const renderGameContent = (): React.ReactElement | null => {

0 commit comments

Comments
 (0)