import React, { useMemo } from 'react'; import { StyleSheet, Text, View } from 'react-native'; import Svg, { Defs, LinearGradient as SvgLinearGradient, Rect, Stop, } from 'react-native-svg'; import { avatarGradient, useFontScale, useTheme } from '../../../theme'; import { useSvgId } from '../useSvgId'; import { makeAvatarStyles } from './styles'; import type { AvatarWithRingProps } from './types'; /** * 圆形头像 + 白色 ring + 品牌橙渐变底 + 品牌色 shadow。 * * 用 outer shell (bg=ringColor 圆) + inner avatarCore (圆形 overflow:hidden, * 内含 SVG 渐变 + label) 双层模拟 ring,避免 RN Fabric `borderColor + alpha * + borderRadius: 50%` 的 anti-aliasing 渲染缺失(详见 styles.ts)。 */ export function AvatarWithRing({ label, size = 64, ringColor, style, testID, }: AvatarWithRingProps): React.JSX.Element { const { colors: c, shadow } = useTheme(); const fontScale = useFontScale(); const id = useSvgId('av'); const { inner, styles } = useMemo( () => makeAvatarStyles( size, ringColor ?? c.avatarRing, shadow.brandAvatar, c, fontScale ), [size, ringColor, c, shadow.brandAvatar, fontScale] ); return ( {/* userSpaceOnUse + 像素坐标 + Rect 数值: 避免 BBox 0-1 模式在 RN-svg 小尺寸 + alpha 下渲染为单色。 */} {/* rx 全圆:渐变本体自带圆形,不依赖 avatarCore 的 overflow:hidden —— Fabric 上 overflow 对 SVG 子层的圆角裁切不生效,方形渐变会露角。 */} {label} ); }