Skip to content

Commit 96a15c5

Browse files
committed
no ios scroll
1 parent 73662ca commit 96a15c5

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

src/app/PuzzleClient.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ function useGridSize() {
3232
return gridSize;
3333
}
3434

35+
function useContainerSize() {
36+
const [containerSize, setContainerSize] = useState(0);
37+
38+
useEffect(() => {
39+
function updateSize() {
40+
const maxWidth = window.innerWidth - 32;
41+
const maxHeight = window.innerHeight - 64;
42+
setContainerSize(Math.min(maxWidth, maxHeight));
43+
}
44+
updateSize();
45+
window.addEventListener("resize", updateSize);
46+
return () => window.removeEventListener("resize", updateSize);
47+
}, []);
48+
49+
return containerSize;
50+
}
51+
3552
const ALL_FACTS = [
3653
// 1
3754
`Zak King <a href="mailto:[email protected]">[email protected]</a>`,
@@ -120,10 +137,10 @@ function isPuzzleSolved(tiles: (number | null)[]) {
120137

121138
export default function PuzzleClient() {
122139
const gridSize = useGridSize();
140+
const containerSize = useContainerSize();
123141
const resumeFacts = useMemo(() => getFactsForGridSize(gridSize), [gridSize]);
124142
const puzzleImages = useMemo(() => getPuzzleImages(gridSize), [gridSize]);
125143
const [tiles, setTiles] = useState<(number | null)[]>([]);
126-
const [containerSize, setContainerSize] = useState(0);
127144
const [tileOffsets, setTileOffsets] = useState<{ x: number; y: number }[]>(
128145
[]
129146
);
@@ -155,17 +172,6 @@ export default function PuzzleClient() {
155172
setIsWon(false); // reset if grid changes
156173
}, [puzzleImages, gridSize]);
157174

158-
useEffect(() => {
159-
function updateSize() {
160-
const maxWidth = window.innerWidth - 8;
161-
const maxHeight = window.innerHeight - 8;
162-
setContainerSize(Math.min(maxWidth, maxHeight));
163-
}
164-
updateSize();
165-
window.addEventListener("resize", updateSize);
166-
return () => window.removeEventListener("resize", updateSize);
167-
}, []);
168-
169175
// Whenever tiles change, check if puzzle is solved
170176
useEffect(() => {
171177
if (!isWon && isPuzzleSolved(tiles)) {
@@ -346,7 +352,7 @@ export default function PuzzleClient() {
346352
newLeft = baseX;
347353
}
348354

349-
// clamp so tile cant move beyond 1 tile distance
355+
// clamp so tile can't move beyond 1 tile distance
350356
if (axis === "x") {
351357
if (direction === 1) {
352358
newLeft = Math.max(newLeft, baseX);
@@ -413,7 +419,7 @@ export default function PuzzleClient() {
413419
// Render puzzle
414420
// ------------------------------------------------------
415421
return (
416-
<div className="min-h-screen w-screen flex items-center justify-center relative">
422+
<div className="w-screen min-h-[100dvh] flex items-center justify-center relative p-4 md:p-8">
417423
{isWon && (
418424
<>
419425
<Confetti
@@ -436,8 +442,8 @@ export default function PuzzleClient() {
436442
className="border"
437443
style={{
438444
position: "relative",
439-
width: gridSize * tileSize,
440-
height: gridSize * tileSize,
445+
width: containerSize,
446+
height: containerSize,
441447
}}
442448
>
443449
{/* Bottom layer: NxN facts */}
@@ -529,12 +535,15 @@ export default function PuzzleClient() {
529535
}
530536
html {
531537
color-scheme: light dark;
538+
height: 100%;
532539
}
533540
body {
534541
margin: 0;
535542
background-color: #fdfdfd;
536543
color: #333;
537544
padding: 0;
545+
min-height: 100%;
546+
overscroll-behavior: none; /* Prevent bounce on iOS */
538547
}
539548
@media (prefers-color-scheme: dark) {
540549
body {
@@ -543,8 +552,8 @@ export default function PuzzleClient() {
543552
}
544553
}
545554
.draggable {
546-
touch-action: none; /* prevent scrolling on mobile */
547-
user-select: none; /* prevent text highlighting */
555+
touch-action: none;
556+
user-select: none;
548557
}
549558
`}</style>
550559
</div>

0 commit comments

Comments
 (0)