fix(tv): lazy-load @expo/ui to prevent tvOS crash at module load

This commit is contained in:
Fredrik Burmester
2026-05-30 21:21:22 +02:00
parent d2e73021b1
commit 252c58f120
3 changed files with 34 additions and 9 deletions

View File

@@ -1,9 +1,17 @@
import { Button, Host, Menu } from "@expo/ui/swift-ui";
import { buttonStyle } from "@expo/ui/swift-ui/modifiers";
import { Platform, View } from "react-native";
import { FilterButton } from "@/components/filters/FilterButton";
import { JellyseerrSearchSort } from "@/components/jellyseerr/JellyseerrIndexPage";
// @expo/ui's SwiftUI native module (ExpoUI) does not exist in tvOS builds.
// A static top-level import crashes the route tree on tvOS at module load.
// Load it lazily and only off-TV; TV never renders this component.
const { Button, Host, Menu } = Platform.isTV
? ({} as typeof import("@expo/ui/swift-ui"))
: require("@expo/ui/swift-ui");
const { buttonStyle } = Platform.isTV
? ({} as typeof import("@expo/ui/swift-ui/modifiers"))
: require("@expo/ui/swift-ui/modifiers");
interface DiscoverFiltersProps {
searchFilterId: string;
orderFilterId: string;
@@ -29,7 +37,7 @@ export const DiscoverFilters: React.FC<DiscoverFiltersProps> = ({
setJellyseerrSortOrder,
t,
}) => {
if (Platform.OS === "ios") {
if (Platform.OS === "ios" && !Platform.isTV) {
return (
<Host
style={{

View File

@@ -1,8 +1,16 @@
import { Button, Host, HStack, Spacer } from "@expo/ui/swift-ui";
import { buttonStyle } from "@expo/ui/swift-ui/modifiers";
import { Platform, TouchableOpacity, View } from "react-native";
import { Tag } from "@/components/GenreTags";
// @expo/ui's SwiftUI native module (ExpoUI) does not exist in tvOS builds.
// A static top-level import crashes the route tree on tvOS at module load.
// Load it lazily and only off-TV; TV never renders this component.
const { Button, Host, HStack, Spacer } = Platform.isTV
? ({} as typeof import("@expo/ui/swift-ui"))
: require("@expo/ui/swift-ui");
const { buttonStyle } = Platform.isTV
? ({} as typeof import("@expo/ui/swift-ui/modifiers"))
: require("@expo/ui/swift-ui/modifiers");
type SearchType = "Library" | "Discover";
interface SearchTabButtonsProps {
@@ -16,7 +24,7 @@ export const SearchTabButtons: React.FC<SearchTabButtonsProps> = ({
setSearchType,
t,
}) => {
if (Platform.OS === "ios") {
if (Platform.OS === "ios" && !Platform.isTV) {
return (
<Host style={{ height: 40, flex: 1 }}>
<HStack spacing={8}>