import { StyleProp, ViewStyle, TextStyle } from 'react-native'; import { ReactNode } from 'react'; /** Tab 项配置 */ export interface TabViewItem { /** 唯一标识 */ key: string; /** Tab 标题 */ title?: string; /** Tab 角标数量 */ badge?: number; /** Tab 图标 */ icon?: string; /** Tab 额外数据(用于自定义渲染) */ extra?: Record; /** 是否禁用 */ disabled?: boolean; } /** 缓存的面板数据 */ export interface CachedPanelData { /** 数据列表 */ data: T[]; /** 是否还有更多 */ hasMore: boolean; /** 加载状态 */ loadingState: 'idle' | 'loading' | 'refreshing' | 'loadingMore'; /** 滚动位置 */ scrollOffset?: number; /** 页码 */ page?: number; /** 最后更新时间 */ lastUpdated?: number; /** 是否已初始化加载 */ initialized: boolean; } /** 面板渲染器参数 */ export interface PanelRenderProps { /** 当前 Tab 项 */ item: TabViewItem; /** Tab 索引 */ index: number; /** 是否当前激活 */ isActive: boolean; /** 缓存的数据 */ cachedData: CachedPanelData; /** 更新缓存数据 */ updateCache: (data: Partial>) => void; /** 刷新数据 */ refresh: () => void; /** 加载更多 */ loadMore: () => void; } /** 加载数据的参数 */ export interface LoadDataParams { /** Tab key */ key: string; /** 页码 */ page: number; /** 每页数量 */ pageSize: number; /** 是否刷新 */ isRefresh: boolean; } /** 加载数据的返回值 */ export interface LoadDataResult { /** 数据列表 */ data: T[]; /** 是否还有更多 */ hasMore: boolean; /** 总数量(可选) */ total?: number; } /** DbTabView 组件属性 */ export interface DbTabViewProps { /** Tab 项列表 */ tabs: TabViewItem[]; /** 当前激活的 Tab key */ activeKey?: string; /** 默认激活的 Tab key */ defaultActiveKey?: string; /** Tab 切换回调 */ onChange?: (key: string, index: number) => void; /** Tab 栏位置 */ tabPosition?: 'top' | 'bottom'; /** Tab 栏是否可滚动 */ tabScrollable?: boolean; /** Tab 栏是否显示下划线指示器 */ showIndicator?: boolean; /** 指示器颜色 */ indicatorColor?: string; /** 指示器宽度 */ indicatorWidth?: number; /** 激活时 Tab 滚动到左侧 */ scrollToLeft?: boolean; /** 自定义 Tab 渲染 */ renderTab?: (item: TabViewItem, isActive: boolean, index: number) => ReactNode; /** 是否启用滑动切换 */ swipeable?: boolean; /** 滑动阈值(0-1,滑动距离占屏幕宽度的比例) */ swipeThreshold?: number; /** 滑动速度阈值 */ swipeVelocityThreshold?: number; /** 是否启用惰性加载(只渲染当前和相邻面板) */ lazy?: boolean; /** 预加载相邻面板数量 */ preloadOffset?: number; /** 是否启用缓存 */ cacheEnabled?: boolean; /** 缓存过期时间(毫秒),0 表示不过期 */ cacheExpiry?: number; /** 最大缓存面板数量 */ maxCachedPanels?: number; /** 初始缓存数据 */ initialCache?: Record>; /** 加载数据函数 */ loadData?: (params: LoadDataParams) => Promise>; /** 每页数量 */ pageSize?: number; /** 是否自动加载首屏数据 */ autoLoad?: boolean; /** 渲染面板内容 */ renderPanel?: (props: PanelRenderProps) => ReactNode; /** 渲染列表项(当使用内置列表时) */ renderItem?: (item: T, index: number, tabKey: string) => ReactNode; /** 列表项 key 提取器 */ keyExtractor?: (item: T, index: number) => string; /** 是否使用内置无限列表 */ useBuiltInList?: boolean; /** 列表是否可下拉刷新 */ refreshable?: boolean; /** 列表是否显示分隔线 */ showSeparator?: boolean; /** 空状态渲染 */ renderEmpty?: (tabKey: string) => ReactNode; /** 加载中渲染 */ renderLoading?: () => ReactNode; /** 错误状态渲染 */ renderError?: (error: string, retry: () => void) => ReactNode; /** 容器样式 */ style?: StyleProp; /** Tab 栏容器样式 */ tabBarStyle?: StyleProp; /** Tab 项样式 */ tabStyle?: StyleProp; /** Tab 文字样式 */ tabTextStyle?: StyleProp; /** 激活的 Tab 文字样式 */ activeTabTextStyle?: StyleProp; /** 面板容器样式 */ panelContainerStyle?: StyleProp; /** 面板样式 */ panelStyle?: StyleProp; } /** DbTabView 引用方法 */ export interface DbTabViewRef { /** 切换到指定 Tab */ switchTo: (key: string) => void; /** 切换到指定索引 */ switchToIndex: (index: number) => void; /** 刷新当前 Tab 数据 */ refreshCurrent: () => void; /** 刷新指定 Tab 数据 */ refresh: (key: string) => void; /** 刷新所有 Tab 数据 */ refreshAll: () => void; /** 获取缓存数据 */ getCache: (key: string) => CachedPanelData | undefined; /** 清除缓存 */ clearCache: (key?: string) => void; /** 获取当前激活的 Tab key */ getActiveKey: () => string; }