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..ba97db3af280 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 @@ -22,6 +22,7 @@ import com.facebook.react.bridge.WritableMap import com.facebook.react.fabric.events.EventEmitterWrapper import com.facebook.react.fabric.mounting.mountitems.MountItem import com.facebook.react.touch.JSResponderHandler +import com.facebook.react.uimanager.AnimatedTransform import com.facebook.react.uimanager.RootViewManager import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.ViewManagerRegistry @@ -278,6 +279,19 @@ internal class MountingManager( return true } + /** See [SurfaceMountingManager.updateAnimatedPropsTyped]. */ + @UiThread + fun updateAnimatedPropsTyped( + reactTag: Int, + hasOpacity: Boolean, + opacity: Double, + transform: AnimatedTransform?, + ): Boolean { + assertOnUiThread() + val surfaceMountingManager = getSurfaceManagerForView(reactTag) ?: return false + return surfaceMountingManager.updateAnimatedPropsTyped(reactTag, hasOpacity, opacity, transform) + } + @UiThread fun updatePropsSynchronously(reactTag: Int, props: ReadableMap?) { assertOnUiThread() 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..9c8feaaaa182 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 @@ -39,6 +39,8 @@ import com.facebook.react.fabric.mounting.MountingManager.MountItemExecutor import com.facebook.react.fabric.mounting.mountitems.MountItem import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags import com.facebook.react.touch.JSResponderHandler +import com.facebook.react.uimanager.AnimatedPropsApplier +import com.facebook.react.uimanager.AnimatedTransform import com.facebook.react.uimanager.IViewGroupManager import com.facebook.react.uimanager.IllegalViewOperationException import com.facebook.react.uimanager.ReactOverflowViewWithInset @@ -118,6 +120,18 @@ internal constructor( @ThreadConfined(ThreadConfined.UI) private val tagToSynchronousMountProps = SparseArrayCompat>() + // Overrides from the typed animated props path, kept typed until a React update needs them as + // props. Folded into [tagToSynchronousMountProps] by [flushTypedAnimatedOverride]. + @ThreadConfined(ThreadConfined.UI) + private val tagToTypedAnimatedOverride = SparseArrayCompat() + + private class TypedAnimatedOverride { + var hasOpacity: Boolean = false + var opacity: Double = 0.0 + var hasTransform: Boolean = false + val transform: AnimatedTransform = AnimatedTransform() + } + @AnyThread public fun attachRootView(rootView: View, themedReactContext: ThemedReactContext) { this.context = themedReactContext @@ -283,6 +297,7 @@ internal constructor( context = null onViewAttachMountItems.clear() tagToSynchronousMountProps.clear() + tagToTypedAnimatedOverride.clear() FLog.e(TAG, "Surface [$surfaceId] was stopped on SurfaceMountingManager.") } @@ -622,6 +637,7 @@ internal constructor( public fun storeSynchronousMountPropsOverride(reactTag: Int, props: ReadableMap) { if (ReactNativeFeatureFlags.overrideBySynchronousMountPropsAtMountingAndroid()) { + flushTypedAnimatedOverride(reactTag) val propsMap = getAnimatedPropsMap(props) val synchronousMountProps = tagToSynchronousMountProps[reactTag] ?: mutableMapOf() clearAnimatedNullPropsMapKeys(props, synchronousMountProps) @@ -638,6 +654,66 @@ internal constructor( updateProps(reactTag, props, true) } + /** + * Typed counterpart of [storeSynchronousMountPropsOverride] plus [updatePropsSynchronously] for + * opacity and transform ([transform] null when absent). Returns false when this view isn't + * covered by [AnimatedPropsApplier], so the caller can use the props map path instead. + * + * Unlike the map path, this leaves [ViewState.currentProps] as the last committed props instead + * of replacing them with the animated subset. Covered view managers don't read them in + * `updateState`. + */ + @UiThread + internal fun updateAnimatedPropsTyped( + reactTag: Int, + hasOpacity: Boolean, + opacity: Double, + transform: AnimatedTransform?, + ): Boolean { + if (isStopped) { + return false + } + val viewState = getNullableViewState(reactTag) ?: return false + val view = viewState.view ?: return false + val viewManager = viewState.viewManager ?: return false + if (!AnimatedPropsApplier.supports(viewManager)) { + return false + } + if (!hasOpacity && transform == null) { + return true + } + if (ReactNativeFeatureFlags.overrideBySynchronousMountPropsAtMountingAndroid()) { + val override = + tagToTypedAnimatedOverride[reactTag] + ?: TypedAnimatedOverride().also { tagToTypedAnimatedOverride.put(reactTag, it) } + if (hasOpacity) { + override.hasOpacity = true + override.opacity = opacity + } + if (transform != null) { + override.transform.copyFrom(transform) + override.hasTransform = true + } + } + AnimatedPropsApplier.apply(viewManager, view, hasOpacity, opacity, transform) + return true + } + + /** Moves a typed override into [tagToSynchronousMountProps], after any older map overrides. */ + private fun flushTypedAnimatedOverride(reactTag: Int) { + val override = tagToTypedAnimatedOverride[reactTag] ?: return + tagToTypedAnimatedOverride.remove(reactTag) + val props = + tagToSynchronousMountProps[reactTag] + ?: mutableMapOf().also { tagToSynchronousMountProps.put(reactTag, it) } + if (override.hasOpacity) { + props[PROP_OPACITY] = override.opacity + } + if (override.hasTransform) { + props[PROP_TRANSFORM] = override.transform.toPropsList() + } + } + public fun updateProps(reactTag: Int, props: ReadableMap) { updateProps(reactTag, props, false) } @@ -661,6 +737,12 @@ internal constructor( return } + if ( + ReactNativeFeatureFlags.overrideBySynchronousMountPropsAtMountingAndroid() && + !shouldSkipSynchronousMountPropsOverride + ) { + flushTypedAnimatedOverride(reactTag) + } if ( ReactNativeFeatureFlags.overrideBySynchronousMountPropsAtMountingAndroid() && !shouldSkipSynchronousMountPropsOverride && @@ -1071,11 +1153,9 @@ internal constructor( return } - if ( - ReactNativeFeatureFlags.overrideBySynchronousMountPropsAtMountingAndroid() && - tagToSynchronousMountProps.containsKey(reactTag) - ) { + if (ReactNativeFeatureFlags.overrideBySynchronousMountPropsAtMountingAndroid()) { tagToSynchronousMountProps.remove(reactTag) + tagToTypedAnimatedOverride.remove(reactTag) } val viewState = getNullableViewState(reactTag) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchedAnimatedPropsMountItem.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchedAnimatedPropsMountItem.kt index 21807a3ade44..a02cece6beaf 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchedAnimatedPropsMountItem.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/BatchedAnimatedPropsMountItem.kt @@ -14,8 +14,21 @@ import com.facebook.react.bridge.ReadableMap import com.facebook.react.fabric.FabricUIManager.IS_DEVELOPMENT_ENVIRONMENT import com.facebook.react.fabric.mounting.MountItemDispatcher import com.facebook.react.fabric.mounting.MountingManager +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags +import com.facebook.react.uimanager.AnimatedTransform import com.facebook.react.uimanager.ViewProps +/** Applies a view's typed animated props. Primitive parameters, so a call doesn't box. */ +internal fun interface TypedAnimatedPropsApplier { + /** Returns false when the caller should apply the view's props through the props map path. */ + fun apply( + viewTag: Int, + hasOpacity: Boolean, + opacity: Double, + transform: AnimatedTransform?, + ): Boolean +} + internal class BatchedAnimatedPropsMountItem( private val intBuffer: IntArray, private val doubleBuffer: DoubleArray, @@ -23,8 +36,30 @@ internal class BatchedAnimatedPropsMountItem( private val mountItemDispatcher: MountItemDispatcher, ) : MountItem { + // Result of the last successful [scanTyped]. + private var scannedIntEnd = 0 + private var scannedDoubleEnd = 0 + private var scannedHasOpacity = false + private var scannedOpacity = 0.0 + private var scannedHasTransform = false + private val scannedTransform = AnimatedTransform() + override fun execute(mountingManager: MountingManager) { - decode { viewTag, props -> + val typedApplier = + if (ReactNativeFeatureFlags.enableTypedAnimatedPropsAndroid()) { + TypedAnimatedPropsApplier { viewTag, hasOpacity, opacity, transform -> + try { + mountingManager.updateAnimatedPropsTyped(viewTag, hasOpacity, opacity, transform) + } catch (ex: Exception) { + // Match SynchronousMountItem's handling of view-manager failures. Report the view as + // handled: it may be partly updated, so applying it again through props is no better. + true + } + } + } else { + null + } + decode(typedApplier) { viewTag, props -> try { if (!mountingManager.updateAnimatedPropsSynchronously(viewTag, props)) { mountItemDispatcher.addMountItem(SynchronousMountItem(viewTag, props)) @@ -35,7 +70,74 @@ internal class BatchedAnimatedPropsMountItem( } } + /** + * Reads one view, starting after its tag, when its commands are only opacity and plain number + * transform operations. Returns false, without consuming anything, when the view has any other + * command, so the caller decodes it as props. + * + * Views whose manager the typed path doesn't cover are scanned and then decoded as props; the + * scan only reads the buffers. + */ + private fun scanTyped(intStart: Int, doubleStart: Int): Boolean { + var intIdx = intStart + var doubleIdx = doubleStart + scannedHasOpacity = false + scannedHasTransform = false + while (true) { + when (intBuffer[intIdx++]) { + CMD_END_OF_VIEW -> break + CMD_OPACITY -> { + scannedHasOpacity = true + scannedOpacity = doubleBuffer[doubleIdx++] + } + CMD_START_OF_TRANSFORM -> { + // A later transform replaces an earlier one, as it does in the props map. + scannedHasTransform = true + scannedTransform.clear() + while (true) { + val transformCmd = intBuffer[intIdx++] + if (transformCmd == CMD_END_OF_TRANSFORM) { + break + } + val op = + when (transformCmd) { + CMD_TRANSLATE_X, + CMD_TRANSLATE_Y -> { + if (intBuffer[intIdx++] != CMD_UNIT_PX) { + return false + } + if (transformCmd == CMD_TRANSLATE_X) AnimatedTransform.TRANSLATE_X + else AnimatedTransform.TRANSLATE_Y + } + CMD_SCALE -> AnimatedTransform.SCALE + CMD_SCALE_X -> AnimatedTransform.SCALE_X + CMD_SCALE_Y -> AnimatedTransform.SCALE_Y + CMD_ROTATE -> AnimatedTransform.ROTATE + CMD_ROTATE_X -> AnimatedTransform.ROTATE_X + CMD_ROTATE_Y -> AnimatedTransform.ROTATE_Y + CMD_ROTATE_Z -> AnimatedTransform.ROTATE_Z + CMD_PERSPECTIVE -> AnimatedTransform.PERSPECTIVE + else -> return false + } + scannedTransform.add(op, doubleBuffer[doubleIdx++]) + } + } + else -> return false + } + } + scannedIntEnd = intIdx + scannedDoubleEnd = doubleIdx + return true + } + internal fun decode(apply: (Int, ReadableMap) -> Unit) { + decode(null, apply) + } + + internal fun decode( + typedApplier: TypedAnimatedPropsApplier?, + apply: (Int, ReadableMap) -> Unit, + ) { var intIdx = 0 var doubleIdx = 0 var rawIdx = 0 @@ -51,6 +153,21 @@ internal class BatchedAnimatedPropsMountItem( continue } + if ( + typedApplier != null && + scanTyped(intIdx, doubleIdx) && + typedApplier.apply( + viewTag, + scannedHasOpacity, + scannedOpacity, + if (scannedHasTransform) scannedTransform else null, + ) + ) { + intIdx = scannedIntEnd + doubleIdx = scannedDoubleEnd + continue + } + val props = JavaOnlyMap() while (true) { val cmd = intBuffer[intIdx++] diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt index 24277871afb6..4484a048b327 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<9a675a67a9ce5e7ca443dd319e2af91a>> + * @generated SignedSource<<22f95267d83e97d88852287061a6df4f>> */ /** @@ -354,6 +354,12 @@ public object ReactNativeFeatureFlags { @JvmStatic public fun enableSwiftUIBasedFilters(): Boolean = accessor.enableSwiftUIBasedFilters() + /** + * Applies opacity and transform updates from the shared animation backend to Android views through typed setters, instead of building a props map and dispatching through the generic ViewManager setters on every frame. + */ + @JvmStatic + public fun enableTypedAnimatedPropsAndroid(): Boolean = accessor.enableTypedAnimatedPropsAndroid() + /** * Enables View Culling: as soon as a view goes off screen, it can be reused anywhere in the UI and pieced together with other items to create new UI elements. */ diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt index 7c30f96a71bf..fb25a996e138 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<6b668cbb1ef60126d7e08b2d853b1262>> + * @generated SignedSource<> */ /** @@ -74,6 +74,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces private var enablePropsUpdateReconciliationAndroidCache: Boolean? = null private var enableResizeObserverByDefaultCache: Boolean? = null private var enableSwiftUIBasedFiltersCache: Boolean? = null + private var enableTypedAnimatedPropsAndroidCache: Boolean? = null private var enableViewCullingCache: Boolean? = null private var enableViewRecyclingCache: Boolean? = null private var enableViewRecyclingForImageCache: Boolean? = null @@ -610,6 +611,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces return cached } + override fun enableTypedAnimatedPropsAndroid(): Boolean { + var cached = enableTypedAnimatedPropsAndroidCache + if (cached == null) { + cached = ReactNativeFeatureFlagsCxxInterop.enableTypedAnimatedPropsAndroid() + enableTypedAnimatedPropsAndroidCache = cached + } + return cached + } + override fun enableViewCulling(): Boolean { var cached = enableViewCullingCache if (cached == null) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt index 03bba689ab05..6f0145c1edf1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<0890a0b7979d00172b0a79abd94f6c3e>> + * @generated SignedSource<<3f593d5418d172954b56dfe92bb2f77e>> */ /** @@ -136,6 +136,8 @@ public object ReactNativeFeatureFlagsCxxInterop { @DoNotStrip @JvmStatic public external fun enableSwiftUIBasedFilters(): Boolean + @DoNotStrip @JvmStatic public external fun enableTypedAnimatedPropsAndroid(): Boolean + @DoNotStrip @JvmStatic public external fun enableViewCulling(): Boolean @DoNotStrip @JvmStatic public external fun enableViewRecycling(): Boolean diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt index 73e4a521e946..bacb0c34ce3d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<3ca183dbeeb3fdeac98780267df9dff2>> + * @generated SignedSource<> */ /** @@ -131,6 +131,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi override fun enableSwiftUIBasedFilters(): Boolean = false + override fun enableTypedAnimatedPropsAndroid(): Boolean = false + override fun enableViewCulling(): Boolean = false override fun enableViewRecycling(): Boolean = false diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt index 9dd027c0ffe9..65f24e3cc69b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<> */ /** @@ -78,6 +78,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc private var enablePropsUpdateReconciliationAndroidCache: Boolean? = null private var enableResizeObserverByDefaultCache: Boolean? = null private var enableSwiftUIBasedFiltersCache: Boolean? = null + private var enableTypedAnimatedPropsAndroidCache: Boolean? = null private var enableViewCullingCache: Boolean? = null private var enableViewRecyclingCache: Boolean? = null private var enableViewRecyclingForImageCache: Boolean? = null @@ -668,6 +669,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc return cached } + override fun enableTypedAnimatedPropsAndroid(): Boolean { + var cached = enableTypedAnimatedPropsAndroidCache + if (cached == null) { + cached = currentProvider.enableTypedAnimatedPropsAndroid() + accessedFeatureFlags.add("enableTypedAnimatedPropsAndroid") + enableTypedAnimatedPropsAndroidCache = cached + } + return cached + } + override fun enableViewCulling(): Boolean { var cached = enableViewCullingCache if (cached == null) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt index 70cde8f01bef..c5f70245f186 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<8d21b1b7d2bd5c5fe3a111c0d411f742>> + * @generated SignedSource<> */ /** @@ -131,6 +131,8 @@ public interface ReactNativeFeatureFlagsProvider { @DoNotStrip public fun enableSwiftUIBasedFilters(): Boolean + @DoNotStrip public fun enableTypedAnimatedPropsAndroid(): Boolean + @DoNotStrip public fun enableViewCulling(): Boolean @DoNotStrip public fun enableViewRecycling(): Boolean diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/AnimatedPropsApplier.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/AnimatedPropsApplier.kt new file mode 100644 index 000000000000..8031d8575329 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/AnimatedPropsApplier.kt @@ -0,0 +1,54 @@ +/* + * 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.uimanager + +import android.view.View +import com.facebook.react.views.view.ReactViewGroup +import com.facebook.react.views.view.ReactViewManager + +/** + * Applies opacity and transform from the shared animation backend through typed setters (see + * [BaseViewManager.applyAnimatedProps]), for the view managers whose handling of those props is + * known to match the props path. + */ +internal object AnimatedPropsApplier { + + /** + * Whether [apply] covers views of this manager: only the core `View` manager, not its subclasses. + * Before adding a manager, check that: + * - its `updateState` doesn't read props, since the typed path leaves `ViewState.currentProps` as + * the last committed props instead of replacing them with the animated subset; + * - any extra work in its `setOpacity` or `setTransformProperty` overrides also happens here, + * like [onTransformApplied] does for `View`. + */ + fun supports(viewManager: ViewManager<*, *>): Boolean = + viewManager.javaClass == ReactViewManager::class.java + + /** Applies the props to a view of a manager that [supports] covers. */ + fun apply( + viewManager: ViewManager<*, *>, + view: View, + hasOpacity: Boolean, + opacity: Double, + transform: AnimatedTransform?, + ) { + @Suppress("UNCHECKED_CAST") + (viewManager as BaseViewManager).applyAnimatedProps( + view, + hasOpacity, + opacity, + transform, + ) + } + + /** Mirrors `ReactViewManager.setTransformProperty`, which updates backface-dependent opacity. */ + @JvmStatic + fun onTransformApplied(view: View) { + (view as? ReactViewGroup)?.setBackfaceVisibilityDependantOpacity() + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/AnimatedTransform.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/AnimatedTransform.kt new file mode 100644 index 000000000000..e361e7a3a780 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/AnimatedTransform.kt @@ -0,0 +1,143 @@ +/* + * 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.uimanager + +import com.facebook.react.bridge.ReadableArray + +/** + * A transform from the shared animation backend, kept as primitive operations instead of a + * `ReadableArray` of maps. Only operations with a plain number value are representable here: + * translations in pixels, scales, rotations in radians and perspective. Anything else (percentages, + * skews, matrices) goes through the generic `transform` prop. + * + * Instances are reused across frames by their owner, so callers copy with [copyFrom] instead of + * keeping references to a holder they don't own. + */ +internal class AnimatedTransform { + @JvmField var size: Int = 0 + @JvmField var ops: IntArray = IntArray(INITIAL_CAPACITY) + @JvmField var values: DoubleArray = DoubleArray(INITIAL_CAPACITY) + + fun clear() { + size = 0 + } + + fun add(op: Int, value: Double) { + if (size == ops.size) { + ops = ops.copyOf(size * 2) + values = values.copyOf(size * 2) + } + ops[size] = op + values[size] = value + size++ + } + + fun copyFrom(other: AnimatedTransform) { + if (ops.size < other.size) { + ops = IntArray(other.size) + values = DoubleArray(other.size) + } + other.ops.copyInto(ops, 0, 0, other.size) + other.values.copyInto(values, 0, 0, other.size) + size = other.size + } + + /** + * Writes the same matrix as [TransformHelper.processTransform] would for the equivalent + * `ReadableArray`, including the transform origin offsets. + */ + fun computeMatrix( + result: DoubleArray, + viewWidth: Float, + viewHeight: Float, + transformOrigin: ReadableArray?, + ) { + val helper = helperMatrix.get()!! + MatrixMathHelper.resetIdentityMatrix(result) + val offsets = + TransformHelper.getTranslateForTransformOrigin(viewWidth, viewHeight, transformOrigin) + if (offsets != null) { + MatrixMathHelper.resetIdentityMatrix(helper) + MatrixMathHelper.applyTranslate3D(helper, offsets[0], offsets[1], offsets[2]) + MatrixMathHelper.multiplyInto(result, result, helper) + } + for (i in 0 until size) { + val value = values[i] + MatrixMathHelper.resetIdentityMatrix(helper) + when (ops[i]) { + TRANSLATE_X -> MatrixMathHelper.applyTranslate2D(helper, value, 0.0) + TRANSLATE_Y -> MatrixMathHelper.applyTranslate2D(helper, 0.0, value) + SCALE -> { + MatrixMathHelper.applyScaleX(helper, value) + MatrixMathHelper.applyScaleY(helper, value) + } + SCALE_X -> MatrixMathHelper.applyScaleX(helper, value) + SCALE_Y -> MatrixMathHelper.applyScaleY(helper, value) + ROTATE, + ROTATE_Z -> MatrixMathHelper.applyRotateZ(helper, value) + ROTATE_X -> MatrixMathHelper.applyRotateX(helper, value) + ROTATE_Y -> MatrixMathHelper.applyRotateY(helper, value) + PERSPECTIVE -> MatrixMathHelper.applyPerspective(helper, value) + else -> error("Unknown animated transform op: ${ops[i]}") + } + MatrixMathHelper.multiplyInto(result, result, helper) + } + if (offsets != null) { + MatrixMathHelper.resetIdentityMatrix(helper) + MatrixMathHelper.applyTranslate3D(helper, -offsets[0], -offsets[1], -offsets[2]) + MatrixMathHelper.multiplyInto(result, result, helper) + } + } + + /** + * The value the generic path stores for a synchronous `transform` override: one single-key map + * per operation, matching `JavaOnlyMap.toHashMap()` of the decoded props. + */ + fun toPropsList(): ArrayList> { + val list = ArrayList>(size) + for (i in 0 until size) { + list.add(hashMapOf(opName(ops[i]) to values[i])) + } + return list + } + + companion object { + private const val INITIAL_CAPACITY = 4 + + const val TRANSLATE_X: Int = 0 + const val TRANSLATE_Y: Int = 1 + const val SCALE: Int = 2 + const val SCALE_X: Int = 3 + const val SCALE_Y: Int = 4 + const val ROTATE: Int = 5 + const val ROTATE_X: Int = 6 + const val ROTATE_Y: Int = 7 + const val ROTATE_Z: Int = 8 + const val PERSPECTIVE: Int = 9 + + private val helperMatrix: ThreadLocal = + object : ThreadLocal() { + override fun initialValue(): DoubleArray = DoubleArray(16) + } + + fun opName(op: Int): String = + when (op) { + TRANSLATE_X -> ViewProps.TRANSLATE_X + TRANSLATE_Y -> ViewProps.TRANSLATE_Y + SCALE -> "scale" + SCALE_X -> ViewProps.SCALE_X + SCALE_Y -> ViewProps.SCALE_Y + ROTATE -> "rotate" + ROTATE_X -> "rotateX" + ROTATE_Y -> "rotateY" + ROTATE_Z -> "rotateZ" + PERSPECTIVE -> "perspective" + else -> error("Unknown animated transform op: $op") + } + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java index 4a207c615047..49cdce441712 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -139,6 +139,7 @@ public BaseViewManager(@Nullable ReactApplicationContext reactContext) { view.setTag(R.id.transform, null); view.setTag(R.id.transform_origin, null); view.setTag(R.id.invalidate_transform, null); + view.setTag(R.id.animated_transform, null); view.removeOnLayoutChangeListener(this); view.setTag(R.id.use_hardware_layer, null); @@ -246,12 +247,12 @@ public void onLayoutChange( int currentHeight = bottom - top; if ((currentHeight != oldHeight || currentWidth != oldWidth)) { - ReadableArray transformOrigin = (ReadableArray) v.getTag(R.id.transform_origin); - ReadableArray transforms = (ReadableArray) v.getTag(R.id.transform); - if (transforms != null || transformOrigin != null) { + if (v.getTag(R.id.transform) != null + || v.getTag(R.id.transform_origin) != null + || v.getTag(R.id.animated_transform) != null) { @SuppressWarnings("unchecked") T typedView = (T) v; - setTransformProperty(typedView, transforms, transformOrigin); + reapplyTransform(typedView); } } } @@ -282,8 +283,11 @@ public void setMixBlendMode(@NonNull T view, @Nullable String mixBlendMode) { @ReactProp(name = ViewProps.TRANSFORM) public void setTransform(@NonNull T view, @Nullable ReadableArray matrix) { @Nullable ReadableArray currentTransform = (ReadableArray) view.getTag(R.id.transform); - if (!Objects.equals(currentTransform, matrix)) { + // While a typed animated transform is applied the raw tag is null, so any regular value, + // including null, replaces it. + if (!Objects.equals(currentTransform, matrix) || view.getTag(R.id.animated_transform) != null) { view.setTag(R.id.transform, matrix); + view.setTag(R.id.animated_transform, null); view.setTag(R.id.invalidate_transform, true); } } @@ -654,14 +658,74 @@ protected void setTransformProperty( return; } - sMatrixDecompositionContext.reset(); TransformHelper.processTransform( transforms, sTransformDecompositionArray, PixelUtil.toDIPFromPixel(view.getWidth()), PixelUtil.toDIPFromPixel(view.getHeight()), transformOrigin); - MatrixMathHelper.decomposeMatrix(sTransformDecompositionArray, sMatrixDecompositionContext); + applyTransformMatrix(view, sTransformDecompositionArray); + } + + /** + * Applies opacity and transform from the shared animation backend through typed setters, without + * a props map. Only called for managers that {@link AnimatedPropsApplier#supports} covers. + * + *

Unlike {@link #updateProperties}, this skips the rest of {@link #onAfterUpdateTransaction}: + * the accessibility delegate, filters and layer type don't depend on opacity or transform. + */ + void applyAnimatedProps( + @NonNull T view, boolean hasOpacity, double opacity, @Nullable AnimatedTransform transform) { + if (hasOpacity) { + setOpacity(view, (float) opacity); + } + if (transform != null) { + setAnimatedTransform(view, transform); + } + } + + /** + * Keeps a copy of the typed transform for layout changes and clears the raw transform tag, so the + * next regular transform prop always applies. {@link AnimatedTransform} has no skew operations, + * so there is no skew path. + */ + private void setAnimatedTransform(@NonNull T view, @NonNull AnimatedTransform transform) { + AnimatedTransform stored = (AnimatedTransform) view.getTag(R.id.animated_transform); + if (stored == null) { + stored = new AnimatedTransform(); + view.setTag(R.id.animated_transform, stored); + view.addOnLayoutChangeListener(this); + } + stored.copyFrom(transform); + view.setTag(R.id.transform, null); + view.setTag(R.id.invalidate_transform, false); + applyAnimatedTransform(view, stored); + } + + private void applyAnimatedTransform(@NonNull T view, @NonNull AnimatedTransform transform) { + transform.computeMatrix( + sTransformDecompositionArray, + PixelUtil.toDIPFromPixel(view.getWidth()), + PixelUtil.toDIPFromPixel(view.getHeight()), + (ReadableArray) view.getTag(R.id.transform_origin)); + applyTransformMatrix(view, sTransformDecompositionArray); + AnimatedPropsApplier.onTransformApplied(view); + } + + /** Applies the current transform: the typed animated one while it is active, else the prop. */ + private void reapplyTransform(@NonNull T view) { + ReadableArray transforms = (ReadableArray) view.getTag(R.id.transform); + AnimatedTransform animatedTransform = (AnimatedTransform) view.getTag(R.id.animated_transform); + if (transforms == null && animatedTransform != null) { + applyAnimatedTransform(view, animatedTransform); + } else { + setTransformProperty(view, transforms, (ReadableArray) view.getTag(R.id.transform_origin)); + } + } + + private void applyTransformMatrix(@NonNull T view, double[] matrix) { + sMatrixDecompositionContext.reset(); + MatrixMathHelper.decomposeMatrix(matrix, sMatrixDecompositionContext); view.setTranslationX( PixelUtil.toPixelFromDIP( sanitizeFloatPropertyValue((float) sMatrixDecompositionContext.translation[0]))); @@ -730,9 +794,7 @@ protected void onAfterUpdateTransaction(@NonNull T view) { Boolean invalidateTransform = (Boolean) view.getTag(R.id.invalidate_transform); if (invalidateTransform != null && invalidateTransform) { view.addOnLayoutChangeListener(this); - ReadableArray transformOrigin = (ReadableArray) view.getTag(R.id.transform_origin); - ReadableArray transforms = (ReadableArray) view.getTag(R.id.transform); - setTransformProperty(view, transforms, transformOrigin); + reapplyTransform(view); view.setTag(R.id.invalidate_transform, false); } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/TransformHelper.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/TransformHelper.kt index 62720a34a8c8..2f9bcce720ea 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/TransformHelper.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/TransformHelper.kt @@ -203,7 +203,7 @@ public object TransformHelper { } } - private fun getTranslateForTransformOrigin( + internal fun getTranslateForTransformOrigin( viewWidth: Float, viewHeight: Float, transformOrigin: ReadableArray?, diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp index f1eff8d3e833..e62a529f2077 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<> */ /** @@ -363,6 +363,12 @@ class ReactNativeFeatureFlagsJavaProvider return method(javaProvider_); } + bool enableTypedAnimatedPropsAndroid() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableTypedAnimatedPropsAndroid"); + return method(javaProvider_); + } + bool enableViewCulling() override { static const auto method = getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableViewCulling"); @@ -931,6 +937,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableSwiftUIBasedFilters( return ReactNativeFeatureFlags::enableSwiftUIBasedFilters(); } +bool JReactNativeFeatureFlagsCxxInterop::enableTypedAnimatedPropsAndroid( + facebook::jni::alias_ref /*unused*/) { + return ReactNativeFeatureFlags::enableTypedAnimatedPropsAndroid(); +} + bool JReactNativeFeatureFlagsCxxInterop::enableViewCulling( facebook::jni::alias_ref /*unused*/) { return ReactNativeFeatureFlags::enableViewCulling(); @@ -1369,6 +1380,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() { makeNativeMethod( "enableSwiftUIBasedFilters", JReactNativeFeatureFlagsCxxInterop::enableSwiftUIBasedFilters), + makeNativeMethod( + "enableTypedAnimatedPropsAndroid", + JReactNativeFeatureFlagsCxxInterop::enableTypedAnimatedPropsAndroid), makeNativeMethod( "enableViewCulling", JReactNativeFeatureFlagsCxxInterop::enableViewCulling), diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h index aecc722b136d..19b831e73614 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<> */ /** @@ -192,6 +192,9 @@ class JReactNativeFeatureFlagsCxxInterop static bool enableSwiftUIBasedFilters( facebook::jni::alias_ref); + static bool enableTypedAnimatedPropsAndroid( + facebook::jni::alias_ref); + static bool enableViewCulling( facebook::jni::alias_ref); diff --git a/packages/react-native/ReactAndroid/src/main/res/views/uimanager/values/ids.xml b/packages/react-native/ReactAndroid/src/main/res/views/uimanager/values/ids.xml index abf719c5964e..189b91369931 100644 --- a/packages/react-native/ReactAndroid/src/main/res/views/uimanager/values/ids.xml +++ b/packages/react-native/ReactAndroid/src/main/res/views/uimanager/values/ids.xml @@ -66,6 +66,10 @@ + + + diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/BatchedAnimatedPropsMountItemTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/BatchedAnimatedPropsMountItemTest.kt index 7c13e89b833a..282b9c1fdaae 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/BatchedAnimatedPropsMountItemTest.kt +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/BatchedAnimatedPropsMountItemTest.kt @@ -12,13 +12,75 @@ import com.facebook.react.bridge.ReadableMap import com.facebook.react.fabric.mounting.MountItemDispatcher import com.facebook.react.fabric.mounting.MountingManager import com.facebook.react.fabric.mounting.mountitems.BatchedAnimatedPropsMountItem +import com.facebook.react.fabric.mounting.mountitems.TypedAnimatedPropsApplier +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsDefaults +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests +import com.facebook.react.uimanager.AnimatedTransform import org.assertj.core.api.Assertions.assertThat +import org.junit.After +import org.junit.Before import org.junit.Test +import org.mockito.kotlin.any import org.mockito.kotlin.mock +import org.mockito.kotlin.never import org.mockito.kotlin.verify import org.mockito.kotlin.whenever class BatchedAnimatedPropsMountItemTest { + @Before + fun setUp() { + ReactNativeFeatureFlagsForTests.setUp() + } + + @After + fun tearDown() { + ReactNativeFeatureFlags.dangerouslyReset() + } + + private fun enableTypedAnimatedProps() { + ReactNativeFeatureFlags.override( + object : ReactNativeFeatureFlagsDefaults() { + override fun enableTypedAnimatedPropsAndroid(): Boolean = true + }, + ) + } + + private fun opacityItem(dispatcher: MountItemDispatcher) = + BatchedAnimatedPropsMountItem( + intArrayOf(CMD_START_OF_VIEW, 11, CMD_OPACITY, CMD_END_OF_VIEW), + doubleArrayOf(0.25), + emptyArray(), + dispatcher, + ) + + @Test + fun typedFailureDoesNotApplyTheViewAgainThroughProps() { + enableTypedAnimatedProps() + val manager = mock() + val dispatcher = mock() + whenever(manager.updateAnimatedPropsTyped(11, true, 0.25, null)) + .thenThrow(RuntimeException("view manager failed")) + + opacityItem(dispatcher).execute(manager) + + verify(manager, never()).updateAnimatedPropsSynchronously(any(), any()) + verify(dispatcher, never()).addMountItem(any()) + } + + @Test + fun declinedTypedViewIsAppliedOrQueuedThroughProps() { + enableTypedAnimatedProps() + val manager = mock() + val dispatcher = mock() + whenever(manager.updateAnimatedPropsTyped(11, true, 0.25, null)).thenReturn(false) + + opacityItem(dispatcher).execute(manager) + + verify(manager).updateAnimatedPropsSynchronously(11, JavaOnlyMap.of("opacity", 0.25)) + verify(dispatcher).addMountItem(any()) + } + private fun decode( ints: IntArray, doubles: DoubleArray, @@ -319,6 +381,248 @@ class BatchedAnimatedPropsMountItemTest { verify(manager).updateAnimatedPropsSynchronously(12, JavaOnlyMap.of("opacity", 0.75)) } + /** [opacity] is null when absent. */ + private data class TypedUpdate( + val tag: Int, + val opacity: Double?, + val transform: List>?, + ) + + private fun decodeTyped( + ints: IntArray, + doubles: DoubleArray, + rawProps: Array = emptyArray(), + accept: (Int) -> Boolean = { true }, + ): Pair, List>> { + val typed = mutableListOf() + val maps = mutableListOf>() + val applier = TypedAnimatedPropsApplier { tag, hasOpacity, opacity, transform -> + if (!accept(tag)) { + false + } else { + val ops = transform?.let { t -> (0 until t.size).map { t.ops[it] to t.values[it] } } + typed.add(TypedUpdate(tag, if (hasOpacity) opacity else null, ops)) + true + } + } + BatchedAnimatedPropsMountItem(ints, doubles, rawProps, mock()).decode(applier) { tag, props -> + maps.add(tag to props) + } + return typed to maps + } + + @Test + fun routesOpacityAndPixelTransformsToTheTypedPath() { + val (typed, maps) = + decodeTyped( + intArrayOf( + CMD_START_OF_VIEW, + 11, + CMD_OPACITY, + CMD_START_OF_TRANSFORM, + CMD_TRANSLATE_X, + CMD_UNIT_PX, + CMD_SCALE, + CMD_ROTATE, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + CMD_START_OF_VIEW, + 12, + CMD_START_OF_TRANSFORM, + CMD_ROTATE_X, + CMD_PERSPECTIVE, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + ), + doubleArrayOf(0.5, 4.0, 1.5, 0.25, 0.1, 800.0), + ) + + assertThat(maps).isEmpty() + assertThat(typed) + .containsExactly( + TypedUpdate( + 11, + 0.5, + listOf( + AnimatedTransform.TRANSLATE_X to 4.0, + AnimatedTransform.SCALE to 1.5, + AnimatedTransform.ROTATE to 0.25, + ), + ), + TypedUpdate( + 12, + null, + listOf(AnimatedTransform.ROTATE_X to 0.1, AnimatedTransform.PERSPECTIVE to 800.0), + ), + ) + } + + @Test + fun typedPathKeepsNaNOpacityAndAnEmptyTransform() { + val (typed, maps) = + decodeTyped( + intArrayOf( + CMD_START_OF_VIEW, + 11, + CMD_OPACITY, + CMD_START_OF_TRANSFORM, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + ), + doubleArrayOf(Double.NaN), + ) + + assertThat(maps).isEmpty() + assertThat(typed).containsExactly(TypedUpdate(11, Double.NaN, emptyList())) + } + + @Test + fun laterTransformReplacesAnEarlierOneOnTheTypedPath() { + val (typed, _) = + decodeTyped( + intArrayOf( + CMD_START_OF_VIEW, + 11, + CMD_START_OF_TRANSFORM, + CMD_SCALE, + CMD_END_OF_TRANSFORM, + CMD_START_OF_TRANSFORM, + CMD_ROTATE, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + ), + doubleArrayOf(2.0, 0.5), + ) + + assertThat(typed) + .containsExactly(TypedUpdate(11, null, listOf(AnimatedTransform.ROTATE to 0.5))) + } + + @Test + fun percentAfterPixelOperationsFallsBackWithTheWholeTransform() { + val (typed, maps) = + decodeTyped( + intArrayOf( + CMD_START_OF_VIEW, + 11, + CMD_START_OF_TRANSFORM, + CMD_TRANSLATE_X, + CMD_UNIT_PX, + CMD_SCALE, + CMD_TRANSLATE_Y, + CMD_UNIT_PERCENT, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + CMD_START_OF_VIEW, + 12, + CMD_START_OF_TRANSFORM, + CMD_ROTATE, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + ), + doubleArrayOf(3.0, 1.5, 25.0, 0.2), + ) + + assertThat(typed) + .containsExactly(TypedUpdate(12, null, listOf(AnimatedTransform.ROTATE to 0.2))) + val transform = maps.single().second.getArray("transform")!! + assertThat(transform.size()).isEqualTo(3) + assertThat(transform.getMap(0)!!.getDouble("translateX")).isEqualTo(3.0) + assertThat(transform.getMap(1)!!.getDouble("scale")).isEqualTo(1.5) + assertThat(transform.getMap(2)!!.getString("translateY")).isEqualTo("25.0%") + } + + @Test + fun fallsBackToPropsForViewsTheTypedPathDoesNotCover() { + val color = 0xff112233.toInt() + val raw = JavaOnlyMap.of("width", 3.0) + val (typed, maps) = + decodeTyped( + intArrayOf( + // Percent translation. + CMD_START_OF_VIEW, + 11, + CMD_START_OF_TRANSFORM, + CMD_TRANSLATE_X, + CMD_UNIT_PERCENT, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + // Typed. + CMD_START_OF_VIEW, + 12, + CMD_OPACITY, + CMD_END_OF_VIEW, + // Matrix. + CMD_START_OF_VIEW, + 13, + CMD_START_OF_TRANSFORM, + CMD_MATRIX, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + // A color after opacity. + CMD_START_OF_VIEW, + 14, + CMD_OPACITY, + CMD_OUTLINE_COLOR, + color, + CMD_END_OF_VIEW, + // Raw props. + CMD_START_OF_VIEW, + 15, + CMD_RAW_PROPS, + CMD_END_OF_VIEW, + // Typed, after every fallback. + CMD_START_OF_VIEW, + 16, + CMD_OPACITY, + CMD_END_OF_VIEW, + ), + doubleArrayOf(50.0, 0.3) + DoubleArray(16) { it.toDouble() } + doubleArrayOf(0.6, 0.9), + arrayOf(raw), + ) + + assertThat(typed.map { it.tag to it.opacity }).containsExactly(12 to 0.3, 16 to 0.9) + assertThat(maps.map { it.first }).containsExactly(11, 13, 14, 15) + assertThat(maps[0].second.getArray("transform")!!.getMap(0)!!.getString("translateX")) + .isEqualTo("50.0%") + assertThat( + maps[1].second.getArray("transform")!!.getMap(0)!!.getArray("matrix")!!.getDouble(15) + ) + .isEqualTo(15.0) + assertThat(maps[2].second.getDouble("opacity")).isEqualTo(0.6) + assertThat(maps[2].second.getInt("outlineColor")).isEqualTo(color) + assertThat(maps[3].second).isSameAs(raw) + } + + @Test + fun decodesPropsWhenTheTypedPathDeclinesAView() { + val (typed, maps) = + decodeTyped( + intArrayOf( + CMD_START_OF_VIEW, + 11, + CMD_OPACITY, + CMD_START_OF_TRANSFORM, + CMD_TRANSLATE_Y, + CMD_UNIT_PX, + CMD_END_OF_TRANSFORM, + CMD_END_OF_VIEW, + CMD_START_OF_VIEW, + 12, + CMD_OPACITY, + CMD_END_OF_VIEW, + ), + doubleArrayOf(0.25, 7.0, 0.75), + accept = { it != 11 }, + ) + + assertThat(typed.map { it.tag to it.opacity }).containsExactly(12 to 0.75) + val props = maps.single().second + assertThat(maps.single().first).isEqualTo(11) + assertThat(props.getDouble("opacity")).isEqualTo(0.25) + assertThat(props.getArray("transform")!!.getMap(0)!!.getDouble("translateY")).isEqualTo(7.0) + } + private companion object { const val CMD_START_OF_VIEW = 1 const val CMD_START_OF_TRANSFORM = 2 diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/SurfaceMountingManagerTypedAnimatedPropsTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/SurfaceMountingManagerTypedAnimatedPropsTest.kt new file mode 100644 index 000000000000..9d407e2a1974 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/SurfaceMountingManagerTypedAnimatedPropsTest.kt @@ -0,0 +1,153 @@ +/* + * 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. + */ + +@file:Suppress("DEPRECATION") + +package com.facebook.react.fabric + +import com.facebook.react.ReactRootView +import com.facebook.react.bridge.JavaOnlyMap +import com.facebook.react.bridge.ReactTestHelper +import com.facebook.react.fabric.mounting.MountingManager +import com.facebook.react.fabric.mounting.SurfaceMountingManager +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests +import com.facebook.react.uimanager.ThemedReactContext +import com.facebook.react.uimanager.ViewManager +import com.facebook.react.uimanager.ViewManagerRegistry +import com.facebook.react.views.view.ReactViewManager +import com.facebook.testutils.shadows.ShadowNativeLoader +import com.facebook.testutils.shadows.ShadowNativeMap +import com.facebook.testutils.shadows.ShadowReadableNativeArray +import com.facebook.testutils.shadows.ShadowReadableNativeMap +import com.facebook.testutils.shadows.ShadowSoLoader +import com.facebook.testutils.shadows.ShadowWritableNativeArray +import com.facebook.testutils.shadows.ShadowWritableNativeMap +import org.assertj.core.api.Assertions.assertThat +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +/** + * Tests that the typed animated props path in [SurfaceMountingManager] keeps the synchronous mount + * override semantics of the props map path: later values win per prop, in either order, and a React + * update reads them. + */ +@RunWith(RobolectricTestRunner::class) +@Config( + shadows = + [ + ShadowSoLoader::class, + ShadowNativeLoader::class, + ShadowNativeMap::class, + ShadowWritableNativeMap::class, + ShadowReadableNativeMap::class, + ShadowWritableNativeArray::class, + ShadowReadableNativeArray::class, + ], +) +class SurfaceMountingManagerTypedAnimatedPropsTest { + private lateinit var mountingManager: MountingManager + private lateinit var themedReactContext: ThemedReactContext + private val surfaceId = 1 + private val tag = 42 + + @Before + fun setUp() { + ReactNativeFeatureFlagsForTests.setUp() + val reactContext = ReactTestHelper.createTestReactApplicationContext() + themedReactContext = ThemedReactContext(reactContext, reactContext, null, -1) + mountingManager = + MountingManager( + ViewManagerRegistry( + listOf>(ReactViewManager(), UncoveredViewManager()) + ), + {}, + ) + } + + private fun startSurfaceWithView(componentName: String = "RCTView"): SurfaceMountingManager { + mountingManager.startSurface(surfaceId, themedReactContext, ReactRootView(themedReactContext)) + val smm = mountingManager.getSurfaceManagerEnforced(surfaceId, "test") + smm.preallocateView(componentName, tag, JavaOnlyMap.of(), null, true) + smm.addViewAt(surfaceId, tag, 0) + return smm + } + + /** A subclass of the View manager: not covered by the typed path. */ + private class UncoveredViewManager : ReactViewManager() { + override fun getName(): String = "UncoveredView" + } + + @Test + fun appliesOpacityAndOverridesAStaleUpdate() { + val smm = startSurfaceWithView() + + assertThat(smm.updateAnimatedPropsTyped(tag, true, 0.3, null)).isTrue() + assertThat(smm.getView(tag).alpha).isEqualTo(0.3f) + + smm.updateProps(tag, JavaOnlyMap.of("opacity", 1.0)) + assertThat(smm.getView(tag).alpha).isEqualTo(0.3f) + } + + @Test + fun typedValueAfterAMapValueWins() { + val smm = startSurfaceWithView() + + smm.storeSynchronousMountPropsOverride(tag, JavaOnlyMap.of("opacity", 0.3)) + smm.updateAnimatedPropsTyped(tag, true, 0.7, null) + smm.updateProps(tag, JavaOnlyMap.of("opacity", 1.0)) + + assertThat(smm.getView(tag).alpha).isEqualTo(0.7f) + } + + @Test + fun mapValueAfterATypedValueWins() { + val smm = startSurfaceWithView() + + smm.updateAnimatedPropsTyped(tag, true, 0.7, null) + smm.storeSynchronousMountPropsOverride(tag, JavaOnlyMap.of("opacity", 0.3)) + smm.updateProps(tag, JavaOnlyMap.of("opacity", 1.0)) + + assertThat(smm.getView(tag).alpha).isEqualTo(0.3f) + } + + @Test + fun nullUpdateClearsATypedOverride() { + val smm = startSurfaceWithView() + + smm.updateAnimatedPropsTyped(tag, true, 0.3, null) + smm.storeSynchronousMountPropsOverride(tag, JavaOnlyMap.of("opacity", null)) + smm.updateProps(tag, JavaOnlyMap.of("opacity", 1.0)) + + assertThat(smm.getView(tag).alpha).isEqualTo(1.0f) + } + + @Test + fun deletingTheViewDropsItsTypedOverride() { + val smm = startSurfaceWithView() + + smm.updateAnimatedPropsTyped(tag, true, 0.3, null) + smm.removeViewAt(tag, surfaceId, 0) + smm.deleteView(tag) + smm.preallocateView("RCTView", tag, JavaOnlyMap.of(), null, true) + smm.addViewAt(surfaceId, tag, 0) + smm.updateProps(tag, JavaOnlyMap.of("opacity", 1.0)) + + assertThat(smm.getView(tag).alpha).isEqualTo(1.0f) + } + + @Test + fun declinesViewsItDoesNotCover() { + val smm = startSurfaceWithView("UncoveredView") + + assertThat(smm.updateAnimatedPropsTyped(tag, true, 0.3, null)).isFalse() + assertThat(smm.getView(tag).alpha).isEqualTo(1.0f) + assertThat(smm.updateAnimatedPropsTyped(tag + 1, true, 0.3, null)).isFalse() + } +} diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/AnimatedTransformTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/AnimatedTransformTest.kt new file mode 100644 index 000000000000..2298d10d9d66 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/AnimatedTransformTest.kt @@ -0,0 +1,92 @@ +/* + * 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.uimanager + +import com.facebook.react.bridge.JavaOnlyArray +import com.facebook.react.bridge.JavaOnlyMap +import com.facebook.react.bridge.ReadableArray +import com.facebook.testutils.shadows.ShadowNativeLoader +import com.facebook.testutils.shadows.ShadowSoLoader +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.data.Offset +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(shadows = [ShadowSoLoader::class, ShadowNativeLoader::class]) +class AnimatedTransformTest { + + private val ops: List> = + listOf( + AnimatedTransform.PERSPECTIVE to 900.0, + AnimatedTransform.TRANSLATE_X to 12.0, + AnimatedTransform.TRANSLATE_Y to -4.5, + AnimatedTransform.ROTATE to 0.3, + AnimatedTransform.ROTATE_X to 0.2, + AnimatedTransform.ROTATE_Y to -0.1, + AnimatedTransform.ROTATE_Z to 0.05, + AnimatedTransform.SCALE to 1.2, + AnimatedTransform.SCALE_X to 0.9, + AnimatedTransform.SCALE_Y to 1.1, + ) + + private fun typed(): AnimatedTransform { + val transform = AnimatedTransform() + for ((op, value) in ops) { + transform.add(op, value) + } + return transform + } + + /** The `transform` prop the props map path builds for the same operations. */ + private fun generic(): ReadableArray { + val array = JavaOnlyArray() + for ((op, value) in ops) { + array.pushMap(JavaOnlyMap.of(AnimatedTransform.opName(op), value)) + } + return array + } + + private fun assertSameMatrix(width: Float, height: Float, origin: ReadableArray?) { + val expected = DoubleArray(16) + TransformHelper.processTransform(generic(), expected, width, height, origin) + val actual = DoubleArray(16) + typed().computeMatrix(actual, width, height, origin) + for (i in 0 until 16) { + assertThat(actual[i]).describedAs("matrix[$i]").isCloseTo(expected[i], Offset.offset(1e-12)) + } + } + + @Test + fun matchesTheGenericMatrixWithoutTransformOrigin() { + assertSameMatrix(100f, 50f, null) + } + + @Test + fun matchesTheGenericMatrixWithTransformOrigin() { + assertSameMatrix(100f, 50f, JavaOnlyArray.of("25%", 10.0, 3.0)) + } + + @Test + fun growsPastItsInitialCapacityAndCopies() { + val source = typed() + val copy = AnimatedTransform() + copy.add(AnimatedTransform.SCALE, 5.0) + copy.copyFrom(source) + assertThat(copy.size).isEqualTo(ops.size) + assertThat((0 until copy.size).map { copy.ops[it] to copy.values[it] }).isEqualTo(ops) + } + + @Test + fun storesTheSameOverrideValueAsTheGenericPath() { + val expected = (0 until generic().size()).map { generic().getMap(it)!!.toHashMap() } + assertThat(typed().toPropsList()).isEqualTo(expected) + } +} diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerAnimatedPropsTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerAnimatedPropsTest.kt new file mode 100644 index 000000000000..95977d80bff7 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerAnimatedPropsTest.kt @@ -0,0 +1,195 @@ +/* + * 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.uimanager + +import com.facebook.react.R +import com.facebook.react.bridge.BridgeReactContext +import com.facebook.react.bridge.JavaOnlyArray +import com.facebook.react.bridge.JavaOnlyMap +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests +import com.facebook.react.views.view.ReactViewGroup +import com.facebook.react.views.view.ReactViewManager +import com.facebook.testutils.shadows.ShadowNativeLoader +import com.facebook.testutils.shadows.ShadowSoLoader +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.data.Offset +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +/** + * Checks that [BaseViewManager.applyAnimatedProps] leaves a view in the same state as applying the + * same `opacity` and `transform` props through [BaseViewManager.updateProperties], and that later + * regular props, layout changes and recycling treat the typed transform like the prop. + */ +@RunWith(RobolectricTestRunner::class) +@Config(shadows = [ShadowSoLoader::class, ShadowNativeLoader::class]) +class BaseViewManagerAnimatedPropsTest { + private lateinit var viewManager: BaseViewManager + private lateinit var themedReactContext: ThemedReactContext + + @Before + fun setUp() { + ReactNativeFeatureFlagsForTests.setUp() + DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(RuntimeEnvironment.getApplication()) + viewManager = ReactViewManager() + val context = BridgeReactContext(RuntimeEnvironment.getApplication()) + themedReactContext = ThemedReactContext(context, context, null, -1) + } + + @After + fun tearDown() { + DisplayMetricsHolder.setScreenDisplayMetrics(null) + } + + private fun newView(width: Int = 200, height: Int = 100): ReactViewGroup { + val view = ReactViewGroup(themedReactContext) + view.layout(0, 0, width, height) + return view + } + + private fun update(view: ReactViewGroup, vararg keysAndValues: Any?) { + viewManager.updateProperties(view, ReactStylesDiffMap(JavaOnlyMap.of(*keysAndValues))) + } + + private fun typed(vararg ops: Pair): AnimatedTransform { + val transform = AnimatedTransform() + for ((op, value) in ops) { + transform.add(op, value) + } + return transform + } + + private fun asProp(transform: AnimatedTransform): JavaOnlyArray { + val array = JavaOnlyArray() + for (i in 0 until transform.size) { + array.pushMap(JavaOnlyMap.of(AnimatedTransform.opName(transform.ops[i]), transform.values[i])) + } + return array + } + + private fun assertSameTransform(actual: ReactViewGroup, expected: ReactViewGroup) { + val offset = Offset.offset(1e-3f) + assertThat(actual.translationX).isCloseTo(expected.translationX, offset) + assertThat(actual.translationY).isCloseTo(expected.translationY, offset) + assertThat(actual.rotation).isCloseTo(expected.rotation, offset) + assertThat(actual.rotationX).isCloseTo(expected.rotationX, offset) + assertThat(actual.rotationY).isCloseTo(expected.rotationY, offset) + assertThat(actual.scaleX).isCloseTo(expected.scaleX, offset) + assertThat(actual.scaleY).isCloseTo(expected.scaleY, offset) + assertThat(actual.alpha).isCloseTo(expected.alpha, offset) + } + + private val sample = + typed( + AnimatedTransform.TRANSLATE_X to 12.0, + AnimatedTransform.ROTATE to 0.4, + AnimatedTransform.SCALE to 1.3, + ) + + @Test + fun matchesThePropsPath() { + val actual = newView() + val expected = newView() + val origin = JavaOnlyArray.of("0%", "100%", 0.0) + update(actual, "transformOrigin", origin) + update(expected, "transformOrigin", origin) + + viewManager.applyAnimatedProps(actual, true, 0.4, sample) + update(expected, "opacity", 0.4, "transform", asProp(sample)) + + assertSameTransform(actual, expected) + assertThat(actual.translationX).isNotZero() + } + + @Test + fun keepsTheTypedTransformWhenOnlyTransformOriginChanges() { + val actual = newView() + val expected = newView() + viewManager.applyAnimatedProps(actual, false, 0.0, sample) + update(expected, "transform", asProp(sample)) + + val origin = JavaOnlyArray.of("0%", "0%", 0.0) + update(actual, "transformOrigin", origin) + update(expected, "transformOrigin", origin) + + assertSameTransform(actual, expected) + assertThat(actual.rotation).isNotZero() + } + + @Test + fun regularTransformReplacesTheTypedOne() { + val view = newView() + viewManager.applyAnimatedProps(view, false, 0.0, sample) + + update(view, "transform", JavaOnlyArray.of(JavaOnlyMap.of("translateY", 5.0))) + + assertThat(view.getTag(R.id.animated_transform)).isNull() + assertThat(view.translationX).isZero() + assertThat(view.translationY).isNotZero() + } + + @Test + fun nullTransformResetsTheTypedOne() { + val view = newView() + viewManager.applyAnimatedProps(view, false, 0.0, sample) + + update(view, "transform", null) + + assertThat(view.getTag(R.id.animated_transform)).isNull() + assertThat(view.translationX).isZero() + assertThat(view.rotation).isZero() + assertThat(view.scaleX).isEqualTo(1f) + } + + @Test + fun layoutChangeRecomputesTheTypedTransform() { + val actual = newView() + val expected = newView() + val origin = JavaOnlyArray.of("100%", "100%", 0.0) + update(actual, "transformOrigin", origin) + update(expected, "transformOrigin", origin) + viewManager.applyAnimatedProps(actual, false, 0.0, sample) + update(expected, "transform", asProp(sample)) + + actual.layout(0, 0, 400, 300) + expected.layout(0, 0, 400, 300) + + assertSameTransform(actual, expected) + } + + @Test + fun hiddenBackfaceHidesTheViewLikeThePropsPath() { + val actual = newView() + val expected = newView() + (viewManager as ReactViewManager).setBackfaceVisibility(actual, "hidden") + (viewManager as ReactViewManager).setBackfaceVisibility(expected, "hidden") + val flipped = typed(AnimatedTransform.ROTATE_Y to Math.toRadians(120.0)) + + viewManager.applyAnimatedProps(actual, true, 1.0, flipped) + update(expected, "opacity", 1.0, "transform", asProp(flipped)) + + assertSameTransform(actual, expected) + assertThat(actual.alpha).isEqualTo(expected.alpha) + } + + @Test + fun recyclingClearsTheTypedTransform() { + val view = newView() + viewManager.applyAnimatedProps(view, false, 0.0, sample) + + viewManager.prepareToRecycleView(themedReactContext, view) + + assertThat(view.getTag(R.id.animated_transform)).isNull() + assertThat(view.translationX).isZero() + } +} diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp index 74d72ae7e94c..de2065189d0d 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<44185d291de75775e5b1b41fc6aacb8c>> + * @generated SignedSource<<739c5d0365a21c64b89863a8fa4d521b>> */ /** @@ -242,6 +242,10 @@ bool ReactNativeFeatureFlags::enableSwiftUIBasedFilters() { return getAccessor().enableSwiftUIBasedFilters(); } +bool ReactNativeFeatureFlags::enableTypedAnimatedPropsAndroid() { + return getAccessor().enableTypedAnimatedPropsAndroid(); +} + bool ReactNativeFeatureFlags::enableViewCulling() { return getAccessor().enableViewCulling(); } diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h index 519b5daa808a..e5e89690e39a 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<399726570a1c326455da3a015add1d9b>> + * @generated SignedSource<> */ /** @@ -311,6 +311,11 @@ class ReactNativeFeatureFlags { */ RN_EXPORT static bool enableSwiftUIBasedFilters(); + /** + * Applies opacity and transform updates from the shared animation backend to Android views through typed setters, instead of building a props map and dispatching through the generic ViewManager setters on every frame. + */ + RN_EXPORT static bool enableTypedAnimatedPropsAndroid(); + /** * Enables View Culling: as soon as a view goes off screen, it can be reused anywhere in the UI and pieced together with other items to create new UI elements. */ diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp index ad5cbd622ecf..c77b7ca3d224 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<13736d698e7f80d874ef56c0b592470d>> + * @generated SignedSource<<290b91a2263b90dd1ef77698fe6332ad>> */ /** @@ -1001,6 +1001,24 @@ bool ReactNativeFeatureFlagsAccessor::enableSwiftUIBasedFilters() { return flagValue.value(); } +bool ReactNativeFeatureFlagsAccessor::enableTypedAnimatedPropsAndroid() { + auto flagValue = enableTypedAnimatedPropsAndroid_.load(); + + if (!flagValue.has_value()) { + // This block is not exclusive but it is not necessary. + // If multiple threads try to initialize the feature flag, we would only + // be accessing the provider multiple times but the end state of this + // instance and the returned flag value would be the same. + + markFlagAsAccessed(54, "enableTypedAnimatedPropsAndroid"); + + flagValue = currentProvider_->enableTypedAnimatedPropsAndroid(); + enableTypedAnimatedPropsAndroid_ = flagValue; + } + + return flagValue.value(); +} + bool ReactNativeFeatureFlagsAccessor::enableViewCulling() { auto flagValue = enableViewCulling_.load(); @@ -1010,7 +1028,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewCulling() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(54, "enableViewCulling"); + markFlagAsAccessed(55, "enableViewCulling"); flagValue = currentProvider_->enableViewCulling(); enableViewCulling_ = flagValue; @@ -1028,7 +1046,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecycling() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(55, "enableViewRecycling"); + markFlagAsAccessed(56, "enableViewRecycling"); flagValue = currentProvider_->enableViewRecycling(); enableViewRecycling_ = flagValue; @@ -1046,7 +1064,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecyclingForImage() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(56, "enableViewRecyclingForImage"); + markFlagAsAccessed(57, "enableViewRecyclingForImage"); flagValue = currentProvider_->enableViewRecyclingForImage(); enableViewRecyclingForImage_ = flagValue; @@ -1064,7 +1082,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecyclingForScrollView() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(57, "enableViewRecyclingForScrollView"); + markFlagAsAccessed(58, "enableViewRecyclingForScrollView"); flagValue = currentProvider_->enableViewRecyclingForScrollView(); enableViewRecyclingForScrollView_ = flagValue; @@ -1082,7 +1100,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecyclingForText() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(58, "enableViewRecyclingForText"); + markFlagAsAccessed(59, "enableViewRecyclingForText"); flagValue = currentProvider_->enableViewRecyclingForText(); enableViewRecyclingForText_ = flagValue; @@ -1100,7 +1118,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecyclingForView() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(59, "enableViewRecyclingForView"); + markFlagAsAccessed(60, "enableViewRecyclingForView"); flagValue = currentProvider_->enableViewRecyclingForView(); enableViewRecyclingForView_ = flagValue; @@ -1118,7 +1136,7 @@ bool ReactNativeFeatureFlagsAccessor::enableVirtualViewContainerStateExperimenta // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(60, "enableVirtualViewContainerStateExperimental"); + markFlagAsAccessed(61, "enableVirtualViewContainerStateExperimental"); flagValue = currentProvider_->enableVirtualViewContainerStateExperimental(); enableVirtualViewContainerStateExperimental_ = flagValue; @@ -1136,7 +1154,7 @@ bool ReactNativeFeatureFlagsAccessor::fixBorderlessRippleAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(61, "fixBorderlessRippleAndroid"); + markFlagAsAccessed(62, "fixBorderlessRippleAndroid"); flagValue = currentProvider_->fixBorderlessRippleAndroid(); fixBorderlessRippleAndroid_ = flagValue; @@ -1154,7 +1172,7 @@ bool ReactNativeFeatureFlagsAccessor::fixMappingOfEventPrioritiesBetweenFabricAn // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(62, "fixMappingOfEventPrioritiesBetweenFabricAndReact"); + markFlagAsAccessed(63, "fixMappingOfEventPrioritiesBetweenFabricAndReact"); flagValue = currentProvider_->fixMappingOfEventPrioritiesBetweenFabricAndReact(); fixMappingOfEventPrioritiesBetweenFabricAndReact_ = flagValue; @@ -1172,7 +1190,7 @@ bool ReactNativeFeatureFlagsAccessor::fixMultilineContentJumpAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(63, "fixMultilineContentJumpAndroid"); + markFlagAsAccessed(64, "fixMultilineContentJumpAndroid"); flagValue = currentProvider_->fixMultilineContentJumpAndroid(); fixMultilineContentJumpAndroid_ = flagValue; @@ -1190,7 +1208,7 @@ bool ReactNativeFeatureFlagsAccessor::fixProgrammaticScrollMomentumEventsIOS() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(64, "fixProgrammaticScrollMomentumEventsIOS"); + markFlagAsAccessed(65, "fixProgrammaticScrollMomentumEventsIOS"); flagValue = currentProvider_->fixProgrammaticScrollMomentumEventsIOS(); fixProgrammaticScrollMomentumEventsIOS_ = flagValue; @@ -1208,7 +1226,7 @@ bool ReactNativeFeatureFlagsAccessor::fixTextInlineViewLineHeight() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(65, "fixTextInlineViewLineHeight"); + markFlagAsAccessed(66, "fixTextInlineViewLineHeight"); flagValue = currentProvider_->fixTextInlineViewLineHeight(); fixTextInlineViewLineHeight_ = flagValue; @@ -1226,7 +1244,7 @@ bool ReactNativeFeatureFlagsAccessor::fixTextLayoutOnPixelDensityChange() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(66, "fixTextLayoutOnPixelDensityChange"); + markFlagAsAccessed(67, "fixTextLayoutOnPixelDensityChange"); flagValue = currentProvider_->fixTextLayoutOnPixelDensityChange(); fixTextLayoutOnPixelDensityChange_ = flagValue; @@ -1244,7 +1262,7 @@ bool ReactNativeFeatureFlagsAccessor::fixYogaFlexBasisFitContentInMainAxis() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(67, "fixYogaFlexBasisFitContentInMainAxis"); + markFlagAsAccessed(68, "fixYogaFlexBasisFitContentInMainAxis"); flagValue = currentProvider_->fixYogaFlexBasisFitContentInMainAxis(); fixYogaFlexBasisFitContentInMainAxis_ = flagValue; @@ -1262,7 +1280,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxAssertSingleHostState() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(68, "fuseboxAssertSingleHostState"); + markFlagAsAccessed(69, "fuseboxAssertSingleHostState"); flagValue = currentProvider_->fuseboxAssertSingleHostState(); fuseboxAssertSingleHostState_ = flagValue; @@ -1280,7 +1298,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxEnabledRelease() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(69, "fuseboxEnabledRelease"); + markFlagAsAccessed(70, "fuseboxEnabledRelease"); flagValue = currentProvider_->fuseboxEnabledRelease(); fuseboxEnabledRelease_ = flagValue; @@ -1298,7 +1316,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxFrameRecordingEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(70, "fuseboxFrameRecordingEnabled"); + markFlagAsAccessed(71, "fuseboxFrameRecordingEnabled"); flagValue = currentProvider_->fuseboxFrameRecordingEnabled(); fuseboxFrameRecordingEnabled_ = flagValue; @@ -1316,7 +1334,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxScreenshotCaptureEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(71, "fuseboxScreenshotCaptureEnabled"); + markFlagAsAccessed(72, "fuseboxScreenshotCaptureEnabled"); flagValue = currentProvider_->fuseboxScreenshotCaptureEnabled(); fuseboxScreenshotCaptureEnabled_ = flagValue; @@ -1334,7 +1352,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxWebSocketEventsEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(72, "fuseboxWebSocketEventsEnabled"); + markFlagAsAccessed(73, "fuseboxWebSocketEventsEnabled"); flagValue = currentProvider_->fuseboxWebSocketEventsEnabled(); fuseboxWebSocketEventsEnabled_ = flagValue; @@ -1352,7 +1370,7 @@ bool ReactNativeFeatureFlagsAccessor::keepTimersRunningWhileHostPausedAndroid() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(73, "keepTimersRunningWhileHostPausedAndroid"); + markFlagAsAccessed(74, "keepTimersRunningWhileHostPausedAndroid"); flagValue = currentProvider_->keepTimersRunningWhileHostPausedAndroid(); keepTimersRunningWhileHostPausedAndroid_ = flagValue; @@ -1370,7 +1388,7 @@ bool ReactNativeFeatureFlagsAccessor::optimizedAnimatedPropUpdates() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(74, "optimizedAnimatedPropUpdates"); + markFlagAsAccessed(75, "optimizedAnimatedPropUpdates"); flagValue = currentProvider_->optimizedAnimatedPropUpdates(); optimizedAnimatedPropUpdates_ = flagValue; @@ -1388,7 +1406,7 @@ bool ReactNativeFeatureFlagsAccessor::overrideBySynchronousMountPropsAtMountingA // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(75, "overrideBySynchronousMountPropsAtMountingAndroid"); + markFlagAsAccessed(76, "overrideBySynchronousMountPropsAtMountingAndroid"); flagValue = currentProvider_->overrideBySynchronousMountPropsAtMountingAndroid(); overrideBySynchronousMountPropsAtMountingAndroid_ = flagValue; @@ -1406,7 +1424,7 @@ bool ReactNativeFeatureFlagsAccessor::perfIssuesEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(76, "perfIssuesEnabled"); + markFlagAsAccessed(77, "perfIssuesEnabled"); flagValue = currentProvider_->perfIssuesEnabled(); perfIssuesEnabled_ = flagValue; @@ -1424,7 +1442,7 @@ bool ReactNativeFeatureFlagsAccessor::perfMonitorV2Enabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(77, "perfMonitorV2Enabled"); + markFlagAsAccessed(78, "perfMonitorV2Enabled"); flagValue = currentProvider_->perfMonitorV2Enabled(); perfMonitorV2Enabled_ = flagValue; @@ -1442,7 +1460,7 @@ double ReactNativeFeatureFlagsAccessor::preparedTextCacheSize() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(78, "preparedTextCacheSize"); + markFlagAsAccessed(79, "preparedTextCacheSize"); flagValue = currentProvider_->preparedTextCacheSize(); preparedTextCacheSize_ = flagValue; @@ -1460,7 +1478,7 @@ bool ReactNativeFeatureFlagsAccessor::preventShadowTreeCommitExhaustion() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(79, "preventShadowTreeCommitExhaustion"); + markFlagAsAccessed(80, "preventShadowTreeCommitExhaustion"); flagValue = currentProvider_->preventShadowTreeCommitExhaustion(); preventShadowTreeCommitExhaustion_ = flagValue; @@ -1478,7 +1496,7 @@ bool ReactNativeFeatureFlagsAccessor::redBoxV2Android() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(80, "redBoxV2Android"); + markFlagAsAccessed(81, "redBoxV2Android"); flagValue = currentProvider_->redBoxV2Android(); redBoxV2Android_ = flagValue; @@ -1496,7 +1514,7 @@ bool ReactNativeFeatureFlagsAccessor::redBoxV2IOS() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(81, "redBoxV2IOS"); + markFlagAsAccessed(82, "redBoxV2IOS"); flagValue = currentProvider_->redBoxV2IOS(); redBoxV2IOS_ = flagValue; @@ -1514,7 +1532,7 @@ bool ReactNativeFeatureFlagsAccessor::shouldPressibilityUseW3CPointerEventsForHo // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(82, "shouldPressibilityUseW3CPointerEventsForHover"); + markFlagAsAccessed(83, "shouldPressibilityUseW3CPointerEventsForHover"); flagValue = currentProvider_->shouldPressibilityUseW3CPointerEventsForHover(); shouldPressibilityUseW3CPointerEventsForHover_ = flagValue; @@ -1532,7 +1550,7 @@ bool ReactNativeFeatureFlagsAccessor::shouldTriggerResponderTransferOnScrollAndr // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(83, "shouldTriggerResponderTransferOnScrollAndroid"); + markFlagAsAccessed(84, "shouldTriggerResponderTransferOnScrollAndroid"); flagValue = currentProvider_->shouldTriggerResponderTransferOnScrollAndroid(); shouldTriggerResponderTransferOnScrollAndroid_ = flagValue; @@ -1550,7 +1568,7 @@ bool ReactNativeFeatureFlagsAccessor::skipActivityIdentityAssertionOnHostPause() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(84, "skipActivityIdentityAssertionOnHostPause"); + markFlagAsAccessed(85, "skipActivityIdentityAssertionOnHostPause"); flagValue = currentProvider_->skipActivityIdentityAssertionOnHostPause(); skipActivityIdentityAssertionOnHostPause_ = flagValue; @@ -1568,7 +1586,7 @@ bool ReactNativeFeatureFlagsAccessor::skipNativePropsForViewManagerWithDelegateA // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(85, "skipNativePropsForViewManagerWithDelegateAndroid"); + markFlagAsAccessed(86, "skipNativePropsForViewManagerWithDelegateAndroid"); flagValue = currentProvider_->skipNativePropsForViewManagerWithDelegateAndroid(); skipNativePropsForViewManagerWithDelegateAndroid_ = flagValue; @@ -1586,7 +1604,7 @@ bool ReactNativeFeatureFlagsAccessor::skipUnchangedChildrenInDifferentiator() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(86, "skipUnchangedChildrenInDifferentiator"); + markFlagAsAccessed(87, "skipUnchangedChildrenInDifferentiator"); flagValue = currentProvider_->skipUnchangedChildrenInDifferentiator(); skipUnchangedChildrenInDifferentiator_ = flagValue; @@ -1604,7 +1622,7 @@ bool ReactNativeFeatureFlagsAccessor::syncAndroidClipBoundsWithOverflow() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(87, "syncAndroidClipBoundsWithOverflow"); + markFlagAsAccessed(88, "syncAndroidClipBoundsWithOverflow"); flagValue = currentProvider_->syncAndroidClipBoundsWithOverflow(); syncAndroidClipBoundsWithOverflow_ = flagValue; @@ -1622,7 +1640,7 @@ bool ReactNativeFeatureFlagsAccessor::traceTurboModulePromiseRejectionsOnAndroid // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(88, "traceTurboModulePromiseRejectionsOnAndroid"); + markFlagAsAccessed(89, "traceTurboModulePromiseRejectionsOnAndroid"); flagValue = currentProvider_->traceTurboModulePromiseRejectionsOnAndroid(); traceTurboModulePromiseRejectionsOnAndroid_ = flagValue; @@ -1640,7 +1658,7 @@ bool ReactNativeFeatureFlagsAccessor::updateRuntimeShadowNodeReferencesOnCommit( // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(89, "updateRuntimeShadowNodeReferencesOnCommit"); + markFlagAsAccessed(90, "updateRuntimeShadowNodeReferencesOnCommit"); flagValue = currentProvider_->updateRuntimeShadowNodeReferencesOnCommit(); updateRuntimeShadowNodeReferencesOnCommit_ = flagValue; @@ -1658,7 +1676,7 @@ bool ReactNativeFeatureFlagsAccessor::updateRuntimeShadowNodeReferencesOnCommitT // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(90, "updateRuntimeShadowNodeReferencesOnCommitThread"); + markFlagAsAccessed(91, "updateRuntimeShadowNodeReferencesOnCommitThread"); flagValue = currentProvider_->updateRuntimeShadowNodeReferencesOnCommitThread(); updateRuntimeShadowNodeReferencesOnCommitThread_ = flagValue; @@ -1676,7 +1694,7 @@ bool ReactNativeFeatureFlagsAccessor::useAlwaysAvailableJSErrorHandling() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(91, "useAlwaysAvailableJSErrorHandling"); + markFlagAsAccessed(92, "useAlwaysAvailableJSErrorHandling"); flagValue = currentProvider_->useAlwaysAvailableJSErrorHandling(); useAlwaysAvailableJSErrorHandling_ = flagValue; @@ -1694,7 +1712,7 @@ bool ReactNativeFeatureFlagsAccessor::useFabricInterop() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(92, "useFabricInterop"); + markFlagAsAccessed(93, "useFabricInterop"); flagValue = currentProvider_->useFabricInterop(); useFabricInterop_ = flagValue; @@ -1712,7 +1730,7 @@ bool ReactNativeFeatureFlagsAccessor::useNativeViewConfigsInBridgelessMode() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(93, "useNativeViewConfigsInBridgelessMode"); + markFlagAsAccessed(94, "useNativeViewConfigsInBridgelessMode"); flagValue = currentProvider_->useNativeViewConfigsInBridgelessMode(); useNativeViewConfigsInBridgelessMode_ = flagValue; @@ -1730,7 +1748,7 @@ bool ReactNativeFeatureFlagsAccessor::useNestedScrollViewAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(94, "useNestedScrollViewAndroid"); + markFlagAsAccessed(95, "useNestedScrollViewAndroid"); flagValue = currentProvider_->useNestedScrollViewAndroid(); useNestedScrollViewAndroid_ = flagValue; @@ -1748,7 +1766,7 @@ bool ReactNativeFeatureFlagsAccessor::useSharedAnimatedBackend() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(95, "useSharedAnimatedBackend"); + markFlagAsAccessed(96, "useSharedAnimatedBackend"); flagValue = currentProvider_->useSharedAnimatedBackend(); useSharedAnimatedBackend_ = flagValue; @@ -1766,7 +1784,7 @@ bool ReactNativeFeatureFlagsAccessor::useTraitHiddenOnAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(96, "useTraitHiddenOnAndroid"); + markFlagAsAccessed(97, "useTraitHiddenOnAndroid"); flagValue = currentProvider_->useTraitHiddenOnAndroid(); useTraitHiddenOnAndroid_ = flagValue; @@ -1784,7 +1802,7 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(97, "useTurboModuleInterop"); + markFlagAsAccessed(98, "useTurboModuleInterop"); flagValue = currentProvider_->useTurboModuleInterop(); useTurboModuleInterop_ = flagValue; @@ -1802,7 +1820,7 @@ bool ReactNativeFeatureFlagsAccessor::useWindowDensityForDisplayMetricsAndroid() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(98, "useWindowDensityForDisplayMetricsAndroid"); + markFlagAsAccessed(99, "useWindowDensityForDisplayMetricsAndroid"); flagValue = currentProvider_->useWindowDensityForDisplayMetricsAndroid(); useWindowDensityForDisplayMetricsAndroid_ = flagValue; @@ -1820,7 +1838,7 @@ double ReactNativeFeatureFlagsAccessor::viewCullingOutsetRatio() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(99, "viewCullingOutsetRatio"); + markFlagAsAccessed(100, "viewCullingOutsetRatio"); flagValue = currentProvider_->viewCullingOutsetRatio(); viewCullingOutsetRatio_ = flagValue; @@ -1838,7 +1856,7 @@ bool ReactNativeFeatureFlagsAccessor::viewTransitionEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(100, "viewTransitionEnabled"); + markFlagAsAccessed(101, "viewTransitionEnabled"); flagValue = currentProvider_->viewTransitionEnabled(); viewTransitionEnabled_ = flagValue; @@ -1856,7 +1874,7 @@ bool ReactNativeFeatureFlagsAccessor::viewTransitionUseHardwareBitmapAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(101, "viewTransitionUseHardwareBitmapAndroid"); + markFlagAsAccessed(102, "viewTransitionUseHardwareBitmapAndroid"); flagValue = currentProvider_->viewTransitionUseHardwareBitmapAndroid(); viewTransitionUseHardwareBitmapAndroid_ = flagValue; @@ -1874,7 +1892,7 @@ double ReactNativeFeatureFlagsAccessor::virtualViewPrerenderRatio() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(102, "virtualViewPrerenderRatio"); + markFlagAsAccessed(103, "virtualViewPrerenderRatio"); flagValue = currentProvider_->virtualViewPrerenderRatio(); virtualViewPrerenderRatio_ = flagValue; diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h index b298365059d6..f3e16744caf5 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<8b81c2a9ef5b462a5c28d96133545537>> + * @generated SignedSource<> */ /** @@ -88,6 +88,7 @@ class ReactNativeFeatureFlagsAccessor { bool enablePropsUpdateReconciliationAndroid(); bool enableResizeObserverByDefault(); bool enableSwiftUIBasedFilters(); + bool enableTypedAnimatedPropsAndroid(); bool enableViewCulling(); bool enableViewRecycling(); bool enableViewRecyclingForImage(); @@ -148,7 +149,7 @@ class ReactNativeFeatureFlagsAccessor { std::unique_ptr currentProvider_; bool wasOverridden_; - std::array, 103> accessedFeatureFlags_; + std::array, 104> accessedFeatureFlags_; std::atomic> commonTestFlag_; std::atomic> cdpInteractionMetricsEnabled_; @@ -204,6 +205,7 @@ class ReactNativeFeatureFlagsAccessor { std::atomic> enablePropsUpdateReconciliationAndroid_; std::atomic> enableResizeObserverByDefault_; std::atomic> enableSwiftUIBasedFilters_; + std::atomic> enableTypedAnimatedPropsAndroid_; std::atomic> enableViewCulling_; std::atomic> enableViewRecycling_; std::atomic> enableViewRecyclingForImage_; diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h index 7d90d55dbba7..873d88687b37 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<3f0de97f1127a4c958beb355dd89aa49>> + * @generated SignedSource<<6829dafa5805bfd68fb56724ada05dbb>> */ /** @@ -245,6 +245,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider { return false; } + bool enableTypedAnimatedPropsAndroid() override { + return false; + } + bool enableViewCulling() override { return false; } diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h index 7808d04f3dc3..51b4096ea031 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<14e648942ae5983397e77b3836005a7c>> + * @generated SignedSource<<750be68fa47cab74c5594a3cc226678b>> */ /** @@ -533,6 +533,15 @@ class ReactNativeFeatureFlagsDynamicProvider : public ReactNativeFeatureFlagsDef return ReactNativeFeatureFlagsDefaults::enableSwiftUIBasedFilters(); } + bool enableTypedAnimatedPropsAndroid() override { + auto value = values_["enableTypedAnimatedPropsAndroid"]; + if (!value.isNull()) { + return value.getBool(); + } + + return ReactNativeFeatureFlagsDefaults::enableTypedAnimatedPropsAndroid(); + } + bool enableViewCulling() override { auto value = values_["enableViewCulling"]; if (!value.isNull()) { diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h index cb3c4f972876..995fadc5fa60 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<03e36dccc314d85a3431d62aceb1174a>> + * @generated SignedSource<<104133c74ede5bcc5d88de1f66984576>> */ /** @@ -81,6 +81,7 @@ class ReactNativeFeatureFlagsProvider { virtual bool enablePropsUpdateReconciliationAndroid() = 0; virtual bool enableResizeObserverByDefault() = 0; virtual bool enableSwiftUIBasedFilters() = 0; + virtual bool enableTypedAnimatedPropsAndroid() = 0; virtual bool enableViewCulling() = 0; virtual bool enableViewRecycling() = 0; virtual bool enableViewRecyclingForImage() = 0; diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp index baad12f49355..5c6ccd6b9cc5 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<6190f5f54c0ccd6946599bb1bbb3c1aa>> + * @generated SignedSource<<10e21d1a1037224a6cf493b31f1fb3b1>> */ /** @@ -314,6 +314,11 @@ bool NativeReactNativeFeatureFlags::enableSwiftUIBasedFilters( return ReactNativeFeatureFlags::enableSwiftUIBasedFilters(); } +bool NativeReactNativeFeatureFlags::enableTypedAnimatedPropsAndroid( + jsi::Runtime& /*runtime*/) { + return ReactNativeFeatureFlags::enableTypedAnimatedPropsAndroid(); +} + bool NativeReactNativeFeatureFlags::enableViewCulling( jsi::Runtime& /*runtime*/) { return ReactNativeFeatureFlags::enableViewCulling(); diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index 3113b0d701d3..993c74bd9a8f 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<9d8b1c429f086297c38b67f8db77c566>> + * @generated SignedSource<<7ffcb6b25390f05a7aa79edb1a3a6323>> */ /** @@ -146,6 +146,8 @@ class NativeReactNativeFeatureFlags bool enableSwiftUIBasedFilters(jsi::Runtime& runtime); + bool enableTypedAnimatedPropsAndroid(jsi::Runtime& runtime); + bool enableViewCulling(jsi::Runtime& runtime); bool enableViewRecycling(jsi::Runtime& runtime); diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index 1aadb56c7ecd..dd6c20463c66 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -630,6 +630,17 @@ const definitions: FeatureFlagDefinitions = { }, ossReleaseStage: 'canary', }, + enableTypedAnimatedPropsAndroid: { + defaultValue: false, + metadata: { + dateAdded: '2026-12-02', + description: + 'Applies opacity and transform updates from the shared animation backend to Android views through typed setters, instead of building a props map and dispatching through the generic ViewManager setters on every frame.', + expectedReleaseValue: true, + purpose: 'experimentation', + }, + ossReleaseStage: 'none', + }, enableViewCulling: { defaultValue: false, metadata: { diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 7ff078b47241..2fd93e6f1c1b 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<96fba2f12c24ed676fa6511735fc8cce>> + * @generated SignedSource<<82337b0f0294a38914188c364e188f42>> * @flow strict * @noformat */ @@ -102,6 +102,7 @@ export type ReactNativeFeatureFlags = Readonly<{ enablePropsUpdateReconciliationAndroid: Getter, enableResizeObserverByDefault: Getter, enableSwiftUIBasedFilters: Getter, + enableTypedAnimatedPropsAndroid: Getter, enableViewCulling: Getter, enableViewRecycling: Getter, enableViewRecyclingForImage: Getter, @@ -438,6 +439,10 @@ export const enableResizeObserverByDefault: Getter = createNativeFlagGe * When enabled, it will use SwiftUI for filter effects like blur on iOS. */ export const enableSwiftUIBasedFilters: Getter = createNativeFlagGetter('enableSwiftUIBasedFilters', false); +/** + * Applies opacity and transform updates from the shared animation backend to Android views through typed setters, instead of building a props map and dispatching through the generic ViewManager setters on every frame. + */ +export const enableTypedAnimatedPropsAndroid: Getter = createNativeFlagGetter('enableTypedAnimatedPropsAndroid', false); /** * Enables View Culling: as soon as a view goes off screen, it can be reused anywhere in the UI and pieced together with other items to create new UI elements. */ diff --git a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js index 7b0bd4e5e4a9..e9c66887168c 100644 --- a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<21711915af041d88c306bc5f671f0622>> + * @generated SignedSource<> * @flow strict * @noformat */ @@ -79,6 +79,7 @@ export interface Spec extends TurboModule { readonly enablePropsUpdateReconciliationAndroid?: () => boolean; readonly enableResizeObserverByDefault?: () => boolean; readonly enableSwiftUIBasedFilters?: () => boolean; + readonly enableTypedAnimatedPropsAndroid?: () => boolean; readonly enableViewCulling?: () => boolean; readonly enableViewRecycling?: () => boolean; readonly enableViewRecyclingForImage?: () => boolean;