Skip to content

Commit eb219df

Browse files
[mobileWallLayout] Fix layout applying to narrow desktop windows (#692)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 311495f commit eb219df

2 files changed

Lines changed: 35 additions & 34 deletions

File tree

plugins/mobileWallLayout/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ making marker previews and images easy to scroll through on a phone.
1313

1414
## Behaviour
1515

16-
- Applies only when `window.innerWidth ≤ 960px` — covers all current phones
17-
including large flagships in landscape (e.g. iPhone 16 Pro Max: 932px,
18-
Galaxy S24 Ultra: 915px), while excluding tablets (iPad mini landscape: 1024px).
16+
- Applies only on **touch-screen devices** (`pointer: coarse`) — correctly
17+
targets phones and tablets without triggering on narrow desktop browser windows.
1918
- Activates and deactivates automatically as you navigate between pages.
20-
- Re-evaluates on orientation change (portrait ↔ landscape).
21-
- Has no effect on desktop or tablet viewports.
19+
- Has no effect on desktop or mouse-driven viewports.
2220

2321
## Implementation note
2422

25-
The fix injects a `<style>` tag with `!important` rules rather than setting
26-
inline styles via JavaScript. This is necessary because `react-photo-gallery`
27-
continuously recalculates and re-applies its own inline styles; a CSS rule with
28-
`!important` wins unconditionally regardless of render timing.
23+
The fix injects a `<style>` tag with `!important` rules wrapped in a
24+
`@media (pointer: coarse)` query, rather than setting inline styles via
25+
JavaScript or checking `window.innerWidth` at runtime. This is necessary
26+
because `react-photo-gallery` continuously recalculates and re-applies its own
27+
inline styles; a CSS rule with `!important` wins unconditionally regardless of
28+
render timing. Using `pointer: coarse` instead of a pixel-width threshold
29+
prevents the fix from activating on narrow desktop windows.

plugins/mobileWallLayout/mobileWallLayout.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,42 @@
2424
// inline styles regardless of render timing, avoiding the race condition that
2525
// JS-based inline overrides suffer from.
2626
//
27-
// The 960px threshold covers all current phones including large flagships in
28-
// landscape (e.g. iPhone 16 Pro Max: 932px, Galaxy S24 Ultra: 915px) while
29-
// excluding tablets (iPad mini landscape: 1024px). The resize listener ensures
30-
// the fix is applied/removed correctly on orientation change.
27+
// Device targeting uses `pointer: coarse` (touchscreens) rather than a pixel
28+
// width threshold. A width-only check (e.g. <= 960px) also triggers on narrow
29+
// desktop windows; pointer coarseness correctly identifies touch devices
30+
// regardless of window size, and CSS media queries re-evaluate automatically on
31+
// any relevant change — no JS resize listener needed.
3132

3233
var _imagesStyleTag = null;
3334

3435
// Uses !important throughout so these rules win over react-photo-gallery's
3536
// inline `style="position:absolute; top:Xpx; left:Ypx"` attributes.
37+
// Wrapped in a pointer:coarse media query so the rules are inert on desktop.
3638
var _IMAGES_CSS = [
37-
'div.react-photo-gallery--gallery {',
38-
' display: block !important;',
39-
'}',
40-
'.wall-item {',
41-
' position: relative !important;', /* pull items back into normal flow */
42-
' width: 100% !important;',
43-
' height: auto !important;',
44-
' top: auto !important;', /* neutralise calculated pixel offsets */
45-
' left: auto !important;',
46-
' display: block !important;',
47-
' margin-bottom: 10px !important;',
48-
'}',
49-
'.wall-item img, .wall-item video {',
50-
' width: 100% !important;',
51-
' height: auto !important;',
52-
' object-fit: contain !important;',
39+
'@media (pointer: coarse) {',
40+
' div.react-photo-gallery--gallery {',
41+
' display: block !important;',
42+
' }',
43+
' .wall-item {',
44+
' position: relative !important;', /* pull items back into normal flow */
45+
' width: 100% !important;',
46+
' height: auto !important;',
47+
' top: auto !important;', /* neutralise calculated pixel offsets */
48+
' left: auto !important;',
49+
' display: block !important;',
50+
' margin-bottom: 10px !important;',
51+
' }',
52+
' .wall-item img, .wall-item video {',
53+
' width: 100% !important;',
54+
' height: auto !important;',
55+
' object-fit: contain !important;',
56+
' }',
5357
'}'
5458
].join('\n');
5559

5660
function updateImagesPageFix() {
5761
var href = window.location.href;
58-
var onTargetPage = (href.includes('/images') || href.includes('scenes/markers'))
59-
&& window.innerWidth <= 960;
62+
var onTargetPage = href.includes('/images') || href.includes('scenes/markers');
6063

6164
if (onTargetPage && !_imagesStyleTag) {
6265
// Entering images or markers page — inject the fix
@@ -79,8 +82,5 @@ function updateImagesPageFix() {
7982
var observer = new MutationObserver(updateImagesPageFix);
8083
observer.observe(document.body, { childList: true, subtree: true });
8184

82-
// Re-evaluate on orientation change (portrait ↔ landscape)
83-
window.addEventListener('resize', updateImagesPageFix);
84-
8585
// Run immediately for whichever page is loaded first
8686
updateImagesPageFix();

0 commit comments

Comments
 (0)