From fbe858715ab911e6eb71eaf74df3d6c3d1dd1a05 Mon Sep 17 00:00:00 2001 From: zimplexing Date: Fri, 11 Jul 2025 21:44:15 +0800 Subject: [PATCH] fix: Update channel change logic to use useCallback for better performance; adjust resource check in VideoSourceSection --- app/live.tsx | 24 ++++++++++++---------- components/settings/VideoSourceSection.tsx | 2 +- package.json | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/live.tsx b/app/live.tsx index c43c2dc..f7a51fc 100644 --- a/app/live.tsx +++ b/app/live.tsx @@ -4,7 +4,6 @@ import LivePlayer from "@/components/LivePlayer"; import { fetchAndParseM3u, getPlayableUrl, Channel } from "@/services/m3u"; import { ThemedView } from "@/components/ThemedView"; import { StyledButton } from "@/components/StyledButton"; -import { AVPlaybackStatus } from "expo-av"; import { useSettingsStore } from "@/stores/settingsStore"; export default function LiveScreen() { @@ -66,15 +65,18 @@ export default function LiveScreen() { } }; - const changeChannel = (direction: "next" | "prev") => { - if (channels.length === 0) return; - let newIndex = - direction === "next" - ? (currentChannelIndex + 1) % channels.length - : (currentChannelIndex - 1 + channels.length) % channels.length; - setCurrentChannelIndex(newIndex); - showChannelTitle(channels[newIndex].name); - }; + const changeChannel = useCallback( + (direction: "next" | "prev") => { + if (channels.length === 0) return; + let newIndex = + direction === "next" + ? (currentChannelIndex + 1) % channels.length + : (currentChannelIndex - 1 + channels.length) % channels.length; + setCurrentChannelIndex(newIndex); + showChannelTitle(channels[newIndex].name); + }, + [channels, currentChannelIndex] + ); const handleTVEvent = useCallback( (event: HWEvent) => { @@ -83,7 +85,7 @@ export default function LiveScreen() { else if (event.eventType === "left") changeChannel("prev"); else if (event.eventType === "right") changeChannel("next"); }, - [channels, currentChannelIndex, isChannelListVisible] + [changeChannel, isChannelListVisible] ); useTVEventHandler(handleTVEvent); diff --git a/components/settings/VideoSourceSection.tsx b/components/settings/VideoSourceSection.tsx index a15dd4f..5c42a1b 100644 --- a/components/settings/VideoSourceSection.tsx +++ b/components/settings/VideoSourceSection.tsx @@ -31,7 +31,7 @@ export const VideoSourceSection: React.FC = ({ onChange const resourcesList = await api.getResources(); setResources(resourcesList); - if (videoSource.enabledAll && resourcesList.length === 0) { + if (videoSource.enabledAll && Object.keys(videoSource.sources).length === 0) { const allResourceKeys: { [key: string]: boolean } = {}; for (const resource of resourcesList) { allResourceKeys[resource.key] = true; diff --git a/package.json b/package.json index 39865f9..f793657 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "OrionTV", "private": true, "main": "expo-router/entry", - "version": "1.1.1", + "version": "1.1.2", "scripts": { "start": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start", "start-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",