Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ internal constructor(
modifiedProps.merge(props)
val directPropsMap = checkNotNull(tagToSynchronousMountProps[reactTag])
overridePropsReadableMap(directPropsMap, modifiedProps)
if (directPropsMap.isEmpty()) {
tagToSynchronousMountProps.remove(reactTag)
}
viewState.currentProps = ReactStylesDiffMap(modifiedProps)
} else {
viewState.currentProps = ReactStylesDiffMap(props)
Expand Down Expand Up @@ -1326,11 +1329,18 @@ internal constructor(
}

private fun overridePropsReadableMap(
patchMap: Map<String, Any>,
patchMap: MutableMap<String, Any>,
outputReadableMap: WritableMap,
) {
for ((propKey, propValue) in patchMap) {
val iterator = patchMap.entries.iterator()
while (iterator.hasNext()) {
val (propKey, propValue) = iterator.next()
if (outputReadableMap.hasKey(propKey)) {
if (outputReadableMap.getType(propKey) == ReadableType.Null) {
iterator.remove()
continue
}

if (propKey == PROP_TRANSFORM) {
assert(outputReadableMap.getType(propKey) == ReadableType.Array && propValue is List<*>)
val array = WritableNativeArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package com.facebook.react.fabric

import com.facebook.react.ReactRootView
import com.facebook.react.bridge.JavaOnlyArray
import com.facebook.react.bridge.JavaOnlyMap
import com.facebook.react.bridge.ReactTestHelper
import com.facebook.react.fabric.mounting.MountingManager
Expand Down Expand Up @@ -137,6 +138,39 @@ class SurfaceMountingManagerSynchronousMountPropsTest {
assertThat(smm.getView(tag).alpha).isEqualTo(0.2f)
}

/** A null Fabric prop update should clear the stored synchronous opacity override. */
@Test
fun updateProps_withNullOpacity_removesStoredSynchronousProp() {
val smm = startSurface()
val tag = 42
createAndAttachView(smm, tag)

smm.storeSynchronousMountPropsOverride(tag, JavaOnlyMap.of("opacity", 0.3))
smm.updatePropsSynchronously(tag, JavaOnlyMap.of("opacity", 0.3))
assertThat(smm.getView(tag).alpha).isEqualTo(0.3f)

smm.updateProps(tag, JavaOnlyMap.of("opacity", null))

assertThat(smm.getView(tag).alpha).isEqualTo(1.0f)
}

/** A null Fabric prop update should clear the stored synchronous transform override. */
@Test
fun updateProps_withNullTransform_removesStoredSynchronousProp() {
val smm = startSurface()
val tag = 42
val transform = JavaOnlyArray.of(JavaOnlyMap.of("translateY", 40.0))
createAndAttachView(smm, tag)

smm.storeSynchronousMountPropsOverride(tag, JavaOnlyMap.of("transform", transform))
smm.updatePropsSynchronously(tag, JavaOnlyMap.of("transform", transform))
assertThat(smm.getView(tag).translationY).isEqualTo(40.0f)

smm.updateProps(tag, JavaOnlyMap.of("transform", null))

assertThat(smm.getView(tag).translationY).isEqualTo(0.0f)
}

/**
* When a view is deleted, stored synchronous props should be cleaned up. A recreated view with
* the same tag should not be affected by the old stored props.
Expand Down
Loading