mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Ship MountItem Remove/Delete Collation
Summary: Ship MountItem Remove/Delete Collation. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D22170891 fbshipit-source-id: a9a149783bdd69df54e429da6ed9870bfb405a36
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7abcaafd66
commit
0a115d9c3f
@@ -21,7 +21,6 @@ import com.facebook.react.fabric.mounting.LayoutMetricsConversions;
|
||||
import com.facebook.react.fabric.mounting.MountingManager;
|
||||
import com.facebook.react.fabric.mounting.mountitems.BatchMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.CreateMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.DeleteMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.DispatchIntCommandMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.DispatchStringCommandMountItem;
|
||||
@@ -29,7 +28,6 @@ import com.facebook.react.fabric.mounting.mountitems.InsertMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.MountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.RemoveDeleteMultiMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.RemoveMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent;
|
||||
import com.facebook.react.fabric.mounting.mountitems.UpdateEventEmitterMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.UpdateLayoutMountItem;
|
||||
@@ -112,7 +110,6 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
|
||||
FabricEventEmitter.class.getClass();
|
||||
BatchMountItem.class.getClass();
|
||||
CreateMountItem.class.getClass();
|
||||
DeleteMountItem.class.getClass();
|
||||
DispatchCommandMountItem.class.getClass();
|
||||
DispatchIntCommandMountItem.class.getClass();
|
||||
DispatchStringCommandMountItem.class.getClass();
|
||||
@@ -120,7 +117,6 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
|
||||
MountItem.class.getClass();
|
||||
PreAllocateViewMountItem.class.getClass();
|
||||
RemoveDeleteMultiMountItem.class.getClass();
|
||||
RemoveMountItem.class.getClass();
|
||||
SendAccessibilityEvent.class.getClass();
|
||||
UpdateEventEmitterMountItem.class.getClass();
|
||||
UpdateLayoutMountItem.class.getClass();
|
||||
|
||||
@@ -56,7 +56,6 @@ import com.facebook.react.fabric.events.FabricEventEmitter;
|
||||
import com.facebook.react.fabric.mounting.MountingManager;
|
||||
import com.facebook.react.fabric.mounting.mountitems.BatchMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.CreateMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.DeleteMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.DispatchIntCommandMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.DispatchStringCommandMountItem;
|
||||
@@ -64,7 +63,6 @@ import com.facebook.react.fabric.mounting.mountitems.InsertMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.MountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.RemoveDeleteMultiMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.RemoveMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent;
|
||||
import com.facebook.react.fabric.mounting.mountitems.UpdateEventEmitterMountItem;
|
||||
import com.facebook.react.fabric.mounting.mountitems.UpdateLayoutMountItem;
|
||||
@@ -367,14 +365,6 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
isLayoutable);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
@SuppressWarnings("unused")
|
||||
@AnyThread
|
||||
@ThreadConfined(ANY)
|
||||
private MountItem removeMountItem(int reactTag, int parentReactTag, int index) {
|
||||
return new RemoveMountItem(reactTag, parentReactTag, index);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
@SuppressWarnings("unused")
|
||||
@AnyThread
|
||||
@@ -383,14 +373,6 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
return new InsertMountItem(reactTag, parentReactTag, index);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
@SuppressWarnings("unused")
|
||||
@AnyThread
|
||||
@ThreadConfined(ANY)
|
||||
private MountItem deleteMountItem(int reactTag) {
|
||||
return new DeleteMountItem(reactTag);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
@SuppressWarnings("unused")
|
||||
@AnyThread
|
||||
|
||||
@@ -280,8 +280,6 @@ void Binding::installFabricUIManager(
|
||||
|
||||
// Keep reference to config object and cache some feature flags here
|
||||
reactNativeConfig_ = config;
|
||||
shouldCollateRemovesAndDeletes_ = reactNativeConfig_->getBool(
|
||||
"react_fabric:enable_removedelete_collation_android");
|
||||
collapseDeleteCreateMountingInstructions_ = reactNativeConfig_->getBool(
|
||||
"react_fabric:enabled_collapse_delete_create_mounting_instructions");
|
||||
|
||||
@@ -491,31 +489,6 @@ local_ref<JMountItem::javaobject> createUpdateStateMountItem(
|
||||
(javaStateWrapper != nullptr ? javaStateWrapper.get() : nullptr));
|
||||
}
|
||||
|
||||
local_ref<JMountItem::javaobject> createRemoveMountItem(
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const ShadowViewMutation &mutation) {
|
||||
static auto removeInstruction =
|
||||
jni::findClassStatic(Binding::UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jint, jint, jint)>(
|
||||
"removeMountItem");
|
||||
|
||||
return removeInstruction(
|
||||
javaUIManager,
|
||||
mutation.oldChildShadowView.tag,
|
||||
mutation.parentShadowView.tag,
|
||||
mutation.index);
|
||||
}
|
||||
|
||||
local_ref<JMountItem::javaobject> createDeleteMountItem(
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const ShadowViewMutation &mutation) {
|
||||
static auto deleteInstruction =
|
||||
jni::findClassStatic(Binding::UIManagerJavaDescriptor)
|
||||
->getMethod<alias_ref<JMountItem>(jint)>("deleteMountItem");
|
||||
|
||||
return deleteInstruction(javaUIManager, mutation.oldChildShadowView.tag);
|
||||
}
|
||||
|
||||
local_ref<JMountItem::javaobject> createRemoveAndDeleteMultiMountItem(
|
||||
const jni::global_ref<jobject> &javaUIManager,
|
||||
const std::vector<RemoveDeleteMetadata> &metadata) {
|
||||
@@ -685,8 +658,7 @@ void Binding::schedulerDidFinishTransaction(
|
||||
oldChildShadowView.layoutMetrics == EmptyLayoutMetrics;
|
||||
|
||||
// Handle accumulated removals/deletions
|
||||
if (shouldCollateRemovesAndDeletes_ &&
|
||||
mutation.type != ShadowViewMutation::Remove &&
|
||||
if (mutation.type != ShadowViewMutation::Remove &&
|
||||
mutation.type != ShadowViewMutation::Delete) {
|
||||
if (toRemove.size() > 0) {
|
||||
mountItems[position++] =
|
||||
@@ -708,39 +680,29 @@ void Binding::schedulerDidFinishTransaction(
|
||||
}
|
||||
case ShadowViewMutation::Remove: {
|
||||
if (!isVirtual) {
|
||||
if (shouldCollateRemovesAndDeletes_) {
|
||||
toRemove.push_back(
|
||||
RemoveDeleteMetadata{mutation.oldChildShadowView.tag,
|
||||
mutation.parentShadowView.tag,
|
||||
mutation.index,
|
||||
true,
|
||||
false});
|
||||
} else {
|
||||
mountItems[position++] =
|
||||
createRemoveMountItem(localJavaUIManager, mutation);
|
||||
}
|
||||
toRemove.push_back(
|
||||
RemoveDeleteMetadata{mutation.oldChildShadowView.tag,
|
||||
mutation.parentShadowView.tag,
|
||||
mutation.index,
|
||||
true,
|
||||
false});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ShadowViewMutation::Delete: {
|
||||
if (shouldCollateRemovesAndDeletes_) {
|
||||
// It is impossible to delete without removing node first
|
||||
const auto &it = std::find_if(
|
||||
std::begin(toRemove),
|
||||
std::end(toRemove),
|
||||
[&mutation](const auto &x) {
|
||||
return x.tag == mutation.oldChildShadowView.tag;
|
||||
});
|
||||
// It is impossible to delete without removing node first
|
||||
const auto &it = std::find_if(
|
||||
std::begin(toRemove),
|
||||
std::end(toRemove),
|
||||
[&mutation](const auto &x) {
|
||||
return x.tag == mutation.oldChildShadowView.tag;
|
||||
});
|
||||
|
||||
if (it != std::end(toRemove)) {
|
||||
it->shouldDelete = true;
|
||||
} else {
|
||||
toRemove.push_back(RemoveDeleteMetadata{
|
||||
mutation.oldChildShadowView.tag, -1, -1, false, true});
|
||||
}
|
||||
if (it != std::end(toRemove)) {
|
||||
it->shouldDelete = true;
|
||||
} else {
|
||||
mountItems[position++] =
|
||||
createDeleteMountItem(localJavaUIManager, mutation);
|
||||
toRemove.push_back(RemoveDeleteMetadata{
|
||||
mutation.oldChildShadowView.tag, -1, -1, false, true});
|
||||
}
|
||||
|
||||
deletedViewTags.insert(mutation.oldChildShadowView.tag);
|
||||
@@ -840,7 +802,7 @@ void Binding::schedulerDidFinishTransaction(
|
||||
}
|
||||
|
||||
// Handle remaining removals and deletions
|
||||
if (shouldCollateRemovesAndDeletes_ && toRemove.size() > 0) {
|
||||
if (toRemove.size() > 0) {
|
||||
mountItems[position++] =
|
||||
createRemoveAndDeleteMultiMountItem(localJavaUIManager, toRemove);
|
||||
toRemove.clear();
|
||||
|
||||
@@ -125,7 +125,6 @@ class Binding : public jni::HybridClass<Binding>,
|
||||
float pointScaleFactor_ = 1;
|
||||
|
||||
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_{nullptr};
|
||||
bool shouldCollateRemovesAndDeletes_{false};
|
||||
bool collapseDeleteCreateMountingInstructions_{false};
|
||||
bool disablePreallocateViews_{false};
|
||||
bool disableVirtualNodePreallocation_{false};
|
||||
|
||||
+11
-13
@@ -281,19 +281,17 @@ public class MountingManager {
|
||||
ViewGroupManager<ViewGroup> viewGroupManager = getViewGroupManager(viewState);
|
||||
|
||||
// Verify that the view we're about to remove has the same tag we expect
|
||||
if (tag != -1) {
|
||||
View view = viewGroupManager.getChildAt(parentView, index);
|
||||
if (view != null && view.getId() != tag) {
|
||||
throw new IllegalStateException(
|
||||
"Tried to delete view ["
|
||||
+ tag
|
||||
+ "] of parent ["
|
||||
+ parentTag
|
||||
+ "] at index "
|
||||
+ index
|
||||
+ ", but got view tag "
|
||||
+ view.getId());
|
||||
}
|
||||
View view = viewGroupManager.getChildAt(parentView, index);
|
||||
if (view != null && view.getId() != tag) {
|
||||
throw new IllegalStateException(
|
||||
"Tried to delete view ["
|
||||
+ tag
|
||||
+ "] of parent ["
|
||||
+ parentTag
|
||||
+ "] at index "
|
||||
+ index
|
||||
+ ", but got view tag "
|
||||
+ view.getId());
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.fabric.mounting.mountitems;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.react.fabric.mounting.MountingManager;
|
||||
|
||||
public class DeleteMountItem implements MountItem {
|
||||
|
||||
private int mReactTag;
|
||||
|
||||
public DeleteMountItem(int reactTag) {
|
||||
mReactTag = reactTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NonNull MountingManager mountingManager) {
|
||||
mountingManager.deleteView(mReactTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeleteMountItem [" + mReactTag + "]";
|
||||
}
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.fabric.mounting.mountitems;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.react.fabric.mounting.MountingManager;
|
||||
|
||||
public class RemoveMountItem implements MountItem {
|
||||
|
||||
private int mReactTag;
|
||||
private int mParentReactTag;
|
||||
private int mIndex;
|
||||
|
||||
public RemoveMountItem(int reactTag, int parentReactTag, int index) {
|
||||
mReactTag = reactTag;
|
||||
mParentReactTag = parentReactTag;
|
||||
mIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NonNull MountingManager mountingManager) {
|
||||
mountingManager.removeViewAt(-1, mParentReactTag, mIndex);
|
||||
}
|
||||
|
||||
public int getParentReactTag() {
|
||||
return mParentReactTag;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return mIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RemoveMountItem ["
|
||||
+ mReactTag
|
||||
+ "] - parentTag: "
|
||||
+ mParentReactTag
|
||||
+ " - index: "
|
||||
+ mIndex;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user