// Themed shadow tokens —— 全仓 shadow 走这一份,callers 不再 inline 写 // shadowColor/Offset/Opacity/Radius/elevation 5 件套。 // // 暗色下中性阴影 shadowOpacity / elevation 全部置 0:视觉层次靠 surface 5 层 // 明度差表达(layered surface 替代 shadow)。 import { Platform, type ViewStyle } from 'react-native'; import { BRAND_ORANGE } from './colors'; // 模块级别名保持历史可读性,同时指向 colors.ts 单一来源。 const BRAND = BRAND_ORANGE; // iOS 透明卡片按自身圆角投影,不再依赖子树像素计算;参数保持单一来源。 const LIGHT_CARD_SHADOW = { shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.08, shadowRadius: 4, elevation: 2, } as const; const IOS_LIGHT_CARD_SHADOW = { ...LIGHT_CARD_SHADOW, shadowOpacity: 0, boxShadow: [ { offsetX: LIGHT_CARD_SHADOW.shadowOffset.width, offsetY: LIGHT_CARD_SHADOW.shadowOffset.height, // RN 将 boxShadow.blurRadius 除以 2 后交给 CALayer。 blurRadius: LIGHT_CARD_SHADOW.shadowRadius * 2, color: `rgba(0, 0, 0, ${LIGHT_CARD_SHADOW.shadowOpacity})`, }, ], } satisfies ViewStyle; const NONE_SHADOW = { shadowColor: 'transparent', shadowOffset: { width: 0, height: 0 }, shadowOpacity: 0, shadowRadius: 0, elevation: 0, } as const; const IOS_NONE_SHADOW = { ...NONE_SHADOW, boxShadow: [] } satisfies ViewStyle; export const lightShadow = { /** 轻提示浮起 —— Segmented active 段 */ subtle: { shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.06, shadowRadius: 2, elevation: 1, }, /** 标准卡片下沉 —— Card 默认 variant */ get card() { return Platform.OS === 'ios' ? IOS_LIGHT_CARD_SHADOW : LIGHT_CARD_SHADOW; }, /** 中性浮岛 —— TabBar 玻璃胶囊等贴底浮起,大半径柔散。 */ floating: { shadowColor: '#000', shadowOffset: { width: 0, height: 16 }, shadowOpacity: 0.1, shadowRadius: 40, elevation: 12, }, /** 品牌光晕 - sm —— 品牌橙浮起轻量档。 */ brandSm: { shadowColor: BRAND, shadowOffset: { width: 0, height: 6 }, shadowOpacity: 0.08, shadowRadius: 18, elevation: 3, }, /** GlassStats 数据条专用 shadow。 * 顶部 `1px inset` 高光由 GlassStats topHighlight View 节点画,不进 shadow。 */ glassBar: { shadowColor: BRAND, shadowOffset: { width: 0, height: 6 }, shadowOpacity: 0.08, shadowRadius: 18, elevation: 3, }, /** 品牌光晕 - md —— 主按钮 / Avatar ring 中等强调 */ brandMd: { shadowColor: BRAND, shadowOffset: { width: 0, height: 12 }, shadowOpacity: 0.26, shadowRadius: 24, elevation: 12, }, /** 品牌光晕 - lg —— Login Logo halo。 */ brandLg: { shadowColor: BRAND, shadowOffset: { width: 0, height: 16 }, shadowOpacity: 0.22, shadowRadius: 36, elevation: 12, }, /** 品牌光晕 - xl —— Splash Logo 启动屏最重浮起。 */ brandXl: { shadowColor: BRAND, shadowOffset: { width: 0, height: 20 }, shadowOpacity: 0.2, shadowRadius: 50, elevation: 12, }, /** About icon halo —— 在 brandLg(Login Logo)和 brandXl(Splash)之间。 */ brandAbout: { shadowColor: BRAND, shadowOffset: { width: 0, height: 18 }, shadowOpacity: 0.28, shadowRadius: 40, elevation: 12, }, /** AssistantCard 42×42 icon tile shadow —— 比 brandSm 重一档,给 hero 区品牌入口加视觉权重。 */ brandAssistant: { shadowColor: BRAND, shadowOffset: { width: 0, height: 8 }, shadowOpacity: 0.3, shadowRadius: 18, elevation: 12, }, /** Avatar 品牌橙光晕。 * 数值不用 r() 缩放(shadow 不跟屏宽等比)。 */ brandAvatar: { shadowColor: BRAND, shadowOffset: { width: 0, height: 10 }, shadowOpacity: 0.28, shadowRadius: 24, elevation: 12, }, get none() { return Platform.OS === 'ios' ? IOS_NONE_SHADOW : NONE_SHADOW; }, } as const; // readonly 加到嵌套字段:顶层 key 经同态映射已只读,但嵌套 shadowOffset 字段 // 在运行时仍可合法赋值(t.card.shadowOffset.height = 5 会静默串改全部共享引用)。 // 此处显式声明 readonly 让 tsc 在编译期捕获误改。 export type ShadowTokens = { readonly [K in keyof typeof lightShadow]: { readonly shadowColor: string; readonly shadowOffset: { readonly width: number; readonly height: number }; readonly shadowOpacity: number; readonly shadowRadius: number; readonly elevation: number; readonly boxShadow?: ViewStyle['boxShadow']; }; }; // darkZero 辅助函数:每次调用返回独立 offset 对象,消除多 token 共享同一 shadowOffset // 引用的隐患——虽然 ShadowTokens readonly 已在类型层阻止赋值,防御深度更好。 const darkZero = (shadowColor: string) => ({ shadowColor, shadowOffset: { width: 0, height: 0 }, shadowOpacity: 0, shadowRadius: 0, elevation: 0, }) as const; export const darkShadow: ShadowTokens = { subtle: darkZero('#000'), card: darkZero('#000'), /** floating 暗色不置零:浮动胶囊在暗 bg 上需要黑色 drop shadow, * 否则跟暗背景贴平,视觉无层级。 */ floating: { shadowColor: '#000', shadowOffset: { width: 0, height: 28 }, shadowOpacity: 0.85, shadowRadius: 60, elevation: 16, }, brandSm: darkZero(BRAND), brandMd: darkZero(BRAND), brandLg: darkZero(BRAND), brandXl: darkZero(BRAND), brandAbout: darkZero(BRAND), brandAssistant: darkZero(BRAND), /** brandAvatar 暗色不置零:暗色 ring 0.10 几乎隐去,靠橙光晕(0.40 比亮色 0.28 更强) * 托起头像。 */ brandAvatar: { shadowColor: BRAND, shadowOffset: { width: 0, height: 10 }, shadowOpacity: 0.4, shadowRadius: 24, elevation: 12, }, /** glassBar 暗色不置零:黑色浮起让数据条在暗 hero 上凸起,缺它整个条贴在背景上 * 像没渲染。 */ glassBar: { shadowColor: '#000', shadowOffset: { width: 0, height: 6 }, shadowOpacity: 0.35, shadowRadius: 18, elevation: 6, }, get none() { return Platform.OS === 'ios' ? IOS_NONE_SHADOW : NONE_SHADOW; }, };