mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-03 19:17:16 -05:00 
			
		
		
		
	Add focus handling for the grid
This commit is contained in:
		
							parent
							
								
									4af4119561
								
							
						
					
					
						commit
						262a26e3df
					
				@ -24,7 +24,6 @@ import { isBreakpoints } from "yoshiki/dist/utils";
 | 
				
			|||||||
import { breakpoints } from "yoshiki/native";
 | 
					import { breakpoints } from "yoshiki/native";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> & U[keyof U];
 | 
					type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> & U[keyof U];
 | 
				
			||||||
 | 
					 | 
				
			||||||
export type Breakpoint<T> = T | AtLeastOne<YoshikiBreakpoint<T>>;
 | 
					export type Breakpoint<T> = T | AtLeastOne<YoshikiBreakpoint<T>>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// copied from yoshiki.
 | 
					// copied from yoshiki.
 | 
				
			||||||
 | 
				
			|||||||
@ -18,8 +18,16 @@
 | 
				
			|||||||
 * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
 | 
					 * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { Platform } from "react-native";
 | 
				
			||||||
import { px } from "yoshiki/native";
 | 
					import { px } from "yoshiki/native";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const ts = (spacing: number) => {
 | 
					export const ts = (spacing: number) => {
 | 
				
			||||||
	return px(spacing * 8);
 | 
						return px(spacing * 8);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const focusReset: object =
 | 
				
			||||||
 | 
						Platform.OS === "web"
 | 
				
			||||||
 | 
							? {
 | 
				
			||||||
 | 
									boxShadow: "unset",
 | 
				
			||||||
 | 
							  }
 | 
				
			||||||
 | 
							: {};
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@
 | 
				
			|||||||
 * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
 | 
					 * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Link, Skeleton, Poster, ts, P, SubP } from "@kyoo/primitives";
 | 
					import { Link, Skeleton, Poster, ts, focusReset, P, SubP } from "@kyoo/primitives";
 | 
				
			||||||
import { Platform } from "react-native";
 | 
					import { Platform } from "react-native";
 | 
				
			||||||
import { percent, px, Stylable, useYoshiki } from "yoshiki/native";
 | 
					import { percent, px, Stylable, useYoshiki } from "yoshiki/native";
 | 
				
			||||||
import { Layout, WithLoading } from "../fetch";
 | 
					import { Layout, WithLoading } from "../fetch";
 | 
				
			||||||
@ -37,7 +37,7 @@ export const ItemGrid = ({
 | 
				
			|||||||
	poster?: string | null;
 | 
						poster?: string | null;
 | 
				
			||||||
}> &
 | 
					}> &
 | 
				
			||||||
	Stylable<"text">) => {
 | 
						Stylable<"text">) => {
 | 
				
			||||||
	const { css } = useYoshiki();
 | 
						const { css } = useYoshiki("grid");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (
 | 
						return (
 | 
				
			||||||
		<Link
 | 
							<Link
 | 
				
			||||||
@ -47,7 +47,22 @@ export const ItemGrid = ({
 | 
				
			|||||||
					{
 | 
										{
 | 
				
			||||||
						flexDirection: "column",
 | 
											flexDirection: "column",
 | 
				
			||||||
						alignItems: "center",
 | 
											alignItems: "center",
 | 
				
			||||||
						m: { xs: ts(1), sm: ts(2) },
 | 
											m: { xs: ts(1), sm: ts(4) },
 | 
				
			||||||
 | 
											child: {
 | 
				
			||||||
 | 
												poster: {
 | 
				
			||||||
 | 
													borderColor: "transparent",
 | 
				
			||||||
 | 
													borderWidth: px(4),
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
 | 
											fover: {
 | 
				
			||||||
 | 
												self: focusReset,
 | 
				
			||||||
 | 
												poster: {
 | 
				
			||||||
 | 
													borderColor: (theme) => theme.appbar,
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
												title: {
 | 
				
			||||||
 | 
													textDecorationLine: "underline",
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
											},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
					// We leave no width on native to fill the list's grid.
 | 
										// We leave no width on native to fill the list's grid.
 | 
				
			||||||
					Platform.OS === "web" && {
 | 
										Platform.OS === "web" && {
 | 
				
			||||||
@ -59,10 +74,16 @@ export const ItemGrid = ({
 | 
				
			|||||||
				props,
 | 
									props,
 | 
				
			||||||
			)}
 | 
								)}
 | 
				
			||||||
		>
 | 
							>
 | 
				
			||||||
			<Poster src={poster} alt={name} isLoading={isLoading} layout={{ width: percent(100) }} />
 | 
								<Poster
 | 
				
			||||||
 | 
									src={poster}
 | 
				
			||||||
 | 
									alt={name}
 | 
				
			||||||
 | 
									isLoading={isLoading}
 | 
				
			||||||
 | 
									layout={{ width: percent(100) }}
 | 
				
			||||||
 | 
									{...css("poster")}
 | 
				
			||||||
 | 
								/>
 | 
				
			||||||
			<Skeleton>
 | 
								<Skeleton>
 | 
				
			||||||
				{isLoading || (
 | 
									{isLoading || (
 | 
				
			||||||
					<P numberOfLines={1} {...css({ marginY: 0, textAlign: "center" })}>
 | 
										<P numberOfLines={1} {...css([{ marginY: 0, textAlign: "center" }, "title"])}>
 | 
				
			||||||
						{name}
 | 
											{name}
 | 
				
			||||||
					</P>
 | 
										</P>
 | 
				
			||||||
				)}
 | 
									)}
 | 
				
			||||||
 | 
				
			|||||||
@ -66,9 +66,10 @@ export const InfiniteFetch = <Data,>({
 | 
				
			|||||||
		return <EmptyView message={empty} />;
 | 
							return <EmptyView message={empty} />;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const placeholders = [
 | 
						const count = items ? numColumns - (items.length % numColumns) : placeholderCount;
 | 
				
			||||||
		...Array(items ? numColumns - (items.length % numColumns) + numColumns : placeholderCount),
 | 
						const placeholders = [...Array(count === 0 ? numColumns : count)].map(
 | 
				
			||||||
	].map((_, i) => ({ id: `gen${i}`, isLoading: true } as Data));
 | 
							(_, i) => ({ id: `gen${i}`, isLoading: true } as Data),
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (
 | 
						return (
 | 
				
			||||||
		<FlashList
 | 
							<FlashList
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user