fix(web): match the iOS status bar to the theme picked in the app
The theme-color metas used prefers-color-scheme media queries, so they followed the OS theme and ignored the in-app choice. Use a single meta that the pre-paint script and ThemeProvider update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,8 +8,9 @@
|
|||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
|
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
|
||||||
/>
|
/>
|
||||||
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#f9f8f5" />
|
<!-- Set from the resolved theme (script below and `theme-provider.tsx`), not with
|
||||||
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#0f1411" />
|
`media` queries: those follow the OS and ignore the theme picked in the app. -->
|
||||||
|
<meta name="theme-color" content="#f9f8f5" />
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
<meta name="mobile-web-app-capable" content="yes" />
|
<meta name="mobile-web-app-capable" content="yes" />
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
|
||||||
@@ -28,6 +29,9 @@
|
|||||||
stored === 'dark' || (stored !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches)
|
stored === 'dark' || (stored !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches)
|
||||||
document.documentElement.classList.toggle('dark', dark)
|
document.documentElement.classList.toggle('dark', dark)
|
||||||
document.documentElement.style.colorScheme = dark ? 'dark' : 'light'
|
document.documentElement.style.colorScheme = dark ? 'dark' : 'light'
|
||||||
|
document
|
||||||
|
.querySelector('meta[name="theme-color"]')
|
||||||
|
.setAttribute('content', dark ? '#0f1411' : '#f9f8f5')
|
||||||
})()
|
})()
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ type ThemeContextValue = {
|
|||||||
const STORAGE_KEY = 'superlist-theme'
|
const STORAGE_KEY = 'superlist-theme'
|
||||||
const DARK_QUERY = '(prefers-color-scheme: dark)'
|
const DARK_QUERY = '(prefers-color-scheme: dark)'
|
||||||
|
|
||||||
|
/** Browser chrome color (the iOS status bar) per theme. Keep in sync with `index.html`. */
|
||||||
|
const THEME_COLORS: Record<ResolvedTheme, string> = { light: '#f9f8f5', dark: '#0f1411' }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This theme handling is hand-rolled on purpose. Libraries such as `next-themes`
|
* This theme handling is hand-rolled on purpose. Libraries such as `next-themes`
|
||||||
* avoid the pre-paint flash by rendering a `<script>` from React, but React 19
|
* avoid the pre-paint flash by rendering a `<script>` from React, but React 19
|
||||||
@@ -60,6 +63,9 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
|
|||||||
const root = document.documentElement
|
const root = document.documentElement
|
||||||
root.classList.toggle('dark', resolvedTheme === 'dark')
|
root.classList.toggle('dark', resolvedTheme === 'dark')
|
||||||
root.style.colorScheme = resolvedTheme
|
root.style.colorScheme = resolvedTheme
|
||||||
|
document
|
||||||
|
.querySelector('meta[name="theme-color"]')
|
||||||
|
?.setAttribute('content', THEME_COLORS[resolvedTheme])
|
||||||
}, [resolvedTheme])
|
}, [resolvedTheme])
|
||||||
|
|
||||||
const setTheme = useCallback((next: Theme) => {
|
const setTheme = useCallback((next: Theme) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user