Skip to content

Commit

Permalink
do not synchronise native animated in paper
Browse files Browse the repository at this point in the history
Summary:
## Changelog:
[General][Fixed] - Fix broken native animation in Paper

In Native Animated Paper, `scheduleUpdate` must not be called. In Fabric, the synchronisation between Fiber and Shadow trees is a must but in Paper it sets undesired state.

Reviewed By: javache

Differential Revision: D54799237

fbshipit-source-id: f6b07dc377111ed2f8253ea0c7c7e312168166e8
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Mar 12, 2024
1 parent 00d8f49 commit 92540a6
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions packages/react-native/Libraries/Animated/useAnimatedProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,45 @@ export default function useAnimatedProps<TProps: {...}, TInstance>(
// every animation frame. When using the native driver, this callback is
// called when the animation completes.
onUpdateRef.current = () => {
if (node.__isNative || process.env.NODE_ENV === 'test') {
// Check 1: either tests are running or this is a native driven animation.
// In native driven animations, this callback is only called once the animation completes.
// Call `scheduleUpdate` to synchronise Fiber and Shadow tree.
if (process.env.NODE_ENV === 'test') {
// Check 1: this is a test.
// call `scheduleUpdate` to bypass use of setNativeProps.
return scheduleUpdate();
}

const isFabricNode = isFabricInstance(instance);
if (node.__isNative) {
// Check 2: this is an animation driven by native.
// In native driven animations, this callback is only called once the animation completes.
if (isFabricNode) {
// Call `scheduleUpdate` to synchronise Fiber and Shadow tree.
// Must not be called in Paper.
scheduleUpdate();
}
return;
}

if (
typeof instance !== 'object' ||
typeof instance?.setNativeProps !== 'function'
) {
// Check 2: the instance does not support setNativeProps. Call `scheduleUpdate`.
// Check 3: the instance does not support setNativeProps. Call `scheduleUpdate`.
return scheduleUpdate();
}

if (!isFabricInstance(instance)) {
// Check 3: this is a paper instance, call setNativeProps.
if (!isFabricNode) {
// Check 4: this is a paper instance, call setNativeProps.
// $FlowIgnore[not-a-function] - Assume it's still a function.
// $FlowFixMe[incompatible-use]
return instance.setNativeProps(node.__getAnimatedValue());
}

if (!useNativePropsInFabric) {
// Check 4: setNativeProps are disabled.
// Check 5: setNativeProps are disabled.
return scheduleUpdate();
}

// This is a Fabric instance and setNativeProps are supported.
// This is a Fabric instance and setNativeProps is supported.

// $FlowIgnore[not-a-function] - Assume it's still a function.
// $FlowFixMe[incompatible-use]
Expand Down

0 comments on commit 92540a6

Please sign in to comment.