trying to get theme-color switching correctly

This commit is contained in:
corgifist 2025-07-25 19:39:24 +03:00
parent 3f1df57cca
commit 04f2ed36bc
3 changed files with 17 additions and 6 deletions

View File

@ -29,7 +29,11 @@ export const viewport: Viewport = {
width: 'device-width',
initialScale: 1,
maximumScale: 1,
viewportFit: 'cover'
viewportFit: 'cover',
themeColor: [
{ color: 'var(--background)', media: '(prefers-color-scheme: light)' },
{ color: 'var(--background)', media: '(prefers-color-scheme: dark)' },
],
};
export default async function RootLayout({
@ -40,7 +44,6 @@ export default async function RootLayout({
return (
<html lang="en" suppressHydrationWarning>
<head>
<meta name="theme-color" content="var(--background)" />
<PWAHead/>
<Analytics/>
</head>

View File

@ -4,6 +4,7 @@ const PWAHead = () => (
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="theme-color" content="var(--background)" />
<link rel="apple-touch-startup-image" href="/splashes/apple-splash-dark-2048-2732.jpg" media="(prefers-color-scheme: dark) and (device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" />
<link rel="apple-touch-startup-image" href="/splashes/apple-splash-dark-2732-2048.jpg" media="(prefers-color-scheme: dark) and (device-width: 1024px) and (device-height: 1366px) and (-webkit-device-pixel-ratio: 2) and (orientation: landscape)" />
<link rel="apple-touch-startup-image" href="/splashes/apple-splash-dark-1668-2388.jpg" media="(prefers-color-scheme: dark) and (device-width: 834px) and (device-height: 1194px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)" />

View File

@ -2,7 +2,11 @@
import { ThemeProvider as NextThemeProvider } from "next-themes";
import { ComponentProps, ReactNode, useEffect } from "react";
const useMetaTheme = () => {
const MetaThemeProvider = ({
children
}: {
children: ReactNode
}) => {
useEffect(() => {
const updateThemeColor = () => {
const bgColor = window.getComputedStyle(document.body).backgroundColor;
@ -19,13 +23,16 @@ const useMetaTheme = () => {
return () => observer.disconnect();
}, []);
};
return children;
}
const ThemeProvider = (props: ComponentProps<typeof NextThemeProvider>): ReactNode => {
useMetaTheme();
return (
<NextThemeProvider {...props} attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
{props.children}
<MetaThemeProvider>
{props.children}
</MetaThemeProvider>
</NextThemeProvider>
)
};