import { ChevronRightOutlined } from '@unif/react-native-icons'; import React, { useEffect } from 'react'; import { type StyleProp, Text, type TextStyle, View, StyleSheet, } from 'react-native'; import { Pressable } from 'react-native-gesture-handler'; import { pressedOpacity, r, radius, useColors, useThemedStyles, } from '../../../theme'; import { GlassLayer } from '../GlassLayer'; import { createLogger } from '../../../utils/logger'; import { A11Y_HIDDEN_PROPS, A11Y_TEXT_ONLY_STYLE } from '../shared/a11y'; import { resolveCellActionAccessibilityLabel, resolveCellTitleColor, resolveExtraSemanticText, stringifyCellText, } from './content'; import { useListVariant } from './context'; import { Leading } from './Leading'; import { makeStyles } from './styles'; import type { CellExtra, CellProps } from './types'; const log = createLogger('Cell'); function CellExtraContent({ extra, textStyle, }: { extra: CellExtra | undefined; textStyle: StyleProp; }): React.JSX.Element | null { if (!extra) return null; switch (extra.kind) { case 'text': return ( {stringifyCellText(extra.value)} ); case 'display': { const semantic = resolveExtraSemanticText(extra); return ( <> {extra.node} {/* 视觉节点已从 a11y 树移除;accessibilityText 在这里落成一个真实的 文本节点,读屏才读得到、测试才按文字查得到。只声明不渲染的话, 它对两者都不存在。 */} {semantic !== undefined ? ( {semantic} ) : null} ); } case 'control': return extra.node; } } /** * 设置 / 列表行。布局:`leading? · (title / desc) · extra? · arrow?` * * 两种风格(由父 `` 通过 ListVariantContext 决定): * - `grouped`(默认):独立玻璃卡片 + 8px 间距 * - `flush`(嵌在 Card 内):紧凑列表,28×28 橙色 icon 盒子,行间 inset hairline 分隔 */ export function Cell(props: CellProps): React.JSX.Element { const c = useColors(); const styles = useThemedStyles(makeStyles); const variant = useListVariant(); const flush = variant === 'flush'; const requestedAction = typeof props.onPress === 'function'; const accessibilityLabel = requestedAction ? resolveCellActionAccessibilityLabel({ accessibilityLabel: props.accessibilityLabel, title: props.title, desc: props.desc, extra: props.extra, }) : undefined; const hasEffectiveAction = requestedAction && accessibilityLabel !== undefined; const hasMissingActionName = requestedAction && !hasEffectiveAction; useEffect(() => { if (hasMissingActionName) { log.warn('Cell action 缺少非空业务名称,已按 display-only 渲染。'); } }, [hasMissingActionName]); const cellStyle = [ styles.cell, flush && styles.cellFlush, flush && props.desc !== undefined && styles.cellFlushWithDesc, props.style, ]; const titleColor = resolveCellTitleColor({ danger: props.danger, selected: props.selected, dangerColor: c.error, selectedColor: c.primary, }); const titleStyle = [ flush ? styles.titleFlush : styles.title, titleColor && { color: titleColor }, ]; const descStyle = flush ? styles.descFlush : styles.desc; const extraStyle = flush ? styles.extraFlush : styles.extra; const inner = (opacity = 1) => ( {!flush ? ( ) : null} {props.leading !== undefined ? ( ) : null} {stringifyCellText(props.title)} {props.desc !== undefined ? ( {stringifyCellText(props.desc)} ) : null} {hasEffectiveAction && props.arrow && !props.danger ? ( ) : null} ); if (hasEffectiveAction) { const isDisabled = props.disabled === true; return ( {({ pressed }) => inner(isDisabled ? 0.5 : pressed ? pressedOpacity : 1) } ); } // 不可点但显式给了整行名称(Static 分支):合成单个 a11y 节点按指定文案播报。 // 没给就保持裸渲染 —— 读屏按 title / desc / extra 各自的文本节点逐个读。 const staticLabel = props.accessibilityLabel; if (staticLabel !== undefined && staticLabel.trim().length > 0) { return ( {inner()} ); } return inner(); }