mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Add automatic theme on the web
This commit is contained in:
parent
9dc9431170
commit
e11af205f8
@ -33,7 +33,7 @@ import {
|
|||||||
Poppins_400Regular,
|
Poppins_400Regular,
|
||||||
Poppins_900Black,
|
Poppins_900Black,
|
||||||
} from "@expo-google-fonts/poppins";
|
} from "@expo-google-fonts/poppins";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useLayoutEffect, useState } from "react";
|
||||||
import { useColorScheme } from "react-native";
|
import { useColorScheme } from "react-native";
|
||||||
import { initReactI18next } from "react-i18next";
|
import { initReactI18next } from "react-i18next";
|
||||||
import { useTheme } from "yoshiki/native";
|
import { useTheme } from "yoshiki/native";
|
||||||
@ -82,6 +82,11 @@ export default function Root() {
|
|||||||
const theme = useColorScheme();
|
const theme = useColorScheme();
|
||||||
const [fontsLoaded] = useFonts({ Poppins_300Light, Poppins_400Regular, Poppins_900Black });
|
const [fontsLoaded] = useFonts({ Poppins_300Light, Poppins_400Regular, Poppins_900Black });
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
// This does not seems to work on the global scope so why not.
|
||||||
|
SplashScreen.preventAutoHideAsync();
|
||||||
|
})
|
||||||
|
|
||||||
const onLayout = useCallback(async () => {
|
const onLayout = useCallback(async () => {
|
||||||
if (fontsLoaded) {
|
if (fontsLoaded) {
|
||||||
await SplashScreen.hideAsync();
|
await SplashScreen.hideAsync();
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
"react-native-screens": "~3.18.0",
|
"react-native-screens": "~3.18.0",
|
||||||
"react-native-svg": "13.4.0",
|
"react-native-svg": "13.4.0",
|
||||||
"react-native-video": "alpha",
|
"react-native-video": "alpha",
|
||||||
"yoshiki": "0.3.2"
|
"yoshiki": "0.3.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.19.3",
|
"@babel/core": "^7.19.3",
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
"react-native-web": "^0.18.10",
|
"react-native-web": "^0.18.10",
|
||||||
"solito": "^2.0.5",
|
"solito": "^2.0.5",
|
||||||
"superjson": "^1.11.0",
|
"superjson": "^1.11.0",
|
||||||
"yoshiki": "0.3.2",
|
"yoshiki": "0.3.3",
|
||||||
"zod": "^3.19.1"
|
"zod": "^3.19.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -96,8 +96,7 @@ const App = ({ Component, pageProps }: AppProps) => {
|
|||||||
</Head>
|
</Head>
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<Hydrate state={queryState}>
|
<Hydrate state={queryState}>
|
||||||
{/* TODO: Add theme support */}
|
<ThemeSelector theme="auto" font={{ normal: "inherit" }}>
|
||||||
<ThemeSelector theme="light" font={{ normal: "inherit" }}>
|
|
||||||
<GlobalCssTheme />
|
<GlobalCssTheme />
|
||||||
<Layout page={<Component {...props} />} {...layoutProps} />
|
<Layout page={<Component {...props} />} {...layoutProps} />
|
||||||
</ThemeSelector>
|
</ThemeSelector>
|
||||||
|
@ -22,10 +22,9 @@ import { Platform } from "react-native";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export const imageFn = (url: string) =>
|
export const imageFn = (url: string) =>
|
||||||
// TODO remove the hardcodded fallback
|
|
||||||
Platform.OS === "web"
|
Platform.OS === "web"
|
||||||
? `/api/${url}`
|
? `/api/${url}`
|
||||||
: (process.env.PUBLIC_BACK_URL ?? "https://beta.sdg.moe") + url;
|
: process.env.PUBLIC_BACK_URL + url;
|
||||||
|
|
||||||
export const ImagesP = z.object({
|
export const ImagesP = z.object({
|
||||||
/**
|
/**
|
||||||
|
@ -20,11 +20,12 @@
|
|||||||
|
|
||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import { Property } from "csstype";
|
import { Property } from "csstype";
|
||||||
import { Theme, ThemeProvider } from "yoshiki";
|
import { Theme, ThemeProvider, useAutomaticTheme } from "yoshiki";
|
||||||
import { useTheme, useYoshiki } from "yoshiki/native";
|
import { useTheme, useYoshiki } from "yoshiki/native";
|
||||||
import "yoshiki";
|
import "yoshiki";
|
||||||
import "yoshiki/native";
|
import "yoshiki/native";
|
||||||
import { catppuccin } from "./catppuccin";
|
import { catppuccin } from "./catppuccin";
|
||||||
|
import { Platform } from "react-native";
|
||||||
|
|
||||||
type FontList = Partial<
|
type FontList = Partial<
|
||||||
Record<
|
Record<
|
||||||
@ -75,18 +76,36 @@ export type ThemeBuilder = {
|
|||||||
dark: Omit<Mode, "contrast"> & { default: Variant };
|
dark: Omit<Mode, "contrast"> & { default: Variant };
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectMode = (theme: ThemeBuilder & { font: FontList }, mode: "light" | "dark"): Theme => {
|
const selectMode = (
|
||||||
|
theme: ThemeBuilder & { font: FontList },
|
||||||
|
mode: "light" | "dark" | "auto",
|
||||||
|
): Theme => {
|
||||||
const { light: lightBuilder, dark: darkBuilder, ...options } = theme;
|
const { light: lightBuilder, dark: darkBuilder, ...options } = theme;
|
||||||
const light = { ...lightBuilder, ...lightBuilder.default, contrast: lightBuilder.colors.black };
|
const light = { ...lightBuilder, ...lightBuilder.default, contrast: lightBuilder.colors.black };
|
||||||
const dark = { ...darkBuilder, ...darkBuilder.default, contrast: darkBuilder.colors.white };
|
const dark = { ...darkBuilder, ...darkBuilder.default, contrast: darkBuilder.colors.white };
|
||||||
const value = mode === "light" ? light : dark;
|
if (Platform.OS !== "web" || mode !== "auto") {
|
||||||
const alternate = mode === "light" ? dark : light;
|
const value = mode === "light" ? light : dark;
|
||||||
|
const alternate = mode === "light" ? dark : light;
|
||||||
|
return {
|
||||||
|
...options,
|
||||||
|
...value,
|
||||||
|
light,
|
||||||
|
dark,
|
||||||
|
user: value,
|
||||||
|
alternate,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
|
const auto = useAutomaticTheme({ light, dark });
|
||||||
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
|
const alternate = useAutomaticTheme({ dark: light, light: dark });
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
...value,
|
...auto,
|
||||||
light,
|
light,
|
||||||
dark,
|
dark,
|
||||||
user: value,
|
user: auto,
|
||||||
alternate,
|
alternate,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -112,12 +131,12 @@ export const ThemeSelector = ({
|
|||||||
font,
|
font,
|
||||||
}: {
|
}: {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
theme: "light" | "dark";
|
theme: "light" | "dark" | "auto";
|
||||||
font: FontList;
|
font: FontList;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
const newTheme = selectMode({ ...catppuccin, font }, theme);
|
||||||
<ThemeProvider theme={selectMode({ ...catppuccin, font }, theme)}>{children}</ThemeProvider>
|
|
||||||
);
|
return <ThemeProvider theme={newTheme}>{children}</ThemeProvider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type YoshikiFunc<T> = (props: ReturnType<typeof useYoshiki>) => T;
|
type YoshikiFunc<T> = (props: ReturnType<typeof useYoshiki>) => T;
|
||||||
|
@ -57,7 +57,16 @@ export const ShowDetails: QueryPage<{ slug: string; season: string }> = ({ slug,
|
|||||||
{...css(
|
{...css(
|
||||||
[
|
[
|
||||||
{ bg: (theme) => theme.background },
|
{ bg: (theme) => theme.background },
|
||||||
Platform.OS === "web" && { flexGrow: 1, flexShrink: 1, overflow: "overlay" as any },
|
Platform.OS === "web" && {
|
||||||
|
flexGrow: 1,
|
||||||
|
flexShrink: 1,
|
||||||
|
// @ts-ignore Web only property
|
||||||
|
overflow: "auto" as any,
|
||||||
|
// @ts-ignore Web only property
|
||||||
|
overflowX: "hidden",
|
||||||
|
// @ts-ignore Web only property
|
||||||
|
overflowY: "overlay",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
props,
|
props,
|
||||||
)}
|
)}
|
||||||
@ -92,4 +101,4 @@ ShowDetails.getFetchUrls = ({ slug, season = 1 }) => [
|
|||||||
EpisodeList.query(slug, season),
|
EpisodeList.query(slug, season),
|
||||||
];
|
];
|
||||||
|
|
||||||
ShowDetails.getLayout = { Layout: DefaultLayout, props: { transparent: true }};
|
ShowDetails.getLayout = { Layout: DefaultLayout, props: { transparent: true } };
|
||||||
|
@ -10200,7 +10200,7 @@ __metadata:
|
|||||||
react-native-svg-transformer: ^1.0.0
|
react-native-svg-transformer: ^1.0.0
|
||||||
react-native-video: alpha
|
react-native-video: alpha
|
||||||
typescript: ^4.6.3
|
typescript: ^4.6.3
|
||||||
yoshiki: 0.3.2
|
yoshiki: 0.3.3
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
@ -10592,6 +10592,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"object-hash@npm:^3.0.0":
|
||||||
|
version: 3.0.0
|
||||||
|
resolution: "object-hash@npm:3.0.0"
|
||||||
|
checksum: 80b4904bb3857c52cc1bfd0b52c0352532ca12ed3b8a6ff06a90cd209dfda1b95cee059a7625eb9da29537027f68ac4619363491eedb2f5d3dddbba97494fd6c
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"object-inspect@npm:^1.12.2, object-inspect@npm:^1.9.0":
|
"object-inspect@npm:^1.12.2, object-inspect@npm:^1.9.0":
|
||||||
version: 1.12.2
|
version: 1.12.2
|
||||||
resolution: "object-inspect@npm:1.12.2"
|
resolution: "object-inspect@npm:1.12.2"
|
||||||
@ -13925,7 +13932,7 @@ __metadata:
|
|||||||
superjson: ^1.11.0
|
superjson: ^1.11.0
|
||||||
typescript: ^4.9.3
|
typescript: ^4.9.3
|
||||||
webpack: ^5.75.0
|
webpack: ^5.75.0
|
||||||
yoshiki: 0.3.2
|
yoshiki: 0.3.3
|
||||||
zod: ^3.19.1
|
zod: ^3.19.1
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
@ -14271,14 +14278,15 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"yoshiki@npm:0.3.2":
|
"yoshiki@npm:0.3.3":
|
||||||
version: 0.3.2
|
version: 0.3.3
|
||||||
resolution: "yoshiki@npm:0.3.2"
|
resolution: "yoshiki@npm:0.3.3"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/node": 18.x.x
|
"@types/node": 18.x.x
|
||||||
"@types/react": 18.x.x
|
"@types/react": 18.x.x
|
||||||
"@types/react-native": ">= 0.70.0"
|
"@types/react-native": ">= 0.70.0"
|
||||||
inline-style-prefixer: ^7.0.0
|
inline-style-prefixer: ^7.0.0
|
||||||
|
object-hash: ^3.0.0
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
react: "*"
|
react: "*"
|
||||||
react-native: "*"
|
react-native: "*"
|
||||||
@ -14288,7 +14296,7 @@ __metadata:
|
|||||||
optional: true
|
optional: true
|
||||||
react-native-web:
|
react-native-web:
|
||||||
optional: true
|
optional: true
|
||||||
checksum: a723473e5593e9871d4903cfc9186240c6745cd97ca45ba9f1f0233e7717afefb908c08a0a6e2dc37ac2bbb0c9df269364767db6c885a8f2e19748d295c42a57
|
checksum: 6358f53d28ba419a8783cd5cf785eb7c64878504815ed4c6794fbf81ed86bca83560a7677e5ecfe568f37c0ff714bf07f3a33c11ce6d869f6d758e800bfa58ba
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user