xref: /MusicFree/src/pages/artistDetail/components/body.tsx (revision 1119c2ea435417cd5c53719f91691ff2b1aa8670)
14060c00aS猫头猫import React, {useState} from 'react';
220e2869eS猫头猫import {StyleSheet, Text} from 'react-native';
3be474dd8S猫头猫import rpx from '@/utils/rpx';
44060c00aS猫头猫import {SceneMap, TabBar, TabView} from 'react-native-tab-view';
520e2869eS猫头猫import {fontWeightConst} from '@/constants/uiConst';
620e2869eS猫头猫import ResultList from './resultList';
720e2869eS猫头猫import {useAtomValue} from 'jotai';
820e2869eS猫头猫import {queryResultAtom} from '../store/atoms';
920e2869eS猫头猫import content from './content';
10*1119c2eaS猫头猫import useColors from '@/hooks/useColors';
1120e2869eS猫头猫
1220e2869eS猫头猫const sceneMap: Record<string, React.FC> = {
1320e2869eS猫头猫    album: BodyContentWrapper,
1420e2869eS猫头猫    music: BodyContentWrapper,
1520e2869eS猫头猫};
1620e2869eS猫头猫
1720e2869eS猫头猫const routes = [
1820e2869eS猫头猫    {
1920e2869eS猫头猫        key: 'music',
2020e2869eS猫头猫        title: '单曲',
2120e2869eS猫头猫    },
2220e2869eS猫头猫    {
2320e2869eS猫头猫        key: 'album',
2420e2869eS猫头猫        title: '专辑',
2520e2869eS猫头猫    },
2620e2869eS猫头猫];
27be474dd8S猫头猫
284060c00aS猫头猫export default function Body() {
2920e2869eS猫头猫    const [index, setIndex] = useState(0);
30*1119c2eaS猫头猫    const colors = useColors();
3120e2869eS猫头猫
32be474dd8S猫头猫    return (
3320e2869eS猫头猫        <TabView
3420e2869eS猫头猫            lazy
3520e2869eS猫头猫            style={style.wrapper}
3620e2869eS猫头猫            navigationState={{
3720e2869eS猫头猫                index,
3820e2869eS猫头猫                routes,
3920e2869eS猫头猫            }}
4020e2869eS猫头猫            renderTabBar={props => (
4120e2869eS猫头猫                <TabBar
4220e2869eS猫头猫                    {...props}
437b28964fS猫头猫                    style={style.transparentColor}
4420e2869eS猫头猫                    tabStyle={{
45*1119c2eaS猫头猫                        width: 'auto',
4620e2869eS猫头猫                    }}
4720e2869eS猫头猫                    renderIndicator={() => null}
4820e2869eS猫头猫                    pressColor="transparent"
49*1119c2eaS猫头猫                    inactiveColor={colors.text}
50*1119c2eaS猫头猫                    activeColor={colors.primary}
5120e2869eS猫头猫                    renderLabel={({route, focused, color}) => (
5220e2869eS猫头猫                        <Text
5320e2869eS猫头猫                            numberOfLines={1}
5420e2869eS猫头猫                            style={{
55*1119c2eaS猫头猫                                width: rpx(160),
5620e2869eS猫头猫                                fontWeight: focused
5720e2869eS猫头猫                                    ? fontWeightConst.bolder
58*1119c2eaS猫头猫                                    : fontWeightConst.medium,
5920e2869eS猫头猫                                color,
60*1119c2eaS猫头猫                                textAlign: 'center',
6120e2869eS猫头猫                            }}>
6220e2869eS猫头猫                            {route.title}
6320e2869eS猫头猫                        </Text>
644060c00aS猫头猫                    )}
654060c00aS猫头猫                />
6620e2869eS猫头猫            )}
6720e2869eS猫头猫            renderScene={SceneMap(sceneMap)}
6820e2869eS猫头猫            onIndexChange={setIndex}
694060c00aS猫头猫            initialLayout={{width: rpx(750)}}
704060c00aS猫头猫        />
7120e2869eS猫头猫    );
7220e2869eS猫头猫}
7320e2869eS猫头猫
7420e2869eS猫头猫export function BodyContentWrapper(props: any) {
7520e2869eS猫头猫    const tab: IArtist.ArtistMediaType = props.route.key;
7620e2869eS猫头猫    const queryResult = useAtomValue(queryResultAtom);
7720e2869eS猫头猫
7820e2869eS猫头猫    const Component = content[tab];
7920e2869eS猫头猫    const renderItem = ({item, index}: any) => (
804060c00aS猫头猫        <Component item={item} index={index} />
8120e2869eS猫头猫    );
8220e2869eS猫头猫
8320e2869eS猫头猫    return (
844060c00aS猫头猫        <ResultList tab={tab} data={queryResult[tab]} renderItem={renderItem} />
85be474dd8S猫头猫    );
86be474dd8S猫头猫}
87be474dd8S猫头猫
88be474dd8S猫头猫const style = StyleSheet.create({
89be474dd8S猫头猫    wrapper: {
9020e2869eS猫头猫        zIndex: 100,
91be474dd8S猫头猫    },
927b28964fS猫头猫    transparentColor: {
937b28964fS猫头猫        backgroundColor: 'transparent',
947b28964fS猫头猫        shadowColor: 'transparent',
957b28964fS猫头猫        borderColor: 'transparent',
967b28964fS猫头猫    },
97be474dd8S猫头猫});
98