Create a tv drawer

This commit is contained in:
Zoe Roux 2023-01-26 18:56:37 +09:00
parent 0e3d87a9ca
commit c7b2daedb9
No known key found for this signature in database
GPG Key ID: B2AB52A2636E5C46
4 changed files with 93 additions and 3 deletions

View File

@ -20,7 +20,7 @@
import { PortalProvider } from "@gorhom/portal";
import { ThemeSelector, ts } from "@kyoo/primitives";
import { NavbarRight, NavbarTitle } from "@kyoo/ui";
import { NavbarRight, NavbarTitle, TvDrawer } from "@kyoo/ui";
import { createQueryClient } from "@kyoo/models";
import { QueryClientProvider } from "@tanstack/react-query";
import i18next from "i18next";
@ -34,7 +34,7 @@ import {
Poppins_900Black,
} from "@expo-google-fonts/poppins";
import { useCallback, useLayoutEffect, useState } from "react";
import { Platform, useColorScheme } from "react-native";
import { Platform, useColorScheme, View } from "react-native";
import { initReactI18next } from "react-i18next";
import { useTheme, useYoshiki } from "yoshiki/native";
import "intl-pluralrules";
@ -124,7 +124,9 @@ export default function Root() {
}}
>
<PortalProvider>
<ThemedStack onLayout={onLayout} />
<TvDrawer>
<ThemedStack onLayout={onLayout} />
</TvDrawer>
</PortalProvider>
</ThemeSelector>
</QueryClientProvider>

View File

View File

@ -0,0 +1,87 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
/* eslint-disable react-hooks/rules-of-hooks */
import { useTranslation } from "react-i18next";
import { Platform, Pressable, View } from "react-native";
import { Theme, useYoshiki } from "yoshiki/native";
import Home from "@material-symbols/svg-400/rounded/home-fill.svg";
import Search from "@material-symbols/svg-400/rounded/search-fill.svg";
import { Icon, P, ts } from "@kyoo/primitives";
import { useState } from "react";
import { motify } from "moti";
const MotiPressable = motify(Pressable)();
const MenuItem = ({
icon,
text,
openned,
setOpen,
}: {
icon: any;
text: string;
openned: boolean;
setOpen: (value: (old: number) => number) => void;
}) => {
const { css, theme } = useYoshiki();
const [width, setWidth] = useState(0);
return (
<MotiPressable
animate={{ width }}
onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
{...(css(
{
flexDirection: "row",
pX: ts(4),
focus: { self: { bg: (theme: Theme) => theme.accent } },
},
{ onFocus: () => setOpen((x) => x++), onBlur: () => setOpen((x) => x--) },
) as any)}
>
<Icon
icon={icon}
color={theme.colors.white}
size={ts(4)}
{...css({ alignSelf: "center", marginHorizontal: ts(1) })}
/>
{openned && <P {...css({ color: (theme) => theme.colors.white })}>{text}</P>}
</MotiPressable>
);
};
export const TvDrawer = ({ children }: { children: JSX.Element }) => {
if (!Platform.isTV) return children;
const { css } = useYoshiki();
const { t } = useTranslation();
const [openned, setOpen] = useState(0);
return (
<View {...css({ flexDirection: "row", flexGrow: 1, bg: (theme) => theme.contrast })}>
<View {...css({ alignSelf: "center" })}>
<MenuItem icon={Home} text={t("navbar.home")} openned={!!openned} setOpen={setOpen} />
<MenuItem icon={Search} text={t("navbar.search")} openned={!!openned} setOpen={setOpen} />
</View>
{children}
</View>
);
};

View File

@ -23,3 +23,4 @@ export { BrowsePage } from "./browse";
export { MovieDetails, ShowDetails } from "./details";
export { Player } from "./player";
export { SearchPage } from "./search";
export { TvDrawer } from "./drawer";