已合并
fix: values from animated props aren't set correctly after finishing animation with native driver, leading to wrong values in measure. #1287
fix: values from animated props aren't set correctly after finishing animation with native driver, leading to wrong values in measure. #1287
已合并
Przemysław Sosna创建于 2025年7月14日
Przemysław Sosna
Przemysław Sosna
2025年7月14日

Description

When using the native driver for animations that involve layout changes (ie. translateY and other transforms, but not styles such as opacity), because it bypasses Fabric, the new coordinates are not updated so the values returned by measure are incorrect.

This was actually fixed on 0.77, so this PR is a cherrypick of "Trigger rerender on animation complete (#37836)" from the upstream RN repository and "fix: values for animated props are not set correctly after display changes to none" from the 0.77 branch. "fix: the infinite loop caused by the error "Animated node with tag xxx does not exist"." (d7083d23e9573c805196f813d5c1051c702e150c) is also cherrypicked, as without that native driver is bugged and after a coupld of animations doesn't work properly.

Changes

  • fix: values from animated props aren't set correctly after finishing animation with native driver, leading to wrong values in measure.

Test Plan

Check the code below, after pressing "Measure Box", the height logged should be 100.

import React, {useLayoutEffect, useRef} from 'react';
import {TouchableOpacity, View, Text, Animated} from 'react-native';

export default function App() {
  const scaleValue = useRef(new Animated.Value(0.2)).current;
  const boxRef = useRef<View>(null);

  React.useEffect(() => {
    Animated.spring(scaleValue, {
      toValue: 1,
      friction: 3,
      useNativeDriver: true,
    }).start();
  }, []);

  const measureBox = () => {
    boxRef.current?.measure((x, y, width, height, pageX, pageY) => {
      console.log({x, y, width, height, pageX, pageY});
    });
  };

  useLayoutEffect(() => {
    measureBox();
  }, []);

  return (
    <View
      style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        gap: 40,
      }}>
      <TouchableOpacity
        onPress={measureBox}
        style={{padding: 10, backgroundColor: '#eee'}}>
        <Text>Measure Box</Text>
      </TouchableOpacity>

      <Animated.View
        ref={boxRef}
        style={{
          width: 100,
          height: 100,
          backgroundColor: 'orange',
          borderRadius: 8,
          transform: [{scale: scaleValue}],
          justifyContent: 'center',
          alignItems: 'center',
        }}>
        <Text>Scaled Box</Text>
      </Animated.View>
    </View>
  );
}

Checklist

likedislike
Pull Request已成功合入, 合并人@huangyouhua
(感谢 Przemysław Sosna 的贡献)
Przemysław SosnaPrzemysław Sosna
2025年7月14日 关联了issue:fix: values from animated props aren't set correctly after finishing animation with native driver, leading to wrong values in measure.
openharmony_ci
openharmony_ci成员
2025年7月14日 评论:

感谢提交 Pull Requests!
Thanks for submitting a pull request.

likedislike
openharmony_ciopenharmony_ci成员
2025年7月14日 添加了label:dco检查成功
Przemysław SosnaPrzemysław Sosna
2025年7月14日 修改了pull request 的描述
Przemysław Sosna
Przemysław Sosna
2025年7月14日 评论:

start build

likedislike
此处折叠了120条消息 查看更多
Przemysław Sosna
Przemysław Sosna
2025年11月19日 评论:
likedislike
gyange成员
2025年11月25日 评论:

ok

likedislike
huangyouhuahuangyouhua
2025年11月26日 通过审查
huangyouhuahuangyouhua
2025年11月26日 关闭了关联的issue
huangyouhuahuangyouhua
2025年11月26日 合入了pull request