2026-05-12 20:27:30 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
import { View, Text, Image, StyleSheet, Animated } from 'react-native';
|
2026-03-10 19:04:18 +08:00
|
|
|
import { useRouter } from 'expo-router';
|
|
|
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
|
|
import { Ionicons } from '@expo/vector-icons';
|
|
|
|
|
import { useVideoStore } from '../store/videoStore';
|
2026-03-10 20:47:14 +08:00
|
|
|
import { proxyImageUrl } from '../utils/imageUrl';
|
2026-05-12 20:27:30 +08:00
|
|
|
import { useMiniDrag } from '../hooks/useMiniDrag';
|
2026-03-10 19:04:18 +08:00
|
|
|
|
2026-03-14 18:25:13 +08:00
|
|
|
const MINI_W = 160;
|
|
|
|
|
const MINI_H = 90;
|
|
|
|
|
|
2026-03-10 19:04:18 +08:00
|
|
|
export function MiniPlayer() {
|
|
|
|
|
const { isActive, bvid, title, cover, clearVideo } = useVideoStore();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const insets = useSafeAreaInsets();
|
|
|
|
|
|
2026-05-12 20:27:30 +08:00
|
|
|
const { pan, panHandlers } = useMiniDrag({
|
|
|
|
|
width: MINI_W,
|
|
|
|
|
height: MINI_H,
|
|
|
|
|
hitClose: (x, y) => x > MINI_W - 28 && y < 28,
|
|
|
|
|
onTap: () => router.push(`/video/${bvid}` as any),
|
|
|
|
|
onClose: clearVideo,
|
|
|
|
|
});
|
2026-03-10 19:04:18 +08:00
|
|
|
|
|
|
|
|
if (!isActive) return null;
|
|
|
|
|
|
|
|
|
|
const bottomOffset = insets.bottom + 16;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Animated.View
|
|
|
|
|
style={[styles.container, { bottom: bottomOffset, transform: pan.getTranslateTransform() }]}
|
2026-05-12 20:27:30 +08:00
|
|
|
{...panHandlers}
|
2026-03-10 19:04:18 +08:00
|
|
|
>
|
2026-03-25 13:36:28 +08:00
|
|
|
<Image source={{ uri: proxyImageUrl(cover) }} style={styles.cover} />
|
|
|
|
|
<Text style={styles.title} numberOfLines={1}>{title}</Text>
|
2026-05-12 20:27:30 +08:00
|
|
|
{/* 关闭按钮仅作视觉展示,点击逻辑由 hitClose 坐标判断处理 */}
|
2026-03-25 13:36:28 +08:00
|
|
|
<View style={styles.closeBtn}>
|
2026-03-10 19:04:18 +08:00
|
|
|
<Ionicons name="close" size={14} color="#fff" />
|
2026-03-25 13:36:28 +08:00
|
|
|
</View>
|
2026-03-10 19:04:18 +08:00
|
|
|
</Animated.View>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
container: {
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
right: 12,
|
2026-03-25 13:36:28 +08:00
|
|
|
width: MINI_W,
|
|
|
|
|
height: MINI_H,
|
2026-03-10 19:04:18 +08:00
|
|
|
borderRadius: 8,
|
|
|
|
|
backgroundColor: '#1a1a1a',
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
elevation: 8,
|
|
|
|
|
shadowColor: '#000',
|
|
|
|
|
shadowOffset: { width: 0, height: 2 },
|
|
|
|
|
shadowOpacity: 0.3,
|
|
|
|
|
shadowRadius: 4,
|
|
|
|
|
},
|
|
|
|
|
cover: { width: '100%', height: 64, backgroundColor: '#333' },
|
|
|
|
|
title: {
|
|
|
|
|
color: '#fff',
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
paddingHorizontal: 6,
|
|
|
|
|
paddingVertical: 4,
|
|
|
|
|
lineHeight: 14,
|
|
|
|
|
},
|
|
|
|
|
closeBtn: {
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
top: 4,
|
|
|
|
|
right: 4,
|
|
|
|
|
width: 18,
|
|
|
|
|
height: 18,
|
|
|
|
|
borderRadius: 9,
|
|
|
|
|
backgroundColor: 'rgba(0,0,0,0.6)',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
},
|
|
|
|
|
});
|