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:
@@ -19,9 +19,12 @@ export function MiniPlayer() {
|
||||
const pan = useRef(new Animated.ValueXY()).current;
|
||||
const isDragging = useRef(false);
|
||||
|
||||
// 用 ref 保持最新值,避免 PanResponder 闭包捕获过期的初始值
|
||||
const storeRef = useRef({ bvid, clearVideo, router });
|
||||
storeRef.current = { bvid, clearVideo, router };
|
||||
|
||||
const panResponder = useRef(
|
||||
PanResponder.create({
|
||||
// 从 start 阶段即抢占响应权,确保拖动可靠触发
|
||||
onStartShouldSetPanResponder: () => true,
|
||||
onPanResponderGrant: () => {
|
||||
isDragging.current = false;
|
||||
@@ -38,16 +41,15 @@ export function MiniPlayer() {
|
||||
onPanResponderRelease: (evt) => {
|
||||
pan.flattenOffset();
|
||||
if (!isDragging.current) {
|
||||
// 点击:通过坐标判断是关闭还是跳转
|
||||
const { locationX, locationY } = evt.nativeEvent;
|
||||
const { bvid: vid, clearVideo: clear, router: r } = storeRef.current;
|
||||
if (locationX > MINI_W - 28 && locationY < 28) {
|
||||
clearVideo();
|
||||
clear();
|
||||
} else {
|
||||
router.push(`/video/${bvid}` as any);
|
||||
r.push(`/video/${vid}` as any);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 拖动:吸附到最近边缘
|
||||
const { width: sw, height: sh } = Dimensions.get('window');
|
||||
const curX = (pan.x as any)._value;
|
||||
const curY = (pan.y as any)._value;
|
||||
|
||||
Reference in New Issue
Block a user