xref: /MusicFree/src/pages/musicDetail/components/navBar.tsx (revision 2aa881935ca35b8fb1abc4206e0dc35149231456)
1import React from 'react';
2import {StyleSheet, Text, View} from 'react-native';
3import rpx from '@/utils/rpx';
4import {IconButton} from 'react-native-paper';
5import MusicQueue from '@/core/musicQueue';
6import {useNavigation} from '@react-navigation/native';
7import Tag from '@/components/base/tag';
8import {fontSizeConst, fontWeightConst} from '@/constants/uiConst';
9import Share from 'react-native-share';
10import {B64Asset} from '@/constants/assetsConst';
11
12export default function NavBar() {
13    const navigation = useNavigation();
14    const musicItem = MusicQueue.useCurrentMusicItem();
15    // const {showShare} = useShare();
16
17    return (
18        <View style={style.wrapper}>
19            <IconButton
20                icon="arrow-left"
21                size={rpx(48)}
22                color="white"
23                onPress={() => {
24                    navigation.goBack();
25                }}
26            />
27            <View style={style.headerContent}>
28                <Text numberOfLines={1} style={style.headerTitleText}>
29                    {musicItem?.title ?? '无音乐'}
30                </Text>
31                <View style={style.headerDesc}>
32                    <Text style={style.headerArtistText}>
33                        {musicItem?.artist}
34                    </Text>
35                    {musicItem?.platform ? (
36                        <Tag tagName={musicItem.platform} />
37                    ) : null}
38                </View>
39            </View>
40            <IconButton
41                icon="share"
42                color="white"
43                size={rpx(48)}
44                onPress={async () => {
45                    try {
46                        await Share.open({
47                            type: 'image/jpeg',
48                            title: 'MusicFree-一个插件化的免费音乐播放器',
49                            message: 'MusicFree-一个插件化的免费音乐播放器',
50                            url: B64Asset.share,
51                            subject: 'MusicFree分享',
52                        });
53                    } catch {}
54                }}
55            />
56        </View>
57    );
58}
59
60const style = StyleSheet.create({
61    wrapper: {
62        width: rpx(750),
63        height: rpx(150),
64        flexDirection: 'row',
65        alignItems: 'center',
66        justifyContent: 'space-between',
67    },
68    headerContent: {
69        flex: 1,
70        height: rpx(150),
71        justifyContent: 'center',
72        alignItems: 'center',
73        maxWidth: rpx(640),
74    },
75    headerTitleText: {
76        color: 'white',
77        fontWeight: fontWeightConst.semibold,
78        fontSize: fontSizeConst.title,
79        marginBottom: rpx(12),
80        includeFontPadding: false,
81    },
82    headerDesc: {
83        height: rpx(32),
84        flexDirection: 'row',
85        alignItems: 'center',
86    },
87    headerArtistText: {
88        color: 'white',
89        fontSize: fontSizeConst.subTitle,
90        includeFontPadding: false,
91        maxWidth: rpx(540),
92    },
93});
94