import React, { useEffect, useRef } from 'react'; import { View } from 'react-native'; import { r, useColors, useMotionActive } from '../../../theme'; import { A11Y_HIDDEN_PROPS } from '../shared/a11y'; import { sanitizeSpinnerProps, SPINNER_CENTER_STYLE } from './shared'; import type { SpinnerProps } from './types'; // React-Native-Web 上 reanimated 4 + worklets 0.9.x 的 useAnimatedStyle 链路在 // web bundle 里跑会触发 `_updatePropsJS` 里 `Object.keys(updates)` 的 worklet // 回值打包 edge case(animation frame 每帧抛 TypeError),旋转停滞。 // 该 .web.tsx 用纯 CSS @keyframes 替代,native 端仍走 Spinner.tsx 的 reanimated 实现, // 走 webpack `resolve.extensions = ['.web.tsx', ...]`,bundle 命中 .web 版本。 const SPIN_KEYFRAMES_ID = 'unif-spinner-spin-keyframes'; // tsconfig 不带 DOM lib(库本体是 RN),用 globalThis 兜底访问浏览器 API, // 类型用 any 通过 strict 检查(实际运行只在 web bundle 命中本文件,document 一定有)。 const win: any = globalThis as any; function ensureKeyframes() { if (typeof win.document === 'undefined') return; if (win.document.getElementById(SPIN_KEYFRAMES_ID)) return; const style = win.document.createElement('style'); style.id = SPIN_KEYFRAMES_ID; // ⚠️ 安全:注入