diff --git a/packages/react-native/Libraries/Animated/__tests__/AnimatedBackend-itest.js b/packages/react-native/Libraries/Animated/__tests__/AnimatedBackend-itest.js index a20d9cdb0a90..94f72bf64862 100644 --- a/packages/react-native/Libraries/Animated/__tests__/AnimatedBackend-itest.js +++ b/packages/react-native/Libraries/Animated/__tests__/AnimatedBackend-itest.js @@ -1012,3 +1012,384 @@ test('native scroll event does not step a running timing animation', () => { mockClock.uninstall(); } }); + +describe('static value set after a native-driver animation', () => { + function runFadeThenStatic(staticOpacity: number | void) { + let _fade; + let _animation; + let _setFading; + + function MyApp() { + const fade = useAnimatedValue(1); + const [fading, setFading] = useState(false); + _fade = fade; + _setFading = setFading; + return ( + + ); + } + + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render(); + }); + + Fantom.runTask(() => { + _setFading(true); + }); + + Fantom.runTask(() => { + _animation = Animated.timing(_fade, { + toValue: 0.2, + duration: 100, + useNativeDriver: true, + }).start(); + }); + + Fantom.unstable_produceFramesForDuration(100); + + // Same as switching to a static style in the start() callback. + Fantom.runTask(() => { + _animation?.stop(); + _setFading(false); + }); + + // Flush the work queued by stopping the animation. + Fantom.runWorkLoop(); + + return root; + } + + test('a new static value replaces the animated value', () => { + const root = runFadeThenStatic(0.6); + + expect(root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + , + ); + }); + + test('going back to the pre-animation value replaces the animated value', () => { + const root = runFadeThenStatic(1); + + expect(root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + , + ); + }); + + test('removing the animated prop resets it to the default', () => { + const root = runFadeThenStatic(undefined); + + expect(root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + , + ); + }); +}); + +describe('switching from a native-driver animation to static styles', () => { + // $FlowFixMe[unclear-type] Any style a test switches between. + type Style = any; + type StyleFor = (value: Animated.Value, animating: boolean) => Style; + + // The expected output: the same style without an animation. + function renderStatic(style: Style, props: Array) { + const root = Fantom.createRoot(); + Fantom.runTask(() => { + root.render( + , + ); + }); + return JSON.stringify(root.getRenderedOutput({props}).toJSON()); + } + + function setUp(styleFor: StyleFor, viewCount: number = 1) { + let _value; + let _setAnimating; + const _setAnimatingByView: Array<(animating: boolean) => void> = []; + + function Box({index}: {index: number}) { + const [animating, setAnimating] = useState(false); + _setAnimatingByView[index] = setAnimating; + return ( + + ); + } + + function MyApp() { + _value = useAnimatedValue(0); + const [, rerender] = useState(0); + _setAnimating = rerender; + return ( + <> + {Array.from({length: viewCount}, (_, index) => ( + + ))} + + ); + } + + const root = Fantom.createRoot(); + Fantom.runTask(() => { + root.render(); + }); + + return { + root, + value: () => nullthrows(_value), + setAnimating: (animating: boolean, index: number = 0) => + _setAnimatingByView[index](animating), + rerender: () => nullthrows(_setAnimating)(n => n + 1), + }; + } + + function animate( + value: Animated.Value, + toValue: number, + duration: number, + runFor: number = duration, + ) { + let animation; + Fantom.runTask(() => { + animation = Animated.timing(value, { + toValue, + duration, + easing: Easing.linear, + useNativeDriver: true, + }); + animation.start(); + }); + Fantom.unstable_produceFramesForDuration(runFor); + // The last frame shows up after the queued work runs. + Fantom.runWorkLoop(); + return nullthrows(animation); + } + + function fadeThenSwitch( + styleFor: StyleFor, + {runFor = 100}: {runFor?: number} = {}, + ) { + const app = setUp(styleFor); + Fantom.runTask(() => app.setAnimating(true)); + const animation = animate(app.value(), 1, 100, runFor); + Fantom.runTask(() => { + animation.stop(); + app.setAnimating(false); + }); + Fantom.runWorkLoop(); + return app; + } + + const cases: Array<[string, StyleFor, Style, Array]> = [ + [ + 'transform to a static transform', + (v, a) => ({ + transform: [ + { + translateX: a + ? v.interpolate({inputRange: [0, 1], outputRange: [0, 50]}) + : 10, + }, + ], + }), + {transform: [{translateX: 10}]}, + ['transform'], + ], + [ + 'transform removed', + (v, a) => + a + ? { + transform: [ + { + translateX: v.interpolate({ + inputRange: [0, 1], + outputRange: [0, 50], + }), + }, + ], + } + : {}, + {}, + ['transform'], + ], + [ + 'interpolated color to a static color', + (v, a) => ({ + backgroundColor: a + ? v.interpolate({inputRange: [0, 1], outputRange: ['red', 'blue']}) + : 'green', + }), + {backgroundColor: 'green'}, + ['backgroundColor'], + ], + [ + 'interpolated color removed', + (v, a) => + a + ? { + backgroundColor: v.interpolate({ + inputRange: [0, 1], + outputRange: ['red', 'blue'], + }), + } + : {}, + {}, + ['backgroundColor'], + ], + [ + 'layout prop to a static value', + (v, a) => ({ + marginLeft: a + ? v.interpolate({inputRange: [0, 1], outputRange: [0, 50]}) + : 5, + }), + {marginLeft: 5}, + ['marginLeft'], + ], + [ + 'border width to a static value', + (v, a) => ({ + borderWidth: a + ? v.interpolate({inputRange: [0, 1], outputRange: [0, 20]}) + : 4, + }), + {borderWidth: 4}, + ['borderWidth'], + ], + [ + 'layout prop removed', + (v, a) => + a + ? {rowGap: v.interpolate({inputRange: [0, 1], outputRange: [0, 20]})} + : {}, + {}, + ['rowGap'], + ], + [ + 'interpolated opacity to a static value', + (v, a) => ({ + opacity: a + ? v.interpolate({inputRange: [0, 1], outputRange: [1, 0.2]}) + : 0.6, + }), + {opacity: 0.6}, + ['opacity'], + ], + ]; + + for (const [name, styleFor, staticStyle, props] of cases) { + test(name, () => { + const {root} = fadeThenSwitch(styleFor); + expect(JSON.stringify(root.getRenderedOutput({props}).toJSON())).toEqual( + renderStatic(staticStyle, props), + ); + }); + } + + test('switching halfway through the animation', () => { + const {root} = fadeThenSwitch((v, a) => ({opacity: a ? v : 0.6}), { + runFor: 50, + }); + expect(root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + , + ); + }); + + test('a prop that stays animated keeps animating', () => { + const app = fadeThenSwitch((v, a) => ({ + opacity: a ? v : 0.6, + transform: [ + { + translateX: v.interpolate({ + inputRange: [0, 2], + outputRange: [0, 100], + }), + }, + ], + })); + animate(app.value(), 2, 100); + expect( + app.root.getRenderedOutput({props: ['opacity', 'transform']}).toJSON(), + ).toEqual( + JSON.parse( + renderStatic({opacity: 0.6, transform: [{translateX: 100}]}, [ + 'opacity', + 'transform', + ]), + ), + ); + }); + + test('another view driven by the same value keeps animating', () => { + const app = setUp((v, a) => ({opacity: a ? v : 0.6}), 2); + Fantom.runTask(() => { + app.setAnimating(true, 0); + app.setAnimating(true, 1); + }); + const animation = animate(app.value(), 0.2, 100); + Fantom.runTask(() => { + animation.stop(); + app.setAnimating(false, 0); + }); + Fantom.runWorkLoop(); + expect( + JSON.stringify(app.root.getRenderedOutput({props: ['opacity']}).toJSON()), + ).toEqual( + '[{"type":"View","props":{"opacity":"0.6"},"children":[]},{"type":"View","props":{"opacity":"0.2"},"children":[]}]', + ); + + animate(app.value(), 0.8, 100); + expect( + JSON.stringify(app.root.getRenderedOutput({props: ['opacity']}).toJSON()), + ).toEqual( + '[{"type":"View","props":{"opacity":"0.6"},"children":[]},{"type":"View","props":{"opacity":"0.8"},"children":[]}]', + ); + }); + + test('re-rendering while animating keeps the animated value', () => { + const app = setUp((v, a) => ({opacity: a ? v : 0.6})); + Fantom.runTask(() => app.setAnimating(true)); + animate(app.value(), 0.2, 100, 50); + Fantom.runTask(() => app.rerender()); + Fantom.unstable_produceFramesForDuration(50); + Fantom.runWorkLoop(); + expect(app.root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + , + ); + }); + + test('animating and switching back twice', () => { + const app = fadeThenSwitch((v, a) => ({opacity: a ? v : 0.6})); + Fantom.runTask(() => { + app.value().setValue(0); + app.setAnimating(true); + }); + const animation = animate(app.value(), 0.3, 100); + expect(app.root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + , + ); + Fantom.runTask(() => { + animation.stop(); + app.setAnimating(false); + }); + Fantom.runWorkLoop(); + expect(app.root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + , + ); + }); +}); diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js b/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js index 604ec5fcd5ff..6aa304c7892e 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js @@ -8,6 +8,7 @@ * @format */ +import type {Node} from '../../Renderer/shims/ReactNativeTypes'; import type {RootTag} from '../../Types/RootTagTypes'; import type {PlatformConfig} from '../AnimatedPlatformConfig'; import type {AnimatedNodeConfig} from './AnimatedNode'; @@ -17,6 +18,7 @@ import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHe import * as ReactNativeFeatureFlags from '../../../src/private/featureflags/ReactNativeFeatureFlags'; import {getFabricUIManager} from '../../ReactNative/FabricUIManager'; import {getNodeFromPublicInstance} from '../../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance'; +import {create as createAttributePayload} from '../../ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload'; import {findNodeHandle} from '../../ReactNative/RendererProxy'; import flattenStyle from '../../StyleSheet/flattenStyle'; import {AnimatedEvent} from '../AnimatedEvent'; @@ -308,6 +310,83 @@ export default class AnimatedProps extends AnimatedNode { } invariant(this.__isNative, 'Expected node to be marked as "native"'); + const shadowNode = this.#getShadowNode(target); + if (shadowNode == null) { + return; + } + NativeAnimatedHelper.API.connectAnimatedNodeToShadowNodeFamily( + this.__getNativeTag(), + shadowNode, + ); + } + + /** + * Names of the props (and style props) that this node drives natively. + */ + __getNativePropNames(): Array { + const propNames = []; + const nodeKeys = this._nodeKeys; + const nodes = this._nodes; + for (let ii = 0, length = nodes.length; ii < length; ii++) { + const node = nodes[ii]; + if (node instanceof AnimatedStyle) { + propNames.push(...node.__getAnimatedKeys()); + } else { + propNames.push(nodeKeys[ii]); + } + } + return propNames; + } + + /** + * Hands props this node no longer drives back to the values `nextNode` sets. + */ + __releaseNativeProps( + propNames: ReadonlyArray, + nextNode: AnimatedProps, + ): void { + const target = this._target; + if ( + !this.__isNative || + target == null || + !ReactNativeFeatureFlags.cxxNativeAnimatedEnabled() || + //eslint-disable-next-line + !ReactNativeFeatureFlags.useSharedAnimatedBackend() + ) { + return; + } + const shadowNode = this.#getShadowNode(target); + if (shadowNode == null) { + return; + } + const nextStyleProp = nextNode._props.style; + const nextFlatStyle: ?Readonly<{[key: string]: unknown}> = + nextStyleProp instanceof AnimatedStyle + ? nextStyleProp.__getFlatStyle() + : flattenStyle(nextStyleProp as $FlowFixMe); + const nextStyle: Readonly<{[key: string]: unknown}> = nextFlatStyle ?? {}; + const values: {[key: string]: unknown} = {}; + for (const propName of propNames) { + values[propName] = hasOwn(nextNode._props, propName) + ? nextNode._props[propName] + : nextStyle[propName]; + } + // Processed like React does; props React no longer sets reset to null. + // $FlowFixMe[unclear-type] Fabric host instances carry their view config. + const instance: any = target.instance; + const validAttributes = instance?.__viewConfig?.validAttributes; + const payload: {[key: string]: unknown} = + validAttributes != null + ? (createAttributePayload(values, validAttributes) ?? {}) + : values; + const props: {[key: string]: unknown} = {}; + for (const propName of propNames) { + props[propName] = payload[propName] ?? null; + } + NativeAnimatedHelper.API.releaseAnimatedProps(shadowNode, props); + } + + #getShadowNode(target: TargetView): ?Node { // Host components and ScrollView (whose ref is the host instance) resolve a // shadow node directly; FlatList/SectionList are class composites that expose // the host via getNativeScrollRef(). @@ -333,13 +412,7 @@ export default class AnimatedProps extends AnimatedNode { connectedViewTag, ); } - if (shadowNode == null) { - return; - } - NativeAnimatedHelper.API.connectAnimatedNodeToShadowNodeFamily( - this.__getNativeTag(), - shadowNode, - ); + return shadowNode; } #disconnectAnimatedView(target: TargetView): void { diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js b/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js index c30f0926e5cc..8e9105a1c104 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js @@ -116,6 +116,14 @@ export default class AnimatedStyle extends AnimatedWithChildren { return new AnimatedStyle(nodeKeys, nodes, style, originalStyleForWeb); } + __getAnimatedKeys(): ReadonlyArray { + return this._nodeKeys; + } + + __getFlatStyle(): Readonly<{[key: string]: unknown}> { + return this._style; + } + constructor( nodeKeys: ReadonlyArray, nodes: ReadonlyArray, diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index db61fe34fd02..2bef6e0b3534 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -64,6 +64,7 @@ import com.facebook.react.fabric.mounting.SurfaceMountingManager; import com.facebook.react.fabric.mounting.mountitems.BatchMountItem; import com.facebook.react.fabric.mounting.mountitems.BatchedAnimatedPropsMountItem; +import com.facebook.react.fabric.mounting.mountitems.ClearSynchronousMountPropsOverrideMountItem; import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem; import com.facebook.react.fabric.mounting.mountitems.MountItem; import com.facebook.react.fabric.mounting.mountitems.MountItemFactory; @@ -959,6 +960,19 @@ private void destroyUnmountedView(int surfaceId, int reactTag) { MountItemFactory.createDestroyViewMountItem(surfaceId, reactTag)); } + /** + * Queued as a pre-mount item so it runs before the commit that sets these props, in both the push + * and pull models. + */ + @SuppressLint("NotInvokedPrivateMethod") // Called from C++ via JNI + @SuppressWarnings("unused") + @AnyThread + @ThreadConfined(ANY) + private void clearSynchronousMountPropsOverride(int surfaceId, int reactTag, String[] propNames) { + mMountItemDispatcher.addPreAllocateMountItem( + new ClearSynchronousMountPropsOverrideMountItem(surfaceId, reactTag, propNames)); + } + @SuppressLint("NotInvokedPrivateMethod") @SuppressWarnings("unused") @AnyThread diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.kt index 72b717d243da..b327465f56e1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.kt @@ -268,6 +268,12 @@ internal class MountingManager( getSurfaceManagerForView(reactTag)?.storeSynchronousMountPropsOverride(reactTag, props) } + @UiThread + internal fun clearSynchronousMountPropsOverride(reactTag: Int, propNames: Array) { + assertOnUiThread() + getSurfaceManagerForView(reactTag)?.clearSynchronousMountPropsOverride(reactTag, propNames) + } + /** Returns false when no surface owns [reactTag] yet, so the caller can queue the update. */ @UiThread fun updateAnimatedPropsSynchronously(reactTag: Int, props: ReadableMap): Boolean { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt index 8830c63a4e40..53a739473585 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.kt @@ -634,6 +634,14 @@ internal constructor( } } + internal fun clearSynchronousMountPropsOverride(reactTag: Int, propNames: Array) { + val synchronousMountProps = tagToSynchronousMountProps[reactTag] ?: return + propNames.forEach { synchronousMountProps.remove(it) } + if (synchronousMountProps.isEmpty()) { + tagToSynchronousMountProps.remove(reactTag) + } + } + public fun updatePropsSynchronously(reactTag: Int, props: ReadableMap) { updateProps(reactTag, props, true) } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/ClearSynchronousMountPropsOverrideMountItem.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/ClearSynchronousMountPropsOverrideMountItem.kt new file mode 100644 index 000000000000..4300414e5c7e --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/ClearSynchronousMountPropsOverrideMountItem.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.fabric.mounting.mountitems + +import com.facebook.react.fabric.mounting.MountingManager + +/** Stops re-applying [propNames] from earlier synchronous updates, without changing the view. */ +internal class ClearSynchronousMountPropsOverrideMountItem( + private val surfaceId: Int, + private val reactTag: Int, + private val propNames: Array, +) : MountItem { + + override fun execute(mountingManager: MountingManager) { + mountingManager.clearSynchronousMountPropsOverride(reactTag, propNames) + } + + override fun getSurfaceId(): Int = surfaceId + + override fun toString(): String = + "CLEAR_SYNCHRONOUS_MOUNT_PROPS_OVERRIDE [$reactTag] - ${propNames.joinToString()}" +} diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp index c20cefc00913..f4d40d7471b3 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp @@ -1369,6 +1369,22 @@ void FabricMountingManager::synchronouslyUpdateViewOnUIThread( synchronouslyUpdateViewOnUIThreadJNI(javaUIManager_, viewTag, propsMap.get()); } +void FabricMountingManager::clearSynchronousMountPropsOverride( + SurfaceId surfaceId, + Tag viewTag, + const std::vector& propNames) { + static auto clearSynchronousMountPropsOverrideJNI = + JFabricUIManager::javaClassStatic() + ->getMethod)>( + "clearSynchronousMountPropsOverride"); + auto names = jni::JArrayClass::newArray(propNames.size()); + for (size_t i = 0; i < propNames.size(); i++) { + names->setElement(i, jni::make_jstring(propNames[i]).get()); + } + clearSynchronousMountPropsOverrideJNI( + javaUIManager_, surfaceId, viewTag, names.get()); +} + void FabricMountingManager::synchronouslyUpdateAnimatedProps( const std::unordered_map& updates) { TraceSection s( diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h index b835826de4d1..e5fce1d6d315 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h @@ -93,6 +93,8 @@ class FabricMountingManager final { void synchronouslyUpdateViewOnUIThread(Tag viewTag, const folly::dynamic &props); + void clearSynchronousMountPropsOverride(SurfaceId surfaceId, Tag viewTag, const std::vector &propNames); + void synchronouslyUpdateAnimatedProps(const std::unordered_map &updates); void captureViewSnapshot(Tag tag, SurfaceId surfaceId); diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp index 481f3d043632..e2292b2d70f7 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp @@ -854,6 +854,16 @@ void FabricUIManagerBinding::schedulerShouldSynchronouslyUpdateViewOnUIThread( } } +void FabricUIManagerBinding::schedulerShouldClearSynchronousMountPropsOverride( + SurfaceId surfaceId, + Tag tag, + const std::vector& propNames) { + if (ReactNativeFeatureFlags::cxxNativeAnimatedEnabled() && mountingManager_) { + mountingManager_->clearSynchronousMountPropsOverride( + surfaceId, tag, propNames); + } +} + void FabricUIManagerBinding::schedulerShouldSynchronouslyUpdateAnimatedProps( const std::unordered_map& updates) { if (ReactNativeFeatureFlags::cxxNativeAnimatedEnabled() && mountingManager_) { diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h index 68c47706ba7b..d5f10ce706f3 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.h @@ -115,6 +115,11 @@ class FabricUIManagerBinding : public jni::HybridClass, void schedulerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) override; + void schedulerShouldClearSynchronousMountPropsOverride( + SurfaceId surfaceId, + Tag tag, + const std::vector &propNames) override; + void schedulerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map &updates) override; void schedulerDidUpdateShadowTree(const std::unordered_map &tagToProps) override; diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/SurfaceMountingManagerSynchronousMountPropsTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/SurfaceMountingManagerSynchronousMountPropsTest.kt index 49d7940429e4..9dfe017a2b81 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/SurfaceMountingManagerSynchronousMountPropsTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/SurfaceMountingManagerSynchronousMountPropsTest.kt @@ -16,6 +16,7 @@ import com.facebook.react.bridge.ReactTestHelper import com.facebook.react.bridge.ReadableArray import com.facebook.react.fabric.mounting.MountingManager import com.facebook.react.fabric.mounting.SurfaceMountingManager +import com.facebook.react.fabric.mounting.mountitems.ClearSynchronousMountPropsOverrideMountItem import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.ViewManager @@ -253,6 +254,73 @@ class SurfaceMountingManagerSynchronousMountPropsTest { assertThat(smm.getView(tag).alpha).isEqualTo(0.9f) } + /** After the override is cleared, the next Fabric mount update sets the prop again. */ + @Test + fun clearOverride_letsTheNextMountSetTheProp() { + val smm = startSurface() + val tag = 42 + createAndAttachView(smm, tag) + + smm.storeSynchronousMountPropsOverride(tag, JavaOnlyMap.of("opacity", 0.2)) + smm.updatePropsSynchronously(tag, JavaOnlyMap.of("opacity", 0.2)) + + smm.clearSynchronousMountPropsOverride(tag, arrayOf("opacity")) + smm.updateProps(tag, JavaOnlyMap.of("opacity", 0.6)) + + assertThat(smm.getView(tag).alpha).isEqualTo(0.6f) + } + + /** Clearing the override doesn't change the view until the next mount update. */ + @Test + fun clearOverride_leavesTheViewAsItIs() { + val smm = startSurface() + val tag = 42 + createAndAttachView(smm, tag) + + smm.storeSynchronousMountPropsOverride(tag, JavaOnlyMap.of("opacity", 0.2)) + smm.updatePropsSynchronously(tag, JavaOnlyMap.of("opacity", 0.2)) + + smm.clearSynchronousMountPropsOverride(tag, arrayOf("opacity")) + + assertThat(smm.getView(tag).alpha).isEqualTo(0.2f) + } + + /** Only the listed props are cleared; the others keep overriding stale mount updates. */ + @Test + fun clearOverride_keepsPropsThatAreNotListed() { + val smm = startSurface() + val tag = 42 + val transform = JavaOnlyArray.of(JavaOnlyMap.of("translateY", 40.0)) + createAndAttachView(smm, tag) + + val animatedProps = JavaOnlyMap.of("opacity", 0.2, "transform", transform) + smm.storeSynchronousMountPropsOverride(tag, animatedProps) + smm.updatePropsSynchronously(tag, animatedProps) + + smm.clearSynchronousMountPropsOverride(tag, arrayOf("opacity")) + smm.updateProps(tag, JavaOnlyMap.of("opacity", 0.6, "transform", null)) + + assertThat(smm.getView(tag).alpha).isEqualTo(0.6f) + assertThat(smm.getView(tag).translationY).isEqualTo(40.0f) + } + + /** The mount item queued from C++ clears the override through the [MountingManager]. */ + @Test + fun clearOverrideMountItem_clearsTheOverride() { + val smm = startSurface() + val tag = 42 + createAndAttachView(smm, tag) + + smm.storeSynchronousMountPropsOverride(tag, JavaOnlyMap.of("opacity", 0.2)) + smm.updatePropsSynchronously(tag, JavaOnlyMap.of("opacity", 0.2)) + + ClearSynchronousMountPropsOverrideMountItem(surfaceId, tag, arrayOf("opacity")) + .execute(mountingManager) + smm.updateProps(tag, JavaOnlyMap.of("opacity", 0.6)) + + assertThat(smm.getView(tag).alpha).isEqualTo(0.6f) + } + /** Synchronous props stored for one tag should not affect a different tag. */ @Test fun synchronousPropsAreIsolatedPerTag() { diff --git a/packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.cpp b/packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.cpp index 0410bd6e7bc2..113699c34ae9 100644 --- a/packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.cpp +++ b/packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.cpp @@ -173,6 +173,22 @@ void AnimatedModule::connectAnimatedNodeToShadowNodeFamily( .shadowNodeFamily = shadowNode->getFamilyShared()}); } +void AnimatedModule::releaseAnimatedProps( + jsi::Runtime& rt, + jsi::Object shadowNodeObj, + jsi::Object props) { + // Not queued: it has to reach the backend before the React commit. + auto nodesManager = nodesManager_.lock(); + if (!nodesManager) { + return; + } + const auto& shadowNode = Bridging>::fromJs( + rt, jsi::Value(rt, shadowNodeObj)); + nodesManager->releaseAnimatedProps( + shadowNode->getFamilyShared(), + jsi::dynamicFromValue(rt, jsi::Value(rt, props))); +} + void AnimatedModule::disconnectAnimatedNodeFromView( jsi::Runtime& /*rt*/, Tag nodeTag, diff --git a/packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.h b/packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.h index 443e98f79648..56441c087338 100644 --- a/packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.h +++ b/packages/react-native/ReactCommon/react/renderer/animated/AnimatedModule.h @@ -186,6 +186,8 @@ class AnimatedModule : public NativeAnimatedModuleCxxSpec, publi void connectAnimatedNodeToShadowNodeFamily(jsi::Runtime &rt, Tag nodeTag, jsi::Object shadowNode); + void releaseAnimatedProps(jsi::Runtime &rt, jsi::Object shadowNode, jsi::Object props); + void disconnectAnimatedNodeFromView(jsi::Runtime &rt, Tag nodeTag, Tag viewTag); void restoreDefaultValues(jsi::Runtime &rt, Tag nodeTag); diff --git a/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp b/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp index de87a75b0c5a..753e0ff7ab1c 100644 --- a/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp @@ -289,6 +289,11 @@ void NativeAnimatedNodesManager::disconnectAnimatedNodeFromView( if (node != nullptr) { node->disconnectFromView(viewTag); if (useSharedAnimatedBackend_) { + if (auto family = node->getShadowNodeFamily()) { + if (auto animationBackend = animationBackend_.lock()) { + animationBackend->onAnimatedNodeDisconnected(family); + } + } node->disconnectFromShadowNodeFamily(); } { @@ -304,6 +309,17 @@ void NativeAnimatedNodesManager::disconnectAnimatedNodeFromView( } } +void NativeAnimatedNodesManager::releaseAnimatedProps( + const std::shared_ptr& family, + const folly::dynamic& props) noexcept { + if (!useSharedAnimatedBackend_) { + return; + } + if (auto animationBackend = animationBackend_.lock()) { + animationBackend->releaseAnimatedProps(family, props); + } +} + void NativeAnimatedNodesManager::disconnectAnimatedNodes( Tag parentTag, Tag childTag) noexcept { diff --git a/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.h b/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.h index 84d580168f40..f4678d7a95af 100644 --- a/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.h +++ b/packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.h @@ -116,6 +116,10 @@ class NativeAnimatedNodesManager : public std::enable_shared_from_this &family, + const folly::dynamic &props) noexcept; + void restoreDefaultValues(Tag tag) noexcept; void dropAnimatedNode(Tag tag) noexcept; diff --git a/packages/react-native/ReactCommon/react/renderer/animated/nodes/PropsAnimatedNode.h b/packages/react-native/ReactCommon/react/renderer/animated/nodes/PropsAnimatedNode.h index fb29e431aa8a..f71c75a7a61f 100644 --- a/packages/react-native/ReactCommon/react/renderer/animated/nodes/PropsAnimatedNode.h +++ b/packages/react-native/ReactCommon/react/renderer/animated/nodes/PropsAnimatedNode.h @@ -27,6 +27,10 @@ class PropsAnimatedNode final : public AnimatedNode { // Only called when `useSharedAnimatedBackend`==true void connectToShadowNodeFamily(ShadowNodeFamily::Weak shadowNodeFamily); void disconnectFromShadowNodeFamily(); + std::shared_ptr getShadowNodeFamily() const + { + return shadowNodeFamily_.lock(); + } void connectToView(Tag viewTag); void disconnectFromView(Tag viewTag); diff --git a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsRegistry.cpp b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsRegistry.cpp index f00e3b2536b7..f17e41c054ac 100644 --- a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsRegistry.cpp +++ b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsRegistry.cpp @@ -116,8 +116,11 @@ void AnimatedPropsRegistry::initializeSurface(SurfaceId surfaceId) { std::pair, std::shared_ptr> AnimatedPropsRegistry::getMap(SurfaceId surfaceId) { auto lock = std::lock_guard(mutex_); - auto& [pendingMap, map, pendingFamilies, families] = - surfaceContexts_[surfaceId]; + auto& surfaceContext = surfaceContexts_[surfaceId]; + auto& pendingMap = surfaceContext.pendingMap; + auto& map = surfaceContext.map; + auto& pendingFamilies = surfaceContext.pendingFamilies; + auto& families = surfaceContext.families; if (!pendingFamilies.empty()) { auto nextFamilies = families ? std::make_shared(*families) @@ -184,6 +187,122 @@ void AnimatedPropsRegistry::clear(SurfaceId surfaceId) { } } +namespace { + +std::shared_ptr withReleasedProps( + const PropsSnapshot& snapshot, + const folly::dynamic& releasedProps) { + auto result = std::make_shared(); + result->rawProps = snapshot.rawProps + ? std::make_unique(*snapshot.rawProps) + : std::make_unique(folly::dynamic::object()); + for (const auto& [key, value] : releasedProps.items()) { + (*result->rawProps)[key] = value; + } + // Animated only writes raw props; typed props are kept. + if (snapshot.props) { + result->props = std::make_unique(*snapshot.props); + } + result->propNames = snapshot.propNames; + result->text = snapshot.text; + return result; +} + +} // namespace + +void AnimatedPropsRegistry::releaseProps( + const std::shared_ptr& family, + const folly::dynamic& props) { + auto lock = std::lock_guard(mutex_); + const auto tag = family->getTag(); + auto contextIt = surfaceContexts_.find(family->getSurfaceId()); + if (contextIt == surfaceContexts_.end()) { + return; + } + auto& surfaceContext = contextIt->second; + auto& releasedPropNames = surfaceContext.releasedPropNames[tag]; + for (const auto& [key, _] : props.items()) { + releasedPropNames.insert(key.asString()); + } + bool found = false; + if (auto it = surfaceContext.pendingMap.find(tag); + it != surfaceContext.pendingMap.end()) { + it->second = withReleasedProps(*it->second, props); + found = true; + } + if (surfaceContext.map) { + if (auto it = surfaceContext.map->find(tag); + it != surfaceContext.map->end()) { + auto nextMap = std::make_shared(*surfaceContext.map); + (*nextMap)[tag] = withReleasedProps(*it->second, props); + surfaceContext.map = std::move(nextMap); + found = true; + } + } + if (!found) { + // The animated values were already committed and dropped; commit React's. + surfaceContext.pendingMap[tag] = withReleasedProps(PropsSnapshot{}, props); + surfaceContext.pendingFamilies.insert(family); + } +} + +void AnimatedPropsRegistry::dropReleasedProps( + std::vector& batches) { + auto lock = std::lock_guard(mutex_); + for (auto& mutations : batches) { + auto& batch = mutations.batch; + for (auto& mutation : batch) { + if (!mutation.family || !mutation.props.rawProps) { + continue; + } + auto contextIt = surfaceContexts_.find(mutation.family->getSurfaceId()); + if (contextIt == surfaceContexts_.end()) { + continue; + } + const auto& releasedByTag = contextIt->second.releasedPropNames; + auto releasedIt = releasedByTag.find(mutation.tag); + if (releasedIt == releasedByTag.end()) { + continue; + } + const auto& rawProps = *mutation.props.rawProps; + auto props = rawProps.getDynamic() != nullptr ? *rawProps.getDynamic() + : rawProps.toDynamic(); + if (!props.isObject()) { + continue; + } + bool dropped = false; + for (const auto& propName : releasedIt->second) { + if (props.erase(propName) != 0) { + dropped = true; + } + } + if (dropped) { + mutation.props.rawProps = props.empty() + ? nullptr + : std::make_unique(std::move(props)); + } + } + batch.erase( + std::remove_if( + batch.begin(), + batch.end(), + [](const AnimationMutation& mutation) { + return !mutation.props.rawProps && mutation.props.props.empty() && + !mutation.props.text; + }), + batch.end()); + } +} + +void AnimatedPropsRegistry::onAnimatedNodeDisconnected( + const std::shared_ptr& family) { + auto lock = std::lock_guard(mutex_); + auto contextIt = surfaceContexts_.find(family->getSurfaceId()); + if (contextIt != surfaceContexts_.end()) { + contextIt->second.releasedPropNames.erase(family->getTag()); + } +} + void AnimatedPropsRegistry::clearOnSurfaceStop(SurfaceId surfaceId) { auto lock = std::lock_guard(mutex_); surfaceContexts_.erase(surfaceId); diff --git a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsRegistry.h b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsRegistry.h index d2e124046cd8..b09cf2cd891a 100644 --- a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsRegistry.h +++ b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropsRegistry.h @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "AnimatedProps.h" #include "AnimationMutation.h" @@ -36,6 +38,8 @@ struct SurfaceContext { std::shared_ptr map; FamilySet pendingFamilies; std::shared_ptr families; + // Kept until the node that drove them disconnects. + std::unordered_map> releasedPropNames; }; /* @@ -57,6 +61,11 @@ class AnimatedPropsRegistry { void initializeSurface(SurfaceId surfaceId); void clear(SurfaceId surfaceId); void clearOnSurfaceStop(SurfaceId surfaceId); + // Replaces animated props no longer driven with React's values (null resets). + void releaseProps(const std::shared_ptr &family, const folly::dynamic &props); + // Drops released props from updates computed before the release. + void dropReleasedProps(std::vector &batches); + void onAnimatedNodeDisconnected(const std::shared_ptr &family); std::pair, std::shared_ptr> getMap(SurfaceId surfaceId); private: diff --git a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp index 4e461d226637..b4b358a052f6 100644 --- a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp +++ b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp @@ -166,6 +166,7 @@ void AnimationBackend::applySurfaceUpdates( } void AnimationBackend::applyMutations(std::vector batches) { + animatedPropsRegistry_->dropReleasedProps(batches); animatedPropsRegistry_->update(batches); std::unordered_map surfaceUpdates; std::set asyncFlushSurfaces; @@ -353,6 +354,29 @@ void AnimationBackend::clearRegistry(SurfaceId surfaceId) { animatedPropsRegistry_->clear(surfaceId); } +void AnimationBackend::releaseAnimatedProps( + const std::shared_ptr& family, + const folly::dynamic& props) { + animatedPropsRegistry_->releaseProps(family, props); + // Android re-applies directly written props on later mounts. + if (auto uiManager = uiManager_.lock()) { + std::vector propNames; + propNames.reserve(props.size()); + for (const auto& [key, _] : props.items()) { + propNames.push_back(key.asString()); + } + uiManager->clearSynchronousMountPropsOverride( + family->getSurfaceId(), family->getTag(), propNames); + } + // React doesn't commit when its value is unchanged (e.g. back to 1). + requestAsyncFlushForSurfaces({family->getSurfaceId()}); +} + +void AnimationBackend::onAnimatedNodeDisconnected( + const std::shared_ptr& family) { + animatedPropsRegistry_->onAnimatedNodeDisconnected(family); +} + void AnimationBackend::clearRegistryOnSurfaceStop(SurfaceId surfaceId) { animatedPropsRegistry_->clearOnSurfaceStop(surfaceId); } diff --git a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h index 3c328ff2adb1..8dd18e71293d 100644 --- a/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h +++ b/packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h @@ -49,6 +49,9 @@ class AnimationBackend : public UIManagerAnimationBackend { void requestAsyncFlushForSurfaces(const std::set &surfaces); void clearRegistry(SurfaceId surfaceId) override; void clearRegistryOnSurfaceStop(SurfaceId surfaceId) override; + void releaseAnimatedProps(const std::shared_ptr &family, const folly::dynamic &props) + override; + void onAnimatedNodeDisconnected(const std::shared_ptr &family) override; void registerJSInvoker(std::shared_ptr jsInvoker) override; void onAnimationFrame(AnimationTimestamp timestamp) override; diff --git a/packages/react-native/ReactCommon/react/renderer/animationbackend/tests/AnimatedPropsRegistryTest.cpp b/packages/react-native/ReactCommon/react/renderer/animationbackend/tests/AnimatedPropsRegistryTest.cpp index eb19bd37c008..81a23e59f621 100644 --- a/packages/react-native/ReactCommon/react/renderer/animationbackend/tests/AnimatedPropsRegistryTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/animationbackend/tests/AnimatedPropsRegistryTest.cpp @@ -360,4 +360,82 @@ TEST_F(AnimatedPropsRegistryTest, concurrentGetMapClearAndSurfaceStop) { clearer.join(); } +std::vector rawMutations( + const std::shared_ptr& family, + const folly::dynamic& props) { + std::vector batches(1); + batches[0].batch.push_back( + AnimationMutation{ + .tag = 10, + .family = family, + .props = AnimatedProps{ + .props = {}, .rawProps = std::make_unique(props)}}); + return batches; +} + +TEST_F(AnimatedPropsRegistryTest, releasedPropsReplacePendingAnimatedValues) { + updateRaw(folly::dynamic::object("opacity", 0.2)("borderRadius", 4)); + registry.releaseProps( + node->getFamilyShared(), folly::dynamic::object("opacity", 0.6)); + expectRawProps(folly::dynamic::object("opacity", 0.6)("borderRadius", 4)); +} + +TEST_F(AnimatedPropsRegistryTest, releasedPropsReplaceCommittedAnimatedValues) { + updateRaw(folly::dynamic::object("opacity", 0.2)("borderRadius", 4)); + snapshot(); + registry.releaseProps( + node->getFamilyShared(), folly::dynamic::object("opacity", nullptr)); + expectRawProps(folly::dynamic::object("opacity", nullptr)("borderRadius", 4)); +} + +TEST_F(AnimatedPropsRegistryTest, releaseWithoutAnimatedValuesStillCommits) { + registry.releaseProps( + node->getFamilyShared(), folly::dynamic::object("opacity", 1)); + auto [families, map] = registry.getMap(1); + ASSERT_NE(families, nullptr); + EXPECT_TRUE(families->contains(node->getFamilyShared())); + expectRawProps(folly::dynamic::object("opacity", 1)); +} + +TEST_F(AnimatedPropsRegistryTest, laterUpdatesDropReleasedProps) { + updateRaw(folly::dynamic::object("opacity", 0.2)); + registry.releaseProps( + node->getFamilyShared(), folly::dynamic::object("opacity", 0.6)); + + // A frame computed before the release reaches the registry after it. + auto batches = rawMutations( + node->getFamilyShared(), + folly::dynamic::object("opacity", 0.2)("borderRadius", 4)); + registry.dropReleasedProps(batches); + ASSERT_EQ(batches[0].batch.size(), 1); + EXPECT_EQ( + batches[0].batch[0].props.rawProps->toDynamic(), + folly::dynamic(folly::dynamic::object("borderRadius", 4))); + registry.update(batches); + + expectRawProps(folly::dynamic::object("opacity", 0.6)("borderRadius", 4)); +} + +TEST_F(AnimatedPropsRegistryTest, updatesWithOnlyReleasedPropsAreRemoved) { + registry.releaseProps( + node->getFamilyShared(), folly::dynamic::object("opacity", 0.6)); + auto batches = rawMutations( + node->getFamilyShared(), folly::dynamic::object("opacity", 0.2)); + registry.dropReleasedProps(batches); + EXPECT_TRUE(batches[0].batch.empty()); +} + +TEST_F(AnimatedPropsRegistryTest, releasedPropsCanBeAnimatedAfterDisconnect) { + registry.releaseProps( + node->getFamilyShared(), folly::dynamic::object("opacity", 0.6)); + registry.onAnimatedNodeDisconnected(node->getFamilyShared()); + + auto batches = rawMutations( + node->getFamilyShared(), folly::dynamic::object("opacity", 0.3)); + registry.dropReleasedProps(batches); + ASSERT_EQ(batches[0].batch.size(), 1); + registry.update(batches); + expectRawProps(folly::dynamic::object("opacity", 0.3)); +} + } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp index a278fb2b3400..65a36532f289 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -378,6 +378,16 @@ void Scheduler::uiManagerShouldSynchronouslyUpdateViewOnUIThread( } } +void Scheduler::uiManagerShouldClearSynchronousMountPropsOverride( + SurfaceId surfaceId, + Tag tag, + const std::vector& propNames) { + if (delegate_ != nullptr) { + delegate_->schedulerShouldClearSynchronousMountPropsOverride( + surfaceId, tag, propNames); + } +} + void Scheduler::uiManagerShouldSynchronouslyUpdateAnimatedProps( const std::unordered_map& updates) { if (delegate_ != nullptr) { diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h index 139df24d68d3..be38431b52d6 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h @@ -96,6 +96,10 @@ class Scheduler final : public UIManagerDelegate { bool isJSResponder, bool blockNativeResponder) override; void uiManagerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) override; + void uiManagerShouldClearSynchronousMountPropsOverride( + SurfaceId surfaceId, + Tag tag, + const std::vector &propNames) override; void uiManagerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map &updates) override; void uiManagerDidUpdateShadowTree(const std::unordered_map &tagToProps) override; void uiManagerDidCaptureViewSnapshot(Tag tag, SurfaceId surfaceId) override; diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h b/packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h index 27c28495fe23..dee1cf650ce1 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerDelegate.h @@ -10,7 +10,9 @@ #include #include +#include #include +#include #include #include @@ -69,6 +71,16 @@ class SchedulerDelegate { virtual void schedulerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) = 0; + /* + * Stops re-applying these props from earlier synchronous updates of the view. + */ + virtual void schedulerShouldClearSynchronousMountPropsOverride( + SurfaceId /*surfaceId*/, + Tag /*tag*/, + const std::vector & /*propNames*/) + { + } + /* * Synchronous update of animated props for many views at once. By default, * forwards each view to `schedulerShouldSynchronouslyUpdateViewOnUIThread`. diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp index 6a18881fd844..42ae2a46d502 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp @@ -772,6 +772,16 @@ void UIManager::synchronouslyUpdateViewOnUIThread( } } +void UIManager::clearSynchronousMountPropsOverride( + SurfaceId surfaceId, + Tag tag, + const std::vector& propNames) { + if (delegate_ != nullptr) { + delegate_->uiManagerShouldClearSynchronousMountPropsOverride( + surfaceId, tag, propNames); + } +} + void UIManager::synchronouslyUpdateAnimatedProps( const std::unordered_map& updates) { if (delegate_ != nullptr) { diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h index 541d57a0b258..010839fda926 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h @@ -89,6 +89,8 @@ class UIManager final : public ShadowTreeDelegate { void synchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props); + void clearSynchronousMountPropsOverride(SurfaceId surfaceId, Tag tag, const std::vector &propNames); + void synchronouslyUpdateAnimatedProps(const std::unordered_map &updates); /* diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationBackend.h b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationBackend.h index d57f1e772ca9..71312c019bcc 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationBackend.h +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerAnimationBackend.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,12 @@ class UIManagerAnimationBackend { virtual void stop(CallbackId callbackId) = 0; virtual void clearRegistry(SurfaceId surfaceId) = 0; virtual void clearRegistryOnSurfaceStop(SurfaceId surfaceId) = 0; + virtual void onAnimatedNodeDisconnected(const std::shared_ptr & /*family*/) {} + virtual void releaseAnimatedProps( + const std::shared_ptr & /*family*/, + const folly::dynamic & /*props*/) + { + } virtual void trigger() = 0; virtual void pushAnimationMutations(const Callback &callback) = 0; virtual void registerJSInvoker(std::shared_ptr jsInvoker) = 0; diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerDelegate.h b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerDelegate.h index e431d6ee22b1..8327511b78f4 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerDelegate.h +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerDelegate.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -73,6 +74,16 @@ class UIManagerDelegate { */ virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) = 0; + /* + * Stops re-applying these props from earlier synchronous updates of the view. + */ + virtual void uiManagerShouldClearSynchronousMountPropsOverride( + SurfaceId /*surfaceId*/, + Tag /*tag*/, + const std::vector & /*propNames*/) + { + } + /* * Synchronous update of animated props for many views at once. */ diff --git a/packages/react-native/src/private/animated/NativeAnimatedHelper.js b/packages/react-native/src/private/animated/NativeAnimatedHelper.js index e6de1345f094..f15f7374f989 100644 --- a/packages/react-native/src/private/animated/NativeAnimatedHelper.js +++ b/packages/react-native/src/private/animated/NativeAnimatedHelper.js @@ -37,6 +37,12 @@ interface NativeAnimatedModuleSpec extends NativeAnimatedTurboModuleSpec { // $FlowExpectedError[unclear-type]. shadowNode: any, ) => void; + // releaseAnimatedProps is available only in NativeAnimatedNonTurboModule + readonly releaseAnimatedProps?: ( + // $FlowExpectedError[unclear-type]. + shadowNode: any, + props: {[key: string]: unknown}, + ) => void; } // TODO T69437152 @petetheheat - Delete this fork when Fabric ships to 100%. @@ -188,6 +194,13 @@ const API = { shadowNode, ); }, + releaseAnimatedProps( + shadowNode: Node, + props: {[key: string]: unknown}, + ): void { + // Not batched: it has to land before the React commit. + NativeAnimatedModule?.releaseAnimatedProps?.(shadowNode, props); + }, connectAnimatedNodeToView(nodeTag: number, viewTag: number): void { NativeOperations.connectAnimatedNodeToView(nodeTag, viewTag); }, diff --git a/packages/react-native/src/private/animated/createAnimatedPropsHook.js b/packages/react-native/src/private/animated/createAnimatedPropsHook.js index 499ade268ea0..4aba75a19e7b 100644 --- a/packages/react-native/src/private/animated/createAnimatedPropsHook.js +++ b/packages/react-native/src/private/animated/createAnimatedPropsHook.js @@ -289,11 +289,26 @@ function addAnimatedValuesListenersToProps( */ function useAnimatedPropsLifecycle(node: AnimatedProps): void { const isMounted = useRef(false); + const prevNodeRef = useRef(null); useInsertionEffect(() => { isMounted.current = true; node.__attach(); + // Release props the previous node drove natively and this one doesn't, + // before the commit that sets them. + const prevNode = prevNodeRef.current; + prevNodeRef.current = node; + if (prevNode != null && prevNode !== node) { + const propNames = new Set(node.__getNativePropNames()); + const releasedPropNames = prevNode + .__getNativePropNames() + .filter(propName => !propNames.has(propName)); + if (releasedPropNames.length > 0) { + prevNode.__releaseNativeProps(releasedPropNames, node); + } + } + return () => { isMounted.current = false; queueMicrotask(() => { diff --git a/packages/react-native/src/private/specs_DEPRECATED/modules/NativeAnimatedModule.js b/packages/react-native/src/private/specs_DEPRECATED/modules/NativeAnimatedModule.js index e8f6548167e0..143d277e64b4 100644 --- a/packages/react-native/src/private/specs_DEPRECATED/modules/NativeAnimatedModule.js +++ b/packages/react-native/src/private/specs_DEPRECATED/modules/NativeAnimatedModule.js @@ -69,6 +69,10 @@ export interface Spec extends TurboModule { nodeTag: number, shadowNode: UnsafeObject, ) => void; + readonly releaseAnimatedProps?: ( + shadowNode: UnsafeObject, + props: UnsafeObject, + ) => void; readonly disconnectAnimatedNodeFromView: ( nodeTag: number, viewTag: number, diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api index 456c30e7f37d..aeaaba8a990b 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api @@ -1244,6 +1244,7 @@ class facebook::react::FabricMountingManager { public bool isViewAllocated(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag); public void captureViewSnapshot(facebook::react::Tag tag, facebook::react::SurfaceId surfaceId); public void clearPendingSnapshots(); + public void clearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag viewTag, const std::vector& propNames); public void destroyUnmountedShadowNode(const facebook::react::ShadowNodeFamily& family); public void dispatchCommand(const facebook::react::ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args); public void drainPreallocateViewsQueue(); diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api index 0cf931d8a049..f43f47c9f841 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api @@ -1263,6 +1263,7 @@ class facebook::react::AnimatedModule : public facebook::react::NativeAnimatedMo public void flattenAnimatedNodeOffset(facebook::jsi::Runtime& rt, facebook::react::Tag nodeTag); public void getValue(facebook::jsi::Runtime& rt, facebook::react::Tag tag, facebook::react::AsyncCallback saveValueCallback); public void queueAndExecuteBatchedOperations(facebook::jsi::Runtime& rt, facebook::jsi::Array operationsAndArgs); + public void releaseAnimatedProps(facebook::jsi::Runtime& rt, facebook::jsi::Object shadowNode, facebook::jsi::Object props); public void removeAnimatedEventFromView(facebook::jsi::Runtime& rt, facebook::react::Tag viewTag, std::string eventName, facebook::react::Tag animatedNodeTag); public void removeListeners(facebook::jsi::Runtime& rt, int count); public void restoreDefaultValues(facebook::jsi::Runtime& rt, facebook::react::Tag nodeTag); @@ -1310,9 +1311,11 @@ class facebook::react::AnimationBackend : public facebook::react::UIManagerAnima public virtual facebook::react::CallbackId start(const facebook::react::UIManagerAnimationBackend::Callback& callback) override; public virtual void clearRegistry(facebook::react::SurfaceId surfaceId) override; public virtual void clearRegistryOnSurfaceStop(facebook::react::SurfaceId surfaceId) override; + public virtual void onAnimatedNodeDisconnected(const std::shared_ptr& family) override; public virtual void onAnimationFrame(facebook::react::AnimationTimestamp timestamp) override; public virtual void pushAnimationMutations(const facebook::react::UIManagerAnimationBackend::Callback& callback) override; public virtual void registerJSInvoker(std::shared_ptr jsInvoker) override; + public virtual void releaseAnimatedProps(const std::shared_ptr& family, const folly::dynamic& props) override; public virtual void stop(facebook::react::CallbackId callbackId) override; public virtual void trigger() override; public void requestAsyncFlushForSurfaces(const std::set& surfaces); @@ -1953,6 +1956,7 @@ class facebook::react::FabricMountingManager { public bool isViewAllocated(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag); public void captureViewSnapshot(facebook::react::Tag tag, facebook::react::SurfaceId surfaceId); public void clearPendingSnapshots(); + public void clearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag viewTag, const std::vector& propNames); public void destroyUnmountedShadowNode(const facebook::react::ShadowNodeFamily& family); public void dispatchCommand(const facebook::react::ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args); public void drainPreallocateViewsQueue(); @@ -2874,6 +2878,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr public void insertMutations(std::unordered_map>& updates, facebook::react::AnimationMutations& mutations, facebook::react::AnimatedPropsBuilder& propsBuilder, bool hasLayoutUpdates = false); public void onManagedPropsRemoved(facebook::react::Tag tag) noexcept; public void onRender(); + public void releaseAnimatedProps(const std::shared_ptr& family, const folly::dynamic& props) noexcept; public void removeAnimatedEventFromView(facebook::react::Tag viewTag, const std::string& eventName, facebook::react::Tag animatedValueTag) noexcept; public void resolvePlatformColor(facebook::react::SurfaceId surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result) const; public void restoreDefaultValues(facebook::react::Tag tag) noexcept; @@ -3548,6 +3553,7 @@ class facebook::react::Scheduler : public facebook::react::UIManagerDelegate { public virtual void uiManagerDidUpdateShadowTree(const std::unordered_map& tagToProps) override; public virtual void uiManagerShouldAddEventListener(std::shared_ptr listener) final; public virtual void uiManagerShouldAddOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback) override; + public virtual void uiManagerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag, const std::vector& propNames) override; public virtual void uiManagerShouldRemoveEventListener(const std::shared_ptr& listener) final; public virtual void uiManagerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates) override; public virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props) override; @@ -3571,6 +3577,7 @@ class facebook::react::SchedulerDelegate { public virtual void schedulerDidSetIsJSResponder(const facebook::react::ShadowView& shadowView, bool isJSResponder, bool blockNativeResponder) = 0; public virtual void schedulerDidSetViewSnapshot(facebook::react::Tag sourceTag, facebook::react::Tag targetTag, facebook::react::SurfaceId surfaceId) = 0; public virtual void schedulerDidUpdateShadowTree(const std::unordered_map& tagToProps) = 0; + public virtual void schedulerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId, facebook::react::Tag, const std::vector&); public virtual void schedulerShouldMergeReactRevision(facebook::react::SurfaceId surfaceId) = 0; public virtual void schedulerShouldRenderTransactions(const std::shared_ptr& mountingCoordinator) = 0; public virtual void schedulerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates); @@ -4237,6 +4244,7 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate { public void addOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback); public void animationTick() const; public void appendChild(const std::shared_ptr& parentShadowNode, const std::shared_ptr& childShadowNode) const; + public void clearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag, const std::vector& propNames); public void completeSurface(facebook::react::SurfaceId surfaceId, const std::shared_ptr>>& rootChildren, facebook::react::ShadowTree::CommitOptions commitOptions); public void dispatchCommand(const std::shared_ptr& shadowNode, const std::string& commandName, const folly::dynamic& args) const; public void registerCommitHook(facebook::react::UIManagerCommitHook& commitHook); @@ -4269,9 +4277,11 @@ class facebook::react::UIManagerAnimationBackend { public virtual facebook::react::CallbackId start(const facebook::react::UIManagerAnimationBackend::Callback& callback) = 0; public virtual void clearRegistry(facebook::react::SurfaceId surfaceId) = 0; public virtual void clearRegistryOnSurfaceStop(facebook::react::SurfaceId surfaceId) = 0; + public virtual void onAnimatedNodeDisconnected(const std::shared_ptr&); public virtual void onAnimationFrame(facebook::react::AnimationTimestamp timestamp) = 0; public virtual void pushAnimationMutations(const facebook::react::UIManagerAnimationBackend::Callback& callback) = 0; public virtual void registerJSInvoker(std::shared_ptr jsInvoker) = 0; + public virtual void releaseAnimatedProps(const std::shared_ptr&, const folly::dynamic&); public virtual void stop(facebook::react::CallbackId callbackId) = 0; public virtual void trigger() = 0; public virtual ~UIManagerAnimationBackend() = default; @@ -4321,6 +4331,7 @@ class facebook::react::UIManagerDelegate { public virtual void uiManagerDidUpdateShadowTree(const std::unordered_map& tagToProps) = 0; public virtual void uiManagerShouldAddEventListener(std::shared_ptr listener) = 0; public virtual void uiManagerShouldAddOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback) = 0; + public virtual void uiManagerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId, facebook::react::Tag, const std::vector&); public virtual void uiManagerShouldRemoveEventListener(const std::shared_ptr& listener) = 0; public virtual void uiManagerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates) = 0; public virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props) = 0; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api index 81dc01048c7a..59a744a0be9e 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api @@ -1244,6 +1244,7 @@ class facebook::react::FabricMountingManager { public bool isViewAllocated(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag); public void captureViewSnapshot(facebook::react::Tag tag, facebook::react::SurfaceId surfaceId); public void clearPendingSnapshots(); + public void clearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag viewTag, const std::vector& propNames); public void destroyUnmountedShadowNode(const facebook::react::ShadowNodeFamily& family); public void dispatchCommand(const facebook::react::ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args); public void drainPreallocateViewsQueue(); diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api index 81dc01048c7a..59a744a0be9e 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api @@ -1244,6 +1244,7 @@ class facebook::react::FabricMountingManager { public bool isViewAllocated(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag); public void captureViewSnapshot(facebook::react::Tag tag, facebook::react::SurfaceId surfaceId); public void clearPendingSnapshots(); + public void clearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag viewTag, const std::vector& propNames); public void destroyUnmountedShadowNode(const facebook::react::ShadowNodeFamily& family); public void dispatchCommand(const facebook::react::ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args); public void drainPreallocateViewsQueue(); diff --git a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api index 81ca4add275f..094721600b99 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api @@ -2170,6 +2170,7 @@ protocol NativeAnimatedModuleSpec : public NSObjectRCTBridgeModule, public RCTTu public virtual void flattenAnimatedNodeOffset:(double nodeTag); public virtual void getValue:saveValueCallback:(double tag, RCTResponseSenderBlock saveValueCallback); public virtual void queueAndExecuteBatchedOperations:(NSArray* operationsAndArgs); + public virtual void releaseAnimatedProps:props:(NSDictionary* shadowNode, NSDictionary* props); public virtual void removeAnimatedEventFromView:eventName:animatedNodeTag:(double viewTag, NSString* eventName, double animatedNodeTag); public virtual void removeListeners:(double count); public virtual void restoreDefaultValues:(double nodeTag); diff --git a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api index bbf618bbd290..2763361d8a33 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api @@ -2228,6 +2228,7 @@ protocol NativeAnimatedModuleSpec : public NSObjectRCTBridgeModule, public RCTTu public virtual void flattenAnimatedNodeOffset:(double nodeTag); public virtual void getValue:saveValueCallback:(double tag, RCTResponseSenderBlock saveValueCallback); public virtual void queueAndExecuteBatchedOperations:(NSArray* operationsAndArgs); + public virtual void releaseAnimatedProps:props:(NSDictionary* shadowNode, NSDictionary* props); public virtual void removeAnimatedEventFromView:eventName:animatedNodeTag:(double viewTag, NSString* eventName, double animatedNodeTag); public virtual void removeListeners:(double count); public virtual void restoreDefaultValues:(double nodeTag); @@ -3815,6 +3816,7 @@ class facebook::react::AnimatedModule : public facebook::react::NativeAnimatedMo public void flattenAnimatedNodeOffset(facebook::jsi::Runtime& rt, facebook::react::Tag nodeTag); public void getValue(facebook::jsi::Runtime& rt, facebook::react::Tag tag, facebook::react::AsyncCallback saveValueCallback); public void queueAndExecuteBatchedOperations(facebook::jsi::Runtime& rt, facebook::jsi::Array operationsAndArgs); + public void releaseAnimatedProps(facebook::jsi::Runtime& rt, facebook::jsi::Object shadowNode, facebook::jsi::Object props); public void removeAnimatedEventFromView(facebook::jsi::Runtime& rt, facebook::react::Tag viewTag, std::string eventName, facebook::react::Tag animatedNodeTag); public void removeListeners(facebook::jsi::Runtime& rt, int count); public void restoreDefaultValues(facebook::jsi::Runtime& rt, facebook::react::Tag nodeTag); @@ -3862,9 +3864,11 @@ class facebook::react::AnimationBackend : public facebook::react::UIManagerAnima public virtual facebook::react::CallbackId start(const facebook::react::UIManagerAnimationBackend::Callback& callback) override; public virtual void clearRegistry(facebook::react::SurfaceId surfaceId) override; public virtual void clearRegistryOnSurfaceStop(facebook::react::SurfaceId surfaceId) override; + public virtual void onAnimatedNodeDisconnected(const std::shared_ptr& family) override; public virtual void onAnimationFrame(facebook::react::AnimationTimestamp timestamp) override; public virtual void pushAnimationMutations(const facebook::react::UIManagerAnimationBackend::Callback& callback) override; public virtual void registerJSInvoker(std::shared_ptr jsInvoker) override; + public virtual void releaseAnimatedProps(const std::shared_ptr& family, const folly::dynamic& props) override; public virtual void stop(facebook::react::CallbackId callbackId) override; public virtual void trigger() override; public void requestAsyncFlushForSurfaces(const std::set& surfaces); @@ -5073,6 +5077,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr public void insertMutations(std::unordered_map>& updates, facebook::react::AnimationMutations& mutations, facebook::react::AnimatedPropsBuilder& propsBuilder, bool hasLayoutUpdates = false); public void onManagedPropsRemoved(facebook::react::Tag tag) noexcept; public void onRender(); + public void releaseAnimatedProps(const std::shared_ptr& family, const folly::dynamic& props) noexcept; public void removeAnimatedEventFromView(facebook::react::Tag viewTag, const std::string& eventName, facebook::react::Tag animatedValueTag) noexcept; public void resolvePlatformColor(facebook::react::SurfaceId surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result) const; public void restoreDefaultValues(facebook::react::Tag tag) noexcept; @@ -5729,6 +5734,7 @@ class facebook::react::Scheduler : public facebook::react::UIManagerDelegate { public virtual void uiManagerDidUpdateShadowTree(const std::unordered_map& tagToProps) override; public virtual void uiManagerShouldAddEventListener(std::shared_ptr listener) final; public virtual void uiManagerShouldAddOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback) override; + public virtual void uiManagerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag, const std::vector& propNames) override; public virtual void uiManagerShouldRemoveEventListener(const std::shared_ptr& listener) final; public virtual void uiManagerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates) override; public virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props) override; @@ -5752,6 +5758,7 @@ class facebook::react::SchedulerDelegate { public virtual void schedulerDidSetIsJSResponder(const facebook::react::ShadowView& shadowView, bool isJSResponder, bool blockNativeResponder) = 0; public virtual void schedulerDidSetViewSnapshot(facebook::react::Tag sourceTag, facebook::react::Tag targetTag, facebook::react::SurfaceId surfaceId) = 0; public virtual void schedulerDidUpdateShadowTree(const std::unordered_map& tagToProps) = 0; + public virtual void schedulerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId, facebook::react::Tag, const std::vector&); public virtual void schedulerShouldMergeReactRevision(facebook::react::SurfaceId surfaceId) = 0; public virtual void schedulerShouldRenderTransactions(const std::shared_ptr& mountingCoordinator) = 0; public virtual void schedulerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates); @@ -6368,6 +6375,7 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate { public void addOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback); public void animationTick() const; public void appendChild(const std::shared_ptr& parentShadowNode, const std::shared_ptr& childShadowNode) const; + public void clearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag, const std::vector& propNames); public void completeSurface(facebook::react::SurfaceId surfaceId, const std::shared_ptr>>& rootChildren, facebook::react::ShadowTree::CommitOptions commitOptions); public void dispatchCommand(const std::shared_ptr& shadowNode, const std::string& commandName, const folly::dynamic& args) const; public void registerCommitHook(facebook::react::UIManagerCommitHook& commitHook); @@ -6400,9 +6408,11 @@ class facebook::react::UIManagerAnimationBackend { public virtual facebook::react::CallbackId start(const facebook::react::UIManagerAnimationBackend::Callback& callback) = 0; public virtual void clearRegistry(facebook::react::SurfaceId surfaceId) = 0; public virtual void clearRegistryOnSurfaceStop(facebook::react::SurfaceId surfaceId) = 0; + public virtual void onAnimatedNodeDisconnected(const std::shared_ptr&); public virtual void onAnimationFrame(facebook::react::AnimationTimestamp timestamp) = 0; public virtual void pushAnimationMutations(const facebook::react::UIManagerAnimationBackend::Callback& callback) = 0; public virtual void registerJSInvoker(std::shared_ptr jsInvoker) = 0; + public virtual void releaseAnimatedProps(const std::shared_ptr&, const folly::dynamic&); public virtual void stop(facebook::react::CallbackId callbackId) = 0; public virtual void trigger() = 0; public virtual ~UIManagerAnimationBackend() = default; @@ -6452,6 +6462,7 @@ class facebook::react::UIManagerDelegate { public virtual void uiManagerDidUpdateShadowTree(const std::unordered_map& tagToProps) = 0; public virtual void uiManagerShouldAddEventListener(std::shared_ptr listener) = 0; public virtual void uiManagerShouldAddOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback) = 0; + public virtual void uiManagerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId, facebook::react::Tag, const std::vector&); public virtual void uiManagerShouldRemoveEventListener(const std::shared_ptr& listener) = 0; public virtual void uiManagerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates) = 0; public virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props) = 0; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api index 7fc171e2fbea..63aab692eb1f 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api @@ -2163,6 +2163,7 @@ protocol NativeAnimatedModuleSpec : public NSObjectRCTBridgeModule, public RCTTu public virtual void flattenAnimatedNodeOffset:(double nodeTag); public virtual void getValue:saveValueCallback:(double tag, RCTResponseSenderBlock saveValueCallback); public virtual void queueAndExecuteBatchedOperations:(NSArray* operationsAndArgs); + public virtual void releaseAnimatedProps:props:(NSDictionary* shadowNode, NSDictionary* props); public virtual void removeAnimatedEventFromView:eventName:animatedNodeTag:(double viewTag, NSString* eventName, double animatedNodeTag); public virtual void removeListeners:(double count); public virtual void restoreDefaultValues:(double nodeTag); diff --git a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api index 1f2a23ed55dd..f1787e48370c 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api @@ -2170,6 +2170,7 @@ protocol NativeAnimatedModuleSpec : public NSObjectRCTBridgeModule, public RCTTu public virtual void flattenAnimatedNodeOffset:(double nodeTag); public virtual void getValue:saveValueCallback:(double tag, RCTResponseSenderBlock saveValueCallback); public virtual void queueAndExecuteBatchedOperations:(NSArray* operationsAndArgs); + public virtual void releaseAnimatedProps:props:(NSDictionary* shadowNode, NSDictionary* props); public virtual void removeAnimatedEventFromView:eventName:animatedNodeTag:(double viewTag, NSString* eventName, double animatedNodeTag); public virtual void removeListeners:(double count); public virtual void restoreDefaultValues:(double nodeTag); diff --git a/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api index 03a6c75b75a3..389b2c2f9740 100644 --- a/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactCommonFrameworksCxx.api @@ -602,6 +602,7 @@ class facebook::react::AnimatedModule : public NativeAnimatedModuleCxxSpec saveValueCallback); public void queueAndExecuteBatchedOperations(facebook::jsi::Runtime& rt, facebook::jsi::Array operationsAndArgs); + public void releaseAnimatedProps(facebook::jsi::Runtime& rt, facebook::jsi::Object shadowNode, facebook::jsi::Object props); public void removeAnimatedEventFromView(facebook::jsi::Runtime& rt, facebook::react::Tag viewTag, std::string eventName, facebook::react::Tag animatedNodeTag); public void removeListeners(facebook::jsi::Runtime& rt, int count); public void restoreDefaultValues(facebook::jsi::Runtime& rt, facebook::react::Tag nodeTag); @@ -649,9 +650,11 @@ class facebook::react::AnimationBackend : public facebook::react::UIManagerAnima public virtual facebook::react::CallbackId start(const facebook::react::UIManagerAnimationBackend::Callback& callback) override; public virtual void clearRegistry(facebook::react::SurfaceId surfaceId) override; public virtual void clearRegistryOnSurfaceStop(facebook::react::SurfaceId surfaceId) override; + public virtual void onAnimatedNodeDisconnected(const std::shared_ptr& family) override; public virtual void onAnimationFrame(facebook::react::AnimationTimestamp timestamp) override; public virtual void pushAnimationMutations(const facebook::react::UIManagerAnimationBackend::Callback& callback) override; public virtual void registerJSInvoker(std::shared_ptr jsInvoker) override; + public virtual void releaseAnimatedProps(const std::shared_ptr& family, const folly::dynamic& props) override; public virtual void stop(facebook::react::CallbackId callbackId) override; public virtual void trigger() override; public void requestAsyncFlushForSurfaces(const std::set& surfaces); @@ -1729,6 +1732,7 @@ class facebook::react::NativeAnimatedNodesManager : public std::enable_shared_fr public void insertMutations(std::unordered_map>& updates, facebook::react::AnimationMutations& mutations, facebook::react::AnimatedPropsBuilder& propsBuilder, bool hasLayoutUpdates = false); public void onManagedPropsRemoved(facebook::react::Tag tag) noexcept; public void onRender(); + public void releaseAnimatedProps(const std::shared_ptr& family, const folly::dynamic& props) noexcept; public void removeAnimatedEventFromView(facebook::react::Tag viewTag, const std::string& eventName, facebook::react::Tag animatedValueTag) noexcept; public void resolvePlatformColor(facebook::react::SurfaceId surfaceId, const facebook::react::RawValue& value, facebook::react::SharedColor& result) const; public void restoreDefaultValues(facebook::react::Tag tag) noexcept; @@ -2133,6 +2137,7 @@ class facebook::react::Scheduler : public facebook::react::UIManagerDelegate { public virtual void uiManagerDidUpdateShadowTree(const std::unordered_map& tagToProps) override; public virtual void uiManagerShouldAddEventListener(std::shared_ptr listener) final; public virtual void uiManagerShouldAddOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback) override; + public virtual void uiManagerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag, const std::vector& propNames) override; public virtual void uiManagerShouldRemoveEventListener(const std::shared_ptr& listener) final; public virtual void uiManagerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates) override; public virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props) override; @@ -2156,6 +2161,7 @@ class facebook::react::SchedulerDelegate { public virtual void schedulerDidSetIsJSResponder(const facebook::react::ShadowView& shadowView, bool isJSResponder, bool blockNativeResponder) = 0; public virtual void schedulerDidSetViewSnapshot(facebook::react::Tag sourceTag, facebook::react::Tag targetTag, facebook::react::SurfaceId surfaceId) = 0; public virtual void schedulerDidUpdateShadowTree(const std::unordered_map& tagToProps) = 0; + public virtual void schedulerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId, facebook::react::Tag, const std::vector&); public virtual void schedulerShouldMergeReactRevision(facebook::react::SurfaceId surfaceId) = 0; public virtual void schedulerShouldRenderTransactions(const std::shared_ptr& mountingCoordinator) = 0; public virtual void schedulerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates); @@ -2693,6 +2699,7 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate { public void addOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback); public void animationTick() const; public void appendChild(const std::shared_ptr& parentShadowNode, const std::shared_ptr& childShadowNode) const; + public void clearSynchronousMountPropsOverride(facebook::react::SurfaceId surfaceId, facebook::react::Tag tag, const std::vector& propNames); public void completeSurface(facebook::react::SurfaceId surfaceId, const std::shared_ptr>>& rootChildren, facebook::react::ShadowTree::CommitOptions commitOptions); public void dispatchCommand(const std::shared_ptr& shadowNode, const std::string& commandName, const folly::dynamic& args) const; public void registerCommitHook(facebook::react::UIManagerCommitHook& commitHook); @@ -2725,9 +2732,11 @@ class facebook::react::UIManagerAnimationBackend { public virtual facebook::react::CallbackId start(const facebook::react::UIManagerAnimationBackend::Callback& callback) = 0; public virtual void clearRegistry(facebook::react::SurfaceId surfaceId) = 0; public virtual void clearRegistryOnSurfaceStop(facebook::react::SurfaceId surfaceId) = 0; + public virtual void onAnimatedNodeDisconnected(const std::shared_ptr&); public virtual void onAnimationFrame(facebook::react::AnimationTimestamp timestamp) = 0; public virtual void pushAnimationMutations(const facebook::react::UIManagerAnimationBackend::Callback& callback) = 0; public virtual void registerJSInvoker(std::shared_ptr jsInvoker) = 0; + public virtual void releaseAnimatedProps(const std::shared_ptr&, const folly::dynamic&); public virtual void stop(facebook::react::CallbackId callbackId) = 0; public virtual void trigger() = 0; public virtual ~UIManagerAnimationBackend() = default; @@ -2777,6 +2786,7 @@ class facebook::react::UIManagerDelegate { public virtual void uiManagerDidUpdateShadowTree(const std::unordered_map& tagToProps) = 0; public virtual void uiManagerShouldAddEventListener(std::shared_ptr listener) = 0; public virtual void uiManagerShouldAddOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback) = 0; + public virtual void uiManagerShouldClearSynchronousMountPropsOverride(facebook::react::SurfaceId, facebook::react::Tag, const std::vector&); public virtual void uiManagerShouldRemoveEventListener(const std::shared_ptr& listener) = 0; public virtual void uiManagerShouldSynchronouslyUpdateAnimatedProps(const std::unordered_map& updates) = 0; public virtual void uiManagerShouldSynchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props) = 0;