1*bf6e62f2S猫头猫/** 2*bf6e62f2S猫头猫 * 搜索结果面板 一级页 3*bf6e62f2S猫头猫 */ 4*bf6e62f2S猫头猫import React, {useState} from 'react'; 5*bf6e62f2S猫头猫import {StyleSheet, Text, View} from 'react-native'; 6*bf6e62f2S猫头猫import rpx from '@/utils/rpx'; 7*bf6e62f2S猫头猫import {SceneMap, TabBar, TabView} from 'react-native-tab-view'; 8*bf6e62f2S猫头猫import ResultSubPanel from './resultSubPanel'; 9*bf6e62f2S猫头猫import results from './results'; 10*bf6e62f2S猫头猫import { fontWeightConst } from '@/constants/uiConst'; 11*bf6e62f2S猫头猫import { useTheme } from 'react-native-paper'; 12*bf6e62f2S猫头猫import Color from 'color'; 13*bf6e62f2S猫头猫 14*bf6e62f2S猫头猫interface IResultPanelProps {} 15*bf6e62f2S猫头猫 16*bf6e62f2S猫头猫const routes = results; 17*bf6e62f2S猫头猫 18*bf6e62f2S猫头猫const getRouterScene = (routes: Array<{key: ICommon.SupportMediaType; title: string}>) => { 19*bf6e62f2S猫头猫 const scene: Record<string, () => JSX.Element> = {}; 20*bf6e62f2S猫头猫 routes.forEach(r => { 21*bf6e62f2S猫头猫 scene[r.key] = () => <ResultSubPanel tab={r.key}></ResultSubPanel>; 22*bf6e62f2S猫头猫 }); 23*bf6e62f2S猫头猫 return SceneMap(scene); 24*bf6e62f2S猫头猫}; 25*bf6e62f2S猫头猫 26*bf6e62f2S猫头猫const renderScene = getRouterScene(routes); 27*bf6e62f2S猫头猫 28*bf6e62f2S猫头猫export default function ResultPanel(props: IResultPanelProps) { 29*bf6e62f2S猫头猫 const [index, setIndex] = useState(0); 30*bf6e62f2S猫头猫 const {colors} = useTheme(); 31*bf6e62f2S猫头猫 32*bf6e62f2S猫头猫 return ( 33*bf6e62f2S猫头猫 <TabView 34*bf6e62f2S猫头猫 navigationState={{ 35*bf6e62f2S猫头猫 index, 36*bf6e62f2S猫头猫 routes, 37*bf6e62f2S猫头猫 }} 38*bf6e62f2S猫头猫 renderTabBar={props => ( 39*bf6e62f2S猫头猫 <TabBar 40*bf6e62f2S猫头猫 {...props} 41*bf6e62f2S猫头猫 style={{ 42*bf6e62f2S猫头猫 backgroundColor: Color(colors.primary).alpha(0.7).toString(), 43*bf6e62f2S猫头猫 shadowColor: 'transparent', 44*bf6e62f2S猫头猫 borderColor: 'transparent', 45*bf6e62f2S猫头猫 }} 46*bf6e62f2S猫头猫 tabStyle={{ 47*bf6e62f2S猫头猫 width: rpx(128), 48*bf6e62f2S猫头猫 }} 49*bf6e62f2S猫头猫 renderLabel={({route, focused, color}) => ( 50*bf6e62f2S猫头猫 <Text 51*bf6e62f2S猫头猫 style={{ 52*bf6e62f2S猫头猫 fontWeight: focused ? fontWeightConst.bolder : fontWeightConst.bold, 53*bf6e62f2S猫头猫 color, 54*bf6e62f2S猫头猫 }}> 55*bf6e62f2S猫头猫 {route.title} 56*bf6e62f2S猫头猫 </Text> 57*bf6e62f2S猫头猫 )} 58*bf6e62f2S猫头猫 indicatorStyle={{ 59*bf6e62f2S猫头猫 backgroundColor: colors.text, 60*bf6e62f2S猫头猫 height: rpx(4), 61*bf6e62f2S猫头猫 }}></TabBar> 62*bf6e62f2S猫头猫 )} 63*bf6e62f2S猫头猫 style={{ 64*bf6e62f2S猫头猫 backgroundColor: colors.background, 65*bf6e62f2S猫头猫 }} 66*bf6e62f2S猫头猫 renderScene={renderScene} 67*bf6e62f2S猫头猫 onIndexChange={setIndex} 68*bf6e62f2S猫头猫 initialLayout={{width: rpx(750)}}></TabView> 69*bf6e62f2S猫头猫 ); 70*bf6e62f2S猫头猫} 71*bf6e62f2S猫头猫 72*bf6e62f2S猫头猫const style = StyleSheet.create({ 73*bf6e62f2S猫头猫 wrapper: { 74*bf6e62f2S猫头猫 width: rpx(750), 75*bf6e62f2S猫头猫 }, 76*bf6e62f2S猫头猫}); 77