Implement back navigation and control visibility in PlayScreen

- Added back navigation functionality using the router in PlayScreen.
- Implemented hardware back button handling to toggle controls visibility.
- Updated useTVRemoteHandler to show controls on down key press.
This commit is contained in:
zimplexing
2025-07-08 17:03:15 +08:00
parent 5b4c8db317
commit 9f721c22d5
2 changed files with 21 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import React, { useEffect, useRef } from "react";
import { View, StyleSheet, TouchableOpacity, ActivityIndicator } from "react-native";
import { useLocalSearchParams } from "expo-router";
import { View, StyleSheet, TouchableOpacity, ActivityIndicator, BackHandler } from "react-native";
import { useLocalSearchParams, useRouter } from "expo-router";
import { Video, ResizeMode } from "expo-av";
import { useKeepAwake } from "expo-keep-awake";
import { ThemedView } from "@/components/ThemedView";
@@ -14,6 +14,7 @@ import { useTVRemoteHandler } from "@/hooks/useTVRemoteHandler";
export default function PlayScreen() {
const videoRef = useRef<Video>(null);
const router = useRouter();
useKeepAwake();
const { source, id, episodeIndex, position } = useLocalSearchParams<{
source: string;
@@ -55,6 +56,21 @@ export default function PlayScreen() {
const { onScreenPress } = useTVRemoteHandler();
useEffect(() => {
const backAction = () => {
if (showControls) {
setShowControls(false);
return true;
}
router.back();
return true;
};
const backHandler = BackHandler.addEventListener("hardwareBackPress", backAction);
return () => backHandler.remove();
}, [showControls, showEpisodeModal, setShowControls, setShowEpisodeModal, router]);
if (!detail && isLoading) {
return (
<ThemedView style={[styles.container, styles.centered]}>

View File

@@ -73,6 +73,9 @@ export const useTVRemoteHandler = () => {
case "longRight":
seek(60000); // 快进60秒
break;
case "down":
setShowControls(true);
break;
}
}
},