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'; 11e650bfb3S猫头猫import useColors from '@/hooks/useColors'; 12bf6e62f2S猫头猫 13bf6e62f2S猫头猫const routes = results; 14bf6e62f2S猫头猫 15d139abf1S猫头猫const getRouterScene = ( 16d139abf1S猫头猫 routes: Array<{key: ICommon.SupportMediaType; title: string}>, 17d139abf1S猫头猫) => { 18bf6e62f2S猫头猫 const scene: Record<string, () => JSX.Element> = {}; 19bf6e62f2S猫头猫 routes.forEach(r => { 204060c00aS猫头猫 scene[r.key] = () => <ResultSubPanel tab={r.key} />; 21bf6e62f2S猫头猫 }); 22bf6e62f2S猫头猫 return SceneMap(scene); 23bf6e62f2S猫头猫}; 24bf6e62f2S猫头猫 25bf6e62f2S猫头猫const renderScene = getRouterScene(routes); 26bf6e62f2S猫头猫 274060c00aS猫头猫function ResultPanel() { 28bf6e62f2S猫头猫 const [index, setIndex] = useState(0); 29e650bfb3S猫头猫 const colors = useColors(); 30bf6e62f2S猫头猫 31bf6e62f2S猫头猫 return ( 32bf6e62f2S猫头猫 <TabView 330b940038S猫头猫 lazy 34bf6e62f2S猫头猫 navigationState={{ 35bf6e62f2S猫头猫 index, 36bf6e62f2S猫头猫 routes, 37bf6e62f2S猫头猫 }} 38bf6e62f2S猫头猫 renderTabBar={props => ( 39bf6e62f2S猫头猫 <TabBar 40bf6e62f2S猫头猫 {...props} 41771839b6S猫头猫 scrollEnabled 42bf6e62f2S猫头猫 style={{ 43*1119c2eaS猫头猫 backgroundColor: colors.backdrop, 44bf6e62f2S猫头猫 shadowColor: 'transparent', 45bf6e62f2S猫头猫 borderColor: 'transparent', 46bf6e62f2S猫头猫 }} 47*1119c2eaS猫头猫 inactiveColor={colors.text} 48*1119c2eaS猫头猫 activeColor={colors.primary} 49bf6e62f2S猫头猫 tabStyle={{ 50*1119c2eaS猫头猫 width: 'auto', 51bf6e62f2S猫头猫 }} 52bf6e62f2S猫头猫 renderLabel={({route, focused, color}) => ( 53bf6e62f2S猫头猫 <Text 54*1119c2eaS猫头猫 numberOfLines={1} 55bf6e62f2S猫头猫 style={{ 56*1119c2eaS猫头猫 width: rpx(160), 57d139abf1S猫头猫 fontWeight: focused 58d139abf1S猫头猫 ? fontWeightConst.bolder 59*1119c2eaS猫头猫 : fontWeightConst.medium, 60bf6e62f2S猫头猫 color, 61*1119c2eaS猫头猫 textAlign: 'center', 62bf6e62f2S猫头猫 }}> 63bf6e62f2S猫头猫 {route.title} 64bf6e62f2S猫头猫 </Text> 65bf6e62f2S猫头猫 )} 66bf6e62f2S猫头猫 indicatorStyle={{ 67*1119c2eaS猫头猫 backgroundColor: colors.primary, 68bf6e62f2S猫头猫 height: rpx(4), 694060c00aS猫头猫 }} 704060c00aS猫头猫 /> 71bf6e62f2S猫头猫 )} 72bf6e62f2S猫头猫 style={{ 73bf6e62f2S猫头猫 backgroundColor: colors.background, 74bf6e62f2S猫头猫 }} 75bf6e62f2S猫头猫 renderScene={renderScene} 76bf6e62f2S猫头猫 onIndexChange={setIndex} 77c446f2b8S猫头猫 initialLayout={{width: vw(100)}} 784060c00aS猫头猫 /> 79bf6e62f2S猫头猫 ); 80bf6e62f2S猫头猫} 81bf6e62f2S猫头猫 82d139abf1S猫头猫export default memo(ResultPanel); 83