xref: /MusicFree/src/pages/searchPage/components/resultPanel/index.tsx (revision c446f2b83c1bd26ef7ee96c37926a9cbde29bc16)
1bf6e62f2S猫头猫/**
2bf6e62f2S猫头猫 * 搜索结果面板 一级页
3bf6e62f2S猫头猫 */
4d139abf1S猫头猫import React, {memo, useState} from 'react';
54060c00aS猫头猫import {Text} from 'react-native';
6*c446f2b8S猫头猫import rpx, {vw} from '@/utils/rpx';
7bf6e62f2S猫头猫import {SceneMap, TabBar, TabView} from 'react-native-tab-view';
8bf6e62f2S猫头猫import ResultSubPanel from './resultSubPanel';
9bf6e62f2S猫头猫import results from './results';
10bf6e62f2S猫头猫import {fontWeightConst} from '@/constants/uiConst';
11bf6e62f2S猫头猫import {useTheme} from 'react-native-paper';
12bf6e62f2S猫头猫import Color from 'color';
13bf6e62f2S猫头猫
14bf6e62f2S猫头猫const routes = results;
15bf6e62f2S猫头猫
16d139abf1S猫头猫const getRouterScene = (
17d139abf1S猫头猫    routes: Array<{key: ICommon.SupportMediaType; title: string}>,
18d139abf1S猫头猫) => {
19bf6e62f2S猫头猫    const scene: Record<string, () => JSX.Element> = {};
20bf6e62f2S猫头猫    routes.forEach(r => {
214060c00aS猫头猫        scene[r.key] = () => <ResultSubPanel tab={r.key} />;
22bf6e62f2S猫头猫    });
23bf6e62f2S猫头猫    return SceneMap(scene);
24bf6e62f2S猫头猫};
25bf6e62f2S猫头猫
26bf6e62f2S猫头猫const renderScene = getRouterScene(routes);
27bf6e62f2S猫头猫
284060c00aS猫头猫function ResultPanel() {
29bf6e62f2S猫头猫    const [index, setIndex] = useState(0);
30bf6e62f2S猫头猫    const {colors} = useTheme();
31bf6e62f2S猫头猫
32bf6e62f2S猫头猫    return (
33bf6e62f2S猫头猫        <TabView
340b940038S猫头猫            lazy
35bf6e62f2S猫头猫            navigationState={{
36bf6e62f2S猫头猫                index,
37bf6e62f2S猫头猫                routes,
38bf6e62f2S猫头猫            }}
39bf6e62f2S猫头猫            renderTabBar={props => (
40bf6e62f2S猫头猫                <TabBar
41bf6e62f2S猫头猫                    {...props}
42bf6e62f2S猫头猫                    style={{
434060c00aS猫头猫                        backgroundColor: Color(colors.primary)
444060c00aS猫头猫                            .alpha(0.7)
454060c00aS猫头猫                            .toString(),
46bf6e62f2S猫头猫                        shadowColor: 'transparent',
47bf6e62f2S猫头猫                        borderColor: 'transparent',
48bf6e62f2S猫头猫                    }}
49bf6e62f2S猫头猫                    tabStyle={{
5020e2869eS猫头猫                        width: rpx(200),
51bf6e62f2S猫头猫                    }}
52bf6e62f2S猫头猫                    renderLabel={({route, focused, color}) => (
53bf6e62f2S猫头猫                        <Text
54bf6e62f2S猫头猫                            style={{
55d139abf1S猫头猫                                fontWeight: focused
56d139abf1S猫头猫                                    ? fontWeightConst.bolder
57d139abf1S猫头猫                                    : fontWeightConst.bold,
58bf6e62f2S猫头猫                                color,
59bf6e62f2S猫头猫                            }}>
60bf6e62f2S猫头猫                            {route.title}
61bf6e62f2S猫头猫                        </Text>
62bf6e62f2S猫头猫                    )}
63bf6e62f2S猫头猫                    indicatorStyle={{
64bf6e62f2S猫头猫                        backgroundColor: colors.text,
65bf6e62f2S猫头猫                        height: rpx(4),
664060c00aS猫头猫                    }}
674060c00aS猫头猫                />
68bf6e62f2S猫头猫            )}
69bf6e62f2S猫头猫            style={{
70bf6e62f2S猫头猫                backgroundColor: colors.background,
71bf6e62f2S猫头猫            }}
72bf6e62f2S猫头猫            renderScene={renderScene}
73bf6e62f2S猫头猫            onIndexChange={setIndex}
74*c446f2b8S猫头猫            initialLayout={{width: vw(100)}}
754060c00aS猫头猫        />
76bf6e62f2S猫头猫    );
77bf6e62f2S猫头猫}
78bf6e62f2S猫头猫
79d139abf1S猫头猫export default memo(ResultPanel);
80