diff --git a/front/packages/primitives/src/image/blurhash.tsx b/front/packages/primitives/src/image/blurhash.tsx new file mode 100644 index 00000000..7c8b2f60 --- /dev/null +++ b/front/packages/primitives/src/image/blurhash.tsx @@ -0,0 +1,43 @@ +/* + * Kyoo - A portable and vast media library solution. + * Copyright (c) Kyoo. + * + * See AUTHORS.md and LICENSE file in the project root for full license information. + * + * Kyoo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Kyoo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Kyoo. If not, see . + */ + +import { ReactElement } from "react"; +import { View } from "react-native"; +import { Blurhash } from "react-native-blurhash"; +import { Stylable, useYoshiki } from "yoshiki/native"; + +export const BlurhashContainer = ({ + blurhash, + children, + ...props +}: { blurhash: string; children?: ReactElement | ReactElement[] } & Stylable) => { + const { css } = useYoshiki(); + + return ( + + + {children} + + ); +}; diff --git a/front/packages/primitives/src/image/blurhash-web.tsx b/front/packages/primitives/src/image/blurhash.web.tsx similarity index 79% rename from front/packages/primitives/src/image/blurhash-web.tsx rename to front/packages/primitives/src/image/blurhash.web.tsx index 98e78b55..338f5e76 100644 --- a/front/packages/primitives/src/image/blurhash-web.tsx +++ b/front/packages/primitives/src/image/blurhash.web.tsx @@ -19,6 +19,10 @@ */ import { decode } from "blurhash"; +import { ReactElement } from "react"; +import { useYoshiki } from "yoshiki"; +import { Stylable } from "yoshiki/native"; +import { StyleList, processStyleList } from "yoshiki/src/type"; // The blurhashToUrl has been stolen from https://gist.github.com/mattiaz9/53cb67040fa135cb395b1d015a200aff export function blurHashToDataURL(hash: string | undefined): string | undefined { @@ -186,3 +190,45 @@ function generatePng(width: number, height: number, rgbaString: string) { const pngString = SIGNATURE + IHDR + IDAT + IEND; return pngString; } + +// Extract classnames from leftover props using yoshiki's internal. +const extractClassNames = (props: { + style?: StyleList<{ $$css?: true; yoshiki?: string } | Style>; +}) => { + const inline = processStyleList(props.style); + return "$$css" in inline && inline.$$css ? inline.yoshiki : undefined; +}; + +export const BlurhashContainer = ({ + blurhash, + children, + ...props +}: { blurhash: string; children?: ReactElement | ReactElement[] } & Stylable) => { + const { css } = useYoshiki(); + + return ( +
+ {children} +
+ ); +}; diff --git a/front/packages/primitives/src/image/image.web.tsx b/front/packages/primitives/src/image/image.web.tsx index 89d12d74..fbfdc285 100644 --- a/front/packages/primitives/src/image/image.web.tsx +++ b/front/packages/primitives/src/image/image.web.tsx @@ -20,22 +20,12 @@ import { useLayoutEffect, useState } from "react"; import { ImageStyle, View, ViewStyle } from "react-native"; -import { StyleList, processStyleList } from "yoshiki/src/type"; -import { useYoshiki as useWebYoshiki } from "yoshiki/web"; import { useYoshiki } from "yoshiki/native"; import { Props, ImageLayout } from "./base-image"; -import { blurHashToDataURL } from "./blurhash-web"; +import { BlurhashContainer, blurHashToDataURL } from "./blurhash.web"; import { Skeleton } from "../skeleton"; import NextImage from "next/image"; -// Extract classnames from leftover props using yoshiki's internal. -const extractClassNames = (props: { - style?: StyleList<{ $$css?: true; yoshiki?: string } | Style>; -}) => { - const inline = processStyleList(props.style); - return "$$css" in inline && inline.$$css ? inline.yoshiki : undefined; -}; - export const Image = ({ src, quality, @@ -46,7 +36,6 @@ export const Image = ({ ...props }: Props & { style?: ImageStyle } & { layout: ImageLayout }) => { const { css } = useYoshiki(); - const { css: wCss } = useWebYoshiki(); const [state, setState] = useState<"loading" | "errored" | "finished">( src ? "finished" : "errored", ); @@ -66,26 +55,8 @@ export const Image = ({ ); } - const blurhash = blurHashToDataURL(src.blurhash); return ( -
+ setState("finished")} onError={() => setState("errored")} /> -
+ ); }; diff --git a/front/packages/primitives/src/image/index.tsx b/front/packages/primitives/src/image/index.tsx index 7cb94f62..12f94a91 100644 --- a/front/packages/primitives/src/image/index.tsx +++ b/front/packages/primitives/src/image/index.tsx @@ -18,14 +18,15 @@ * along with Kyoo. If not, see . */ -import { ImageProps, ImageStyle, Platform, View, ViewProps, ViewStyle } from "react-native"; +import { ImageStyle, View, ViewProps, ViewStyle } from "react-native"; import { Props, YoshikiEnhanced } from "./base-image"; import { Image } from "./image"; -import { ComponentType, ReactNode, useState } from "react"; +import { ComponentType, ReactNode } from "react"; import { LinearGradient, LinearGradientProps } from "expo-linear-gradient"; import { ContrastArea, alpha } from "../themes"; import { percent } from "yoshiki/native"; +export { BlurhashContainer } from "./blurhash"; export { type Props as ImageProps, Image }; export const Poster = ({