Skip to content
Open
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 @@ -618,6 +618,15 @@ void FabricMountingManager::executeMount(
std::vector<CppMountItem> cppUpdateOverflowInsetMountItems;
std::vector<CppMountItem> cppUpdateEventEmitterMountItems;

// Views created by this transaction, with the state and event emitter their
// Create item already passes to Java. Their Insert doesn't need to pass them
// again.
struct CreatedView {
const State* state;
const EventEmitter* eventEmitter;
};
std::unordered_map<Tag, CreatedView> createdViews;

{
std::lock_guard allocatedViewsLock(allocatedViewsMutex_);

Expand Down Expand Up @@ -657,6 +666,9 @@ void FabricMountingManager::executeMount(
if (shouldCreateView) {
cppCommonMountItems.push_back(
CppMountItem::CreateMountItem(newChildShadowView));
createdViews[newChildShadowView.tag] = CreatedView{
.state = newChildShadowView.state.get(),
.eventEmitter = newChildShadowView.eventEmitter.get()};
} else {
allocatedView->second.state = AllocatedViewState::Mounted;
}
Expand Down Expand Up @@ -756,6 +768,13 @@ void FabricMountingManager::executeMount(
break;
}
case ShadowViewMutation::Insert: {
auto createdView = createdViews.find(newChildShadowView.tag);
bool createdWithSameState = createdView != createdViews.end() &&
createdView->second.state == newChildShadowView.state.get();
bool createdWithSameEventEmitter =
createdView != createdViews.end() &&
createdView->second.eventEmitter ==
newChildShadowView.eventEmitter.get();
if (!isVirtual) {
// Insert item
cppCommonMountItems.push_back(
Expand Down Expand Up @@ -804,7 +823,7 @@ void FabricMountingManager::executeMount(
}

// State
if (newChildShadowView.state) {
if (newChildShadowView.state && !createdWithSameState) {
(maintainMutationOrder ? cppCommonMountItems
: cppUpdateStateMountItems)
.push_back(
Expand Down Expand Up @@ -845,13 +864,16 @@ void FabricMountingManager::executeMount(
}

// EventEmitter
// On insert we always update the event emitter, as we do not pass
// it in when preallocating views
(maintainMutationOrder ? cppCommonMountItems
: cppUpdateEventEmitterMountItems)
.push_back(
CppMountItem::UpdateEventEmitterMountItem(
mutation.newChildShadowView));
// On insert we update the event emitter, as we do not pass it in
// when preallocating views. A view created by this transaction
// already got it with its Create item.
if (!createdWithSameEventEmitter) {
(maintainMutationOrder ? cppCommonMountItems
: cppUpdateEventEmitterMountItems)
.push_back(
CppMountItem::UpdateEventEmitterMountItem(
mutation.newChildShadowView));
}

break;
}
Expand Down
Loading