import React from 'react'; import { View } from 'react-native'; import { useThemedStyles } from '../../../theme'; import { ListVariantContext } from './context'; import { makeStyles } from './styles'; import type { ListProps } from './types'; /** * Cell 的分组容器。 * * - 默认 `grouped` = 透明容器内排列玻璃卡片,间距 8px * - `flush=true` = 嵌在外层 Card 内,紧凑列表;`divider="full"` 铺满全宽 hairline / `"none"` 无分隔线 */ export function List({ children, flush, divider = 'full', style, testID, }: ListProps): React.JSX.Element { const styles = useThemedStyles(makeStyles); if (flush) { const items = React.Children.toArray(children).filter(Boolean); return ( {items.map((child, i) => { // 优先使用 caller 传入的 key(React.Children.toArray 已将 key 注入 child), // 回退到索引确保 reconciler 稳定 —— 避免 caller key 丢失导致不必要重挂载。 const key = React.isValidElement(child) && child.key != null ? child.key : i; return ( {i > 0 && divider === 'full' ? ( ) : null} {child} ); })} ); } return ( {children} ); }