fix: Update channel change logic to use useCallback for better performance; adjust resource check in VideoSourceSection

This commit is contained in:
zimplexing
2025-07-11 21:44:15 +08:00
parent 6df4f256e9
commit fbe858715a
3 changed files with 15 additions and 13 deletions

View File

@@ -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);

View File

@@ -31,7 +31,7 @@ export const VideoSourceSection: React.FC<VideoSourceSectionProps> = ({ 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;

View File

@@ -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",