xref: /MusicFree/src/pages/searchPage/components/resultPanel/index.tsx (revision 0b940038696677ddf4d2a91434ce49a8383fecf4)
1bf6e62f2S猫头猫/**
2bf6e62f2S猫头猫 * 搜索结果面板 一级页
3bf6e62f2S猫头猫 */
4d139abf1S猫头猫import React, {memo, useState} from 'react';
5bf6e62f2S猫头猫import {StyleSheet, Text, View} from 'react-native';
6bf6e62f2S猫头猫import rpx 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猫头猫interface IResultPanelProps {}
15bf6e62f2S猫头猫
16bf6e62f2S猫头猫const routes = results;
17bf6e62f2S猫头猫
18d139abf1S猫头猫const getRouterScene = (
19d139abf1S猫头猫  routes: Array<{key: ICommon.SupportMediaType; title: string}>,
20d139abf1S猫头猫) => {
21bf6e62f2S猫头猫  const scene: Record<string, () => JSX.Element> = {};
22bf6e62f2S猫头猫  routes.forEach(r => {
23bf6e62f2S猫头猫    scene[r.key] = () => <ResultSubPanel tab={r.key}></ResultSubPanel>;
24bf6e62f2S猫头猫  });
25bf6e62f2S猫头猫  return SceneMap(scene);
26bf6e62f2S猫头猫};
27bf6e62f2S猫头猫
28bf6e62f2S猫头猫const renderScene = getRouterScene(routes);
29bf6e62f2S猫头猫
30d139abf1S猫头猫function ResultPanel(props: IResultPanelProps) {
31bf6e62f2S猫头猫  const [index, setIndex] = useState(0);
32bf6e62f2S猫头猫  const {colors} = useTheme();
33bf6e62f2S猫头猫
34bf6e62f2S猫头猫  return (
35bf6e62f2S猫头猫    <TabView
36*0b940038S猫头猫      lazy
37bf6e62f2S猫头猫      navigationState={{
38bf6e62f2S猫头猫        index,
39bf6e62f2S猫头猫        routes,
40bf6e62f2S猫头猫      }}
41bf6e62f2S猫头猫      renderTabBar={props => (
42bf6e62f2S猫头猫        <TabBar
43bf6e62f2S猫头猫          {...props}
44bf6e62f2S猫头猫          style={{
45bf6e62f2S猫头猫            backgroundColor: Color(colors.primary).alpha(0.7).toString(),
46bf6e62f2S猫头猫            shadowColor: 'transparent',
47bf6e62f2S猫头猫            borderColor: 'transparent',
48bf6e62f2S猫头猫          }}
49bf6e62f2S猫头猫          tabStyle={{
50bf6e62f2S猫头猫            width: rpx(128),
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),
66bf6e62f2S猫头猫          }}></TabBar>
67bf6e62f2S猫头猫      )}
68bf6e62f2S猫头猫      style={{
69bf6e62f2S猫头猫        backgroundColor: colors.background,
70bf6e62f2S猫头猫      }}
71bf6e62f2S猫头猫      renderScene={renderScene}
72bf6e62f2S猫头猫      onIndexChange={setIndex}
73bf6e62f2S猫头猫      initialLayout={{width: rpx(750)}}></TabView>
74bf6e62f2S猫头猫  );
75bf6e62f2S猫头猫}
76bf6e62f2S猫头猫
77d139abf1S猫头猫export default memo(ResultPanel);
78