feat(tvos): Add TopShelf Extension (#1561)

This commit is contained in:
Steve Byatt
2026-05-21 07:47:45 +01:00
committed by GitHub
parent 4bef386b82
commit 121ff0eea0
19 changed files with 832 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
export type TopShelfCacheModuleEvents = Record<string, never>;
export interface TopShelfCacheItem {
id: string;
title: string;
subtitle?: string;
imageUrl?: string;
route: string;
playRoute?: string;
}
export interface TopShelfCacheSection {
title: string;
items: TopShelfCacheItem[];
}
export interface TopShelfCachePayload {
version: 1;
updatedAt: string;
sections: TopShelfCacheSection[];
}

View File

@@ -0,0 +1,37 @@
import { NativeModule, requireNativeModule } from "expo";
import { Platform } from "react-native";
import type { TopShelfCacheModuleEvents } from "./TopShelfCache.types";
declare class TopShelfCacheModuleType extends NativeModule<TopShelfCacheModuleEvents> {
writeCache(json: string, apiKey?: string): boolean;
clearCache(): boolean;
}
let TopShelfCacheNativeModule: TopShelfCacheModuleType | null = null;
if (Platform.OS === "ios" && Platform.isTV) {
try {
TopShelfCacheNativeModule =
requireNativeModule<TopShelfCacheModuleType>("TopShelfCache");
} catch {
TopShelfCacheNativeModule = null;
}
}
export function writeTopShelfCache(json: string, apiKey?: string): boolean {
if (!TopShelfCacheNativeModule) return false;
try {
return TopShelfCacheNativeModule.writeCache(json, apiKey);
} catch {
try {
return TopShelfCacheNativeModule.writeCache(json);
} catch {
return false;
}
}
}
export function clearTopShelfCache(): boolean {
return TopShelfCacheNativeModule?.clearCache() ?? false;
}

View File

@@ -0,0 +1,2 @@
export * from "./TopShelfCache.types";
export { clearTopShelfCache, writeTopShelfCache } from "./TopShelfCacheModule";