import React, { useEffect } from 'react'; import { Text } from 'react-native'; import { scaleFontMetric, useFontScale, useThemedStyles } from '../../../theme'; import { createLogger } from '../../../utils/logger'; import { normalizeNonBlankText } from '../shared/accessibilityName'; import { ButtonBase } from './ButtonBase'; import { makeStyles } from './styles'; import type { ButtonProps } from './types'; const log = createLogger('Button'); /** * 8 variant × 3 size 文本按钮。 * 内部组合 ButtonBase + content(label + 可选 leftIcon / rightIcon), * ButtonBase 接管 chrome(sizing / palette / disabled / loading / a11y)。 * * `loading=true` 时 ButtonBase 把 children render prop 短路为 ActivityIndicator。 */ export function Button({ label, onPress, size, variant, block, disabled, loading, leftIcon: LeftIcon, rightIcon: RightIcon, style, testID, accessibilityHint, accessibilityState, }: ButtonProps): React.JSX.Element { const styles = useThemedStyles(makeStyles); const fontScale = useFontScale(); const accessibleName = normalizeNonBlankText(label); const hasBlankLabel = accessibleName === undefined; useEffect(() => { if (hasBlankLabel) { log.warn('Button label 不能为空白,当前 action 已禁用。'); } }, [hasBlankLabel]); return ( {({ sizing, palette }) => { const textSize = scaleFontMetric(sizing.fs, fontScale); return ( <> {LeftIcon ? ( ) : null} {label} {RightIcon ? ( ) : null} ); }} ); }