mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-04 03:36:29 +08:00
fix: Update channel change logic to use useCallback for better performance; adjust resource check in VideoSourceSection
This commit is contained in:
24
app/live.tsx
24
app/live.tsx
@@ -4,7 +4,6 @@ import LivePlayer from "@/components/LivePlayer";
|
|||||||
import { fetchAndParseM3u, getPlayableUrl, Channel } from "@/services/m3u";
|
import { fetchAndParseM3u, getPlayableUrl, Channel } from "@/services/m3u";
|
||||||
import { ThemedView } from "@/components/ThemedView";
|
import { ThemedView } from "@/components/ThemedView";
|
||||||
import { StyledButton } from "@/components/StyledButton";
|
import { StyledButton } from "@/components/StyledButton";
|
||||||
import { AVPlaybackStatus } from "expo-av";
|
|
||||||
import { useSettingsStore } from "@/stores/settingsStore";
|
import { useSettingsStore } from "@/stores/settingsStore";
|
||||||
|
|
||||||
export default function LiveScreen() {
|
export default function LiveScreen() {
|
||||||
@@ -66,15 +65,18 @@ export default function LiveScreen() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeChannel = (direction: "next" | "prev") => {
|
const changeChannel = useCallback(
|
||||||
if (channels.length === 0) return;
|
(direction: "next" | "prev") => {
|
||||||
let newIndex =
|
if (channels.length === 0) return;
|
||||||
direction === "next"
|
let newIndex =
|
||||||
? (currentChannelIndex + 1) % channels.length
|
direction === "next"
|
||||||
: (currentChannelIndex - 1 + channels.length) % channels.length;
|
? (currentChannelIndex + 1) % channels.length
|
||||||
setCurrentChannelIndex(newIndex);
|
: (currentChannelIndex - 1 + channels.length) % channels.length;
|
||||||
showChannelTitle(channels[newIndex].name);
|
setCurrentChannelIndex(newIndex);
|
||||||
};
|
showChannelTitle(channels[newIndex].name);
|
||||||
|
},
|
||||||
|
[channels, currentChannelIndex]
|
||||||
|
);
|
||||||
|
|
||||||
const handleTVEvent = useCallback(
|
const handleTVEvent = useCallback(
|
||||||
(event: HWEvent) => {
|
(event: HWEvent) => {
|
||||||
@@ -83,7 +85,7 @@ export default function LiveScreen() {
|
|||||||
else if (event.eventType === "left") changeChannel("prev");
|
else if (event.eventType === "left") changeChannel("prev");
|
||||||
else if (event.eventType === "right") changeChannel("next");
|
else if (event.eventType === "right") changeChannel("next");
|
||||||
},
|
},
|
||||||
[channels, currentChannelIndex, isChannelListVisible]
|
[changeChannel, isChannelListVisible]
|
||||||
);
|
);
|
||||||
|
|
||||||
useTVEventHandler(handleTVEvent);
|
useTVEventHandler(handleTVEvent);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const VideoSourceSection: React.FC<VideoSourceSectionProps> = ({ onChange
|
|||||||
const resourcesList = await api.getResources();
|
const resourcesList = await api.getResources();
|
||||||
setResources(resourcesList);
|
setResources(resourcesList);
|
||||||
|
|
||||||
if (videoSource.enabledAll && resourcesList.length === 0) {
|
if (videoSource.enabledAll && Object.keys(videoSource.sources).length === 0) {
|
||||||
const allResourceKeys: { [key: string]: boolean } = {};
|
const allResourceKeys: { [key: string]: boolean } = {};
|
||||||
for (const resource of resourcesList) {
|
for (const resource of resourcesList) {
|
||||||
allResourceKeys[resource.key] = true;
|
allResourceKeys[resource.key] = true;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "OrionTV",
|
"name": "OrionTV",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "expo-router/entry",
|
"main": "expo-router/entry",
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
"start": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
||||||
"start-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
"start-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
||||||
|
|||||||
Reference in New Issue
Block a user