mirror of
https://gh-proxy.org/https://github.com/tiajinsha/JKVideo
synced 2026-07-07 23:18:38 +08:00
fix: 修复小窗闭包过期、详情页 loading 卡死、视频播放器性能问题
- 小窗 PanResponder 用 storeRef 替代闭包捕获,修复 roomId/bvid 始终为初始值 - useLiveDetail 用 ref 比对替代 cancelled 标志,防止 fetch 被意外取消 - 详情页 useLayoutEffect 同步清除小窗,BigVideoCard 小窗活跃时跳过播放 - 视频播放器竖屏/全屏互斥渲染,减半解码器占用 - onProgress 节流 + 退出全屏强制恢复播放
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import React, { useState, useEffect, useLayoutEffect, useRef } from "react";
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
@@ -24,9 +24,16 @@ type Tab = "intro" | "danmaku";
|
||||
|
||||
export default function LiveDetailScreen() {
|
||||
const { roomId } = useLocalSearchParams<{ roomId: string }>();
|
||||
console.log("LiveDetailScreen params:", { roomId });
|
||||
const router = useRouter();
|
||||
const theme = useTheme();
|
||||
const id = parseInt(roomId ?? "0", 10);
|
||||
|
||||
// 进入详情页时立即清除小窗(useLayoutEffect 在绘制前同步执行)
|
||||
useLayoutEffect(() => {
|
||||
useLiveStore.getState().clearLive();
|
||||
}, []);
|
||||
|
||||
const { room, anchor, stream, loading, error, changeQuality } =
|
||||
useLiveDetail(id);
|
||||
const [tab, setTab] = useState<Tab>("intro");
|
||||
@@ -37,15 +44,7 @@ export default function LiveDetailScreen() {
|
||||
const qualities = stream?.qualities ?? [];
|
||||
const currentQn = stream?.qn ?? 0;
|
||||
|
||||
const { setLive, clearLive } = useLiveStore();
|
||||
|
||||
// 进入该直播间时,若小窗正在播放同一房间,清除小窗避免双播
|
||||
// 仅在挂载时运行一次(用 getState 读值,不创建响应式依赖)
|
||||
useEffect(() => {
|
||||
if (useLiveStore.getState().roomId === id) {
|
||||
clearLive();
|
||||
}
|
||||
}, []);
|
||||
const setLive = useLiveStore(s => s.setLive);
|
||||
|
||||
const actualRoomId = room?.roomid ?? id;
|
||||
const { danmakus, giftCounts } = useLiveDanmaku(isLive ? actualRoomId : 0);
|
||||
|
||||
Reference in New Issue
Block a user