From 012da3d2012df3031a3c232b2305895e28acb6dc Mon Sep 17 00:00:00 2001 From: Masashi Katsumata Date: Thu, 12 Nov 2026 21:48:13 -0800 Subject: [PATCH] Fit the samples to a phone screen On a phone the map stage sat under the page title and two paragraphs, and an open control panel covered most of it; there was no way to see the map alone. - Under 760 px: one line of title (the description stays in the page but takes no room), and a stage that ends at the bottom of the screen. - ControlPanel's title folds the panel. Until it is pressed the width decides in CSS: open on a desktop, folded to its title on a phone; opened there it takes at most 55% of the stage and scrolls. Folding only hides the body, so the controls keep their state. - A full screen button on the stage: the Fullscreen API, or the stage fixed over the page where there is none (iPhone Safari). Escape leaves. Camera Sync keeps its own. - Camera Sync keeps only the selector and the numbers over each of its two maps on a phone. --- .../basic/src/components/ControlPanel.tsx | 29 +++- .../basic/src/components/SamplePageLayout.tsx | 81 ++++++++++- examples/basic/src/index.css | 136 +++++++++++++++++- .../pages/map/camerasync/camera-sync-page.css | 24 +++- 4 files changed, 260 insertions(+), 10 deletions(-) diff --git a/examples/basic/src/components/ControlPanel.tsx b/examples/basic/src/components/ControlPanel.tsx index 6259bfe..1f08317 100644 --- a/examples/basic/src/components/ControlPanel.tsx +++ b/examples/basic/src/components/ControlPanel.tsx @@ -5,11 +5,34 @@ interface ControlPanelProps { children: ReactNode; } +/** + * The options of a sample, over the map. + * + * The title is a button that folds the panel away. Until someone presses it, + * the screen width decides (`auto`, in CSS): open beside a desktop map, folded + * to its title on a phone, where an open panel would cover most of the map. + * Deciding in CSS keeps the server-rendered page and the first paint the same. + * Folding only hides the body, so the controls keep their state. + */ export function ControlPanel({ title, children }: ControlPanelProps) { + const [open, setOpen] = useState(null); + const toggle = () => { + setOpen(current => { + if (current !== null) return !current; + // Still `auto`: flip whatever the screen width shows now. + return typeof window !== 'undefined' && window.matchMedia('(max-width: 760px)').matches; + }); + }; + const mode = open === null ? 'auto' : open ? 'open' : 'folded'; return ( -
-

{title}

- {children} +
+ +
{children}
); } diff --git a/examples/basic/src/components/SamplePageLayout.tsx b/examples/basic/src/components/SamplePageLayout.tsx index 75da81c..c510bb1 100644 --- a/examples/basic/src/components/SamplePageLayout.tsx +++ b/examples/basic/src/components/SamplePageLayout.tsx @@ -1,4 +1,4 @@ -import type { ReactNode } from 'react'; +import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'; import type { SupportedLanguage } from '../samples/sampleRegistry'; import { SamplePageSeo } from '../samples/SamplePageSeo'; import { SampleDocumentation } from './SampleDocumentation'; @@ -16,6 +16,11 @@ export function SamplePageLayout({ language: SupportedLanguage; children?: ReactNode; }) { + const { stageRef, fullscreen, toggleFullscreen } = useMapFullscreen(); + const labels = { + enter: translate(language, { en: 'Full screen', ja: '全画面表示', 'es-419': 'Pantalla completa', de: 'Vollbild', th: 'เต็มหน้าจอ', hi: 'फ़ुल स्क्रीन' }), + exit: translate(language, { en: 'Exit full screen', ja: '全画面表示を終了', 'es-419': 'Salir de pantalla completa', de: 'Vollbild beenden', th: 'ออกจากโหมดเต็มหน้าจอ', hi: 'फ़ुल स्क्रीन से बाहर निकलें' }), + }; // The Hello Map tutorial is a full-page article (its own live demo + steps), // not the standard map-stage + documentation layout. if (page === 'hello-map') { @@ -31,7 +36,24 @@ export function SamplePageLayout({
-
+
+ {/* Camera Sync has its own full screen, for both of its maps. */} + {page !== 'camera-sync' && } {children ?? ( ); } + +/** + * Full screen for the map stage. The Fullscreen API where there is one; where + * there is not (iPhone Safari has none for a div), the stage is fixed over the + * whole page instead. Escape leaves either way. The maps live inside the stage + * (SingletonMaps), so they grow with it. + */ +function useMapFullscreen() { + const stageRef = useRef(null); + const [fullscreen, setFullscreen] = useState(false); + + // Maps that size themselves on window resize only (not every SDK watches its container). + const announceResize = () => requestAnimationFrame(() => window.dispatchEvent(new Event('resize'))); + + const toggleFullscreen = useCallback(() => { + const stage = stageRef.current; + if (!fullscreen) { + setFullscreen(true); + stage?.requestFullscreen?.().catch(() => {}); + } else { + setFullscreen(false); + if (document.fullscreenElement) document.exitFullscreen().catch(() => {}); + } + announceResize(); + }, [fullscreen]); + + useEffect(() => { + if (!fullscreen) return; + // Leaving native full screen (the system back gesture, Escape) ends ours too. + const onChange = () => { + if (!document.fullscreenElement) { + setFullscreen(false); + announceResize(); + } + }; + const onKey = (event: KeyboardEvent) => { + if (event.key === 'Escape' && !document.fullscreenElement) { + setFullscreen(false); + announceResize(); + } + }; + // The page behind must not scroll under the fixed stage. + const overflow = document.body.style.overflow; + document.body.style.overflow = 'hidden'; + document.addEventListener('fullscreenchange', onChange); + document.addEventListener('keydown', onKey); + return () => { + document.body.style.overflow = overflow; + document.removeEventListener('fullscreenchange', onChange); + document.removeEventListener('keydown', onKey); + }; + }, [fullscreen]); + + return { stageRef, fullscreen, toggleFullscreen }; +} diff --git a/examples/basic/src/index.css b/examples/basic/src/index.css index 59e0bf9..fd4d79b 100644 --- a/examples/basic/src/index.css +++ b/examples/basic/src/index.css @@ -659,8 +659,87 @@ body, .control-panel-title { font-size: 1rem; font-weight: 600; - margin: 0 0 12px; + margin: 0; + color: #333; +} + +/* The title is the button that folds the panel; it must not look like the + panel's own buttons (`.control-panel button`). */ +.control-panel .control-panel-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + width: 100%; + min-height: 0; + margin: 0; + padding: 0; + border: 0; + background: none; color: #333; + text-align: left; + cursor: pointer; +} + +.control-panel .control-panel-header:hover { + background: none; +} + +.control-panel-chevron { + flex: none; + color: #64748b; + transition: transform 140ms ease; +} + +.control-panel-body { + margin-top: 12px; +} + +.control-panel-folded .control-panel-body { + display: none; +} + +.control-panel-folded .control-panel-chevron { + transform: rotate(180deg); +} + +/* Full screen for the map stage (SamplePageLayout). */ +.map-fullscreen-button { + position: absolute; + top: 10px; + right: 10px; + z-index: 1300; + display: grid; + place-items: center; + width: 36px; + height: 36px; + padding: 0; + border: 1px solid #cbd5e1; + border-radius: 6px; + background: rgba(255, 255, 255, 0.95); + color: #1f2937; + box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25); + cursor: pointer; +} + +.map-fullscreen-button:hover { + background: #f1f5f9; +} + +.sample-map-stage.is-fullscreen { + position: fixed; + inset: 0; + z-index: 4000; + width: 100vw; + height: 100vh; + height: 100dvh; + border: 0; + border-radius: 0; +} + +.sample-map-stage:fullscreen { + width: 100%; + height: 100%; } .toggle-control { @@ -866,8 +945,61 @@ body, display: block; } + /* The map is what a phone shows: under the header, one line of title, then a + stage that ends at the bottom of the screen, so the folded panel and the + map's own controls are in view without scrolling. The description stays in + the page for search engines but takes no room here. */ + .sample-page-seo { + padding: 8px 10px 0; + } + + .sample-page-seo h2 { + font-size: 0.95rem; + line-height: 1.3; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + + .sample-page-seo p { + display: none; + } + + .sample-map-padding { + padding: 6px 8px 8px; + } + .sample-map-stage { - height: clamp(360px, 62vh, 620px); + /* header 58 + title 33 + padding 14 */ + height: clamp(360px, calc(100dvh - 105px), 900px); + } + + /* Folded to its title until opened, and never over most of the map. */ + .control-panel { + left: 8px; + right: auto; + /* Clear of the map's attribution line, which must stay readable. */ + bottom: 30px; + max-width: calc(100% - 16px); + padding: 10px 12px; + } + + .control-panel-title { + font-size: 0.9rem; + } + + .control-panel-auto .control-panel-body { + display: none; + } + + .control-panel-auto .control-panel-chevron { + transform: rotate(180deg); + } + + .control-panel-open { + right: 8px; + max-height: 55%; + overflow-y: auto; } .desktop-sidebar { diff --git a/examples/basic/src/pages/map/camerasync/camera-sync-page.css b/examples/basic/src/pages/map/camerasync/camera-sync-page.css index a9281bd..9bdb1f7 100644 --- a/examples/basic/src/pages/map/camerasync/camera-sync-page.css +++ b/examples/basic/src/pages/map/camerasync/camera-sync-page.css @@ -263,17 +263,35 @@ width: 100%; } + /* Two maps share a phone screen: keep only the selector and the numbers, + so most of each map stays in view. */ .camera-sync-provider { - width: min(86%, 300px); + top: 6px; + left: 6px; + width: auto; + max-width: calc(100% - 12px); + padding: 3px; + gap: 0; + font-size: 0; + } + + .camera-sync-provider select { + min-height: 28px; + font-size: 0.8rem; } .camera-sync-info { - max-width: calc(100% - 20px); + left: 6px; + bottom: 6px; + min-width: 0; + max-width: calc(100% - 12px); + padding: 4px 7px; grid-template-columns: repeat(2, minmax(0, auto)); column-gap: 10px; + font-size: 0.68rem; } .camera-sync-info strong { - grid-column: 1 / -1; + display: none; } }