xref: /MusicFree/src/pages/searchPage/components/resultPanel/index.tsx (revision e650bfb34226e2a09d15cbf7832c4805a87cd60e)
1bf6e62f2S猫头猫/**
2bf6e62f2S猫头猫 * 搜索结果面板 一级页
3bf6e62f2S猫头猫 */
4d139abf1S猫头猫import React, {memo, useState} from 'react';
54060c00aS猫头猫import {Text} from 'react-native';
6c446f2b8S猫头猫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 Color from 'color';
12*e650bfb3S猫头猫import useColors from '@/hooks/useColors';
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);
30*e650bfb3S猫头猫    const colors = useColors();
31bf6e62f2S猫头猫
32bf6e62f2S猫头猫    return (
33bf6e62f2S猫头猫        <TabView
340b940038S猫头猫            lazy
35bf6e62f2S猫头猫            navigationState={{
36bf6e62f2S猫头猫                index,
37bf6e62f2S猫头猫                routes,
38bf6e62f2S猫头猫            }}
39bf6e62f2S猫头猫            renderTabBar={props => (
40bf6e62f2S猫头猫                <TabBar
41bf6e62f2S猫头猫                    {...props}
42771839b6S猫头猫                    scrollEnabled
43bf6e62f2S猫头猫                    style={{
444060c00aS猫头猫                        backgroundColor: Color(colors.primary)
454060c00aS猫头猫                            .alpha(0.7)
464060c00aS猫头猫                            .toString(),
47bf6e62f2S猫头猫                        shadowColor: 'transparent',
48bf6e62f2S猫头猫                        borderColor: 'transparent',
49bf6e62f2S猫头猫                    }}
50bf6e62f2S猫头猫                    tabStyle={{
5120e2869eS猫头猫                        width: rpx(200),
52bf6e62f2S猫头猫                    }}
53bf6e62f2S猫头猫                    renderLabel={({route, focused, color}) => (
54bf6e62f2S猫头猫                        <Text
55bf6e62f2S猫头猫                            style={{
56d139abf1S猫头猫                                fontWeight: focused
57d139abf1S猫头猫                                    ? fontWeightConst.bolder
58d139abf1S猫头猫                                    : fontWeightConst.bold,
59bf6e62f2S猫头猫                                color,
60bf6e62f2S猫头猫                            }}>
61bf6e62f2S猫头猫                            {route.title}
62bf6e62f2S猫头猫                        </Text>
63bf6e62f2S猫头猫                    )}
64bf6e62f2S猫头猫                    indicatorStyle={{
65bf6e62f2S猫头猫                        backgroundColor: colors.text,
66bf6e62f2S猫头猫                        height: rpx(4),
674060c00aS猫头猫                    }}
684060c00aS猫头猫                />
69bf6e62f2S猫头猫            )}
70bf6e62f2S猫头猫            style={{
71bf6e62f2S猫头猫                backgroundColor: colors.background,
72bf6e62f2S猫头猫            }}
73bf6e62f2S猫头猫            renderScene={renderScene}
74bf6e62f2S猫头猫            onIndexChange={setIndex}
75c446f2b8S猫头猫            initialLayout={{width: vw(100)}}
764060c00aS猫头猫        />
77bf6e62f2S猫头猫    );
78bf6e62f2S猫头猫}
79bf6e62f2S猫头猫
80d139abf1S猫头猫export default memo(ResultPanel);
81