mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-02-22 02:24:44 +08:00
fix: dynamic theme color
This commit is contained in:
@@ -12,10 +12,6 @@ export const metadata: Metadata = {
|
||||
title: 'MoonTV',
|
||||
description: '影视聚合',
|
||||
manifest: '/manifest.json',
|
||||
themeColor: [
|
||||
{ media: '(prefers-color-scheme: light)', color: '#f9fbfe' },
|
||||
{ media: '(prefers-color-scheme: dark)', color: '#0C111C' },
|
||||
],
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
|
||||
@@ -102,7 +102,7 @@ export default function ScrollableRow({
|
||||
>
|
||||
<div
|
||||
ref={containerRef}
|
||||
className='flex space-x-6 overflow-x-auto scrollbar-hide pb-10 sm:pb-14'
|
||||
className='flex space-x-6 overflow-x-auto scrollbar-hide pb-12 sm:pb-14'
|
||||
onScroll={checkScroll}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any,react-hooks/exhaustive-deps */
|
||||
|
||||
'use client';
|
||||
|
||||
@@ -8,10 +8,23 @@ import { useEffect, useState } from 'react';
|
||||
|
||||
export function ThemeToggle() {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const { theme, setTheme } = useTheme();
|
||||
const { setTheme, resolvedTheme } = useTheme();
|
||||
|
||||
const setThemeColor = (theme?: string) => {
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
if (!meta) {
|
||||
const meta = document.createElement('meta');
|
||||
meta.name = 'theme-color';
|
||||
meta.content = theme === 'dark' ? '#0c111c' : '#f9fbfe';
|
||||
document.head.appendChild(meta);
|
||||
} else {
|
||||
meta.setAttribute('content', theme === 'dark' ? '#0c111c' : '#f9fbfe');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
setThemeColor(resolvedTheme);
|
||||
}, []);
|
||||
|
||||
if (!mounted) {
|
||||
@@ -21,13 +34,15 @@ export function ThemeToggle() {
|
||||
|
||||
const toggleTheme = () => {
|
||||
// 检查浏览器是否支持 View Transitions API
|
||||
const targetTheme = resolvedTheme === 'dark' ? 'light' : 'dark';
|
||||
setThemeColor(targetTheme);
|
||||
if (!(document as any).startViewTransition) {
|
||||
setTheme(theme === 'dark' ? 'light' : 'dark');
|
||||
setTheme(targetTheme);
|
||||
return;
|
||||
}
|
||||
|
||||
(document as any).startViewTransition(() => {
|
||||
setTheme(theme === 'dark' ? 'light' : 'dark');
|
||||
setTheme(targetTheme);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -37,7 +52,7 @@ export function ThemeToggle() {
|
||||
className='w-10 h-10 p-2 rounded-full flex items-center justify-center text-gray-600 hover:bg-gray-200/50 dark:text-gray-300 dark:hover:bg-gray-700/50 transition-colors'
|
||||
aria-label='Toggle theme'
|
||||
>
|
||||
{theme === 'dark' ? (
|
||||
{resolvedTheme === 'dark' ? (
|
||||
<Sun className='w-full h-full' />
|
||||
) : (
|
||||
<Moon className='w-full h-full' />
|
||||
|
||||
Reference in New Issue
Block a user