Reanimated 4.4.x animated components conflict with Restyle theme

未关闭
#355 5 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

@KAMRONBEK 已经在做这个了。

开始于 2026年7月16日。

  • #356 来自 @KAMRONBEK —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
react-native, typescript
领域
frontend, mobile

调研方向

Start at the getThemeValue logic shown in the issue and reproduce the crash with the createRestyleComponent/Animated.createAnimatedComponent example on React Native 0.86.0, Reanimated 4.4.1, and Restyle 2.4.5. Done means animated numeric theme-key values pass through as literal styles while unknown string keys retain typo detection; no file or test path is named in the report.

由索引模型根据 Issue 内容生成。

描述

bug

While upgrading our app to RN 0.86.0 and bumping Reanimated from 4.2.2 to 4.4.1 some animated components started crashing the app. Specifically components animating props belonging to Shopify Restyle's theming, like borderRadius or zIndex. It seems the culprit its also a source of Reanimated performance improvements, which is one of the reasons we want to upgrade, so it would not be ideal to turn it off. Upon quite a bit of debugging with Claude this is the information I gathered:

When a theme-key prop (borderRadius, zIndex, spacing props, etc.) receives a value that is not a key in the corresponding theme scale, getThemeValue throws a hard error — even when the value is a valid literal style value such as a raw pixel number. This makes restyle stricter than peer theme-prop libraries (styled-system, dripsy), which pass unknown values through, and it turns benign upstream behavior into render crashes.

Current behavior

  if (isThemeKey(theme, themeKey)) {
    if (value && theme[themeKey][value] === undefined)
      throw new Error(`Value '${value}' does not exist in theme['${String(themeKey)}']`);
    return value ? theme[themeKey][value] : value;
  }

Any truthy value that is not a theme key throws, regardless of whether it is a number (a legitimate literal) or a string (likely a typo).

react-native-reanimated 4.4.x ships a default-on feature flag FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS, which - when an animation settles - spreads the
resolved animated style values onto the wrapped component as top-level props (in addition to style). When that wrapped component is a restyle createBox()/AnimatedBox, the settled numeric values arrive as theme-key props:

Value '13' does not exist in theme['borderRadii'] // animated borderRadius
Value '1' does not exist in theme['zIndices'] // animated zIndex

Expected behavior

A numeric value passed to a theme-key prop should be treated as a literal style value and passed through (this is how styled-system and dripsy behave), rather than throwing. Strings that are not theme keys are the genuine typo case and could still throw or warn. In short:

  • borderRadius="m" and not a key -> likely a typo, throw/warn (current behavior, fine).
  • borderRadius={13} -> a literal value, pass it through.

A passthrough-for-numbers default, or at minimum a configurable option, would restore compatibility without losing typo detection.

Also just leaving my thanks to the Shopify Restyle team, as I think this is the first problem we have encountered in 4 years of using the library.

To Reproduce

 const ButtonContainer = createRestyleComponent<
   VariantProps<Theme, 'buttonVariants'> & React.ComponentProps<typeof Box>,
   Theme
 >(restyleFunctions, Box);

 const AnimatedButtonContainer = Animated.createAnimatedComponent(ButtonContainer);

  const { borderRadii } = useTheme<Theme>();

  const animatedContainerStyle = useAnimatedStyle(() => {
    if (!containerWidth.value || !circularLoading) {
      return {};
    }

    const borderRadius = interpolate(loadingProgress.value, [0, 1], [borderRadii.base, borderRadii.xxl]);

    return {
      height: circleSize,
      borderRadius,
    };
  });
<AnimatedButtonContainer
  style={animatedContainerStyle}
  }>
  {renderContentBox()}
</AnimatedButtonContainer>;

Platform:

  • iOS
  • Android

Environment

2.4.5

主要语言
TypeScript
星标
3.4k
派生
154
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Shopify/restyle 的其他 Issue

查看 Shopify/restyle 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。