From 30d50430a90e0295220b08e327487d7952f26d65 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sat, 10 Dec 2022 10:30:47 -0800 Subject: [PATCH] Delete C++ ViewManagers Summary: This diff deletes the first implementation of C++ ViewManagers integrated into the internals of Fabric changelog: [internal] internal Reviewed By: javache Differential Revision: D41638894 fbshipit-source-id: 2e7aebff587e2e57b7f3fbf37a24b04943c74573 --- .../mountitems/IntBufferBatchMountItem.java | 11 -- .../react/fabric/CppViewMutationsWrapper.cpp | 100 ------------------ .../react/fabric/CppViewMutationsWrapper.h | 39 ------- .../main/jni/react/fabric/FabricMountItem.h | 3 +- .../react/fabric/FabricMountingManager.cpp | 33 ------ .../src/main/jni/react/fabric/OnLoad.cpp | 2 - 6 files changed, 1 insertion(+), 187 deletions(-) delete mode 100644 ReactAndroid/src/main/jni/react/fabric/CppViewMutationsWrapper.cpp delete mode 100644 ReactAndroid/src/main/jni/react/fabric/CppViewMutationsWrapper.h diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java index f5bc56dd52e..9d110574ee8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java @@ -16,7 +16,6 @@ import com.facebook.common.logging.FLog; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.ReactMarker; import com.facebook.react.bridge.ReactMarkerConstants; -import com.facebook.react.fabric.CppViewMutationsWrapper; import com.facebook.react.fabric.events.EventEmitterWrapper; import com.facebook.react.fabric.mounting.MountingManager; import com.facebook.react.fabric.mounting.SurfaceMountingManager; @@ -51,7 +50,6 @@ public class IntBufferBatchMountItem implements MountItem { static final int INSTRUCTION_UPDATE_PADDING = 512; static final int INSTRUCTION_UPDATE_OVERFLOW_INSET = 1024; static final int INSTRUCTION_REMOVE_DELETE_TREE = 2048; - static final int INSTRUCTION_RUN_CPP_VIEWS = 4096; private final int mSurfaceId; private final int mCommitNumber; @@ -99,10 +97,6 @@ public class IntBufferBatchMountItem implements MountItem { return obj != null ? (EventEmitterWrapper) obj : null; } - private static CppViewMutationsWrapper castToCppViewMutationWrapper(Object obj) { - return obj != null ? (CppViewMutationsWrapper) obj : null; - } - @Override public void execute(@NonNull MountingManager mountingManager) { SurfaceMountingManager surfaceMountingManager = mountingManager.getSurfaceManager(mSurfaceId); @@ -184,8 +178,6 @@ public class IntBufferBatchMountItem implements MountItem { } else if (type == INSTRUCTION_UPDATE_EVENT_EMITTER) { surfaceMountingManager.updateEventEmitter( mIntBuffer[i++], castToEventEmitter(mObjBuffer[j++])); - } else if (type == INSTRUCTION_RUN_CPP_VIEWS) { - castToCppViewMutationWrapper(mObjBuffer[j++]).runCppViewMutations(); } else { throw new IllegalArgumentException( "Invalid type argument to IntBufferBatchMountItem: " + type + " at index: " + i); @@ -286,9 +278,6 @@ public class IntBufferBatchMountItem implements MountItem { } else if (type == INSTRUCTION_UPDATE_EVENT_EMITTER) { j += 1; s.append(String.format("UPDATE EVENTEMITTER [%d]\n", mIntBuffer[i++])); - } else if (type == INSTRUCTION_RUN_CPP_VIEWS) { - j += 1; - s.append(String.format("RUN CPP_VIEWS [%d]\n", mIntBuffer[i++])); } else { FLog.e(TAG, "String so far: " + s.toString()); throw new IllegalArgumentException( diff --git a/ReactAndroid/src/main/jni/react/fabric/CppViewMutationsWrapper.cpp b/ReactAndroid/src/main/jni/react/fabric/CppViewMutationsWrapper.cpp deleted file mode 100644 index eb85fae4fe7..00000000000 --- a/ReactAndroid/src/main/jni/react/fabric/CppViewMutationsWrapper.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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. - */ - -#include "CppViewMutationsWrapper.h" - -#include - -#include -#include - -using namespace facebook::jni; - -namespace facebook { -namespace react { - -jni::local_ref -CppViewMutationsWrapper::initHybrid(jni::alias_ref) { - return makeCxxInstance(); -} - -void CppViewMutationsWrapper::registerNatives() { - registerHybrid({ - makeNativeMethod("initHybrid", CppViewMutationsWrapper::initHybrid), - makeNativeMethod( - "runCppViewMutations", CppViewMutationsWrapper::runCppViewMutations), - }); -} - -void CppViewMutationsWrapper::runCppViewMutations() { - // TODO implement rendering logic: - // - caching of componengtManagers of views into maps - // - caching of allocated views - // - logic for each mutation instruction - // - Define API in ComponentManager - // - Define API in Component - // - see RCTMountingManager.mm for logic - for (const auto &mutation : *cppViewMutations) { - const auto &newChildShadowView = mutation.newChildShadowView; - auto &mutationType = mutation.type; - auto componentName = newChildShadowView.componentName; - auto tag = mutation.newChildShadowView.tag; - - switch (mutationType) { - case ShadowViewMutation::Create: { - auto component = cppComponentRegistry->createComponentInstance( - componentName, tag, newChildShadowView.props); - break; - } - case ShadowViewMutation::Remove: { - auto parentTag = mutation.parentShadowView.tag; - auto parentComponent = - cppComponentRegistry->getComponentInstance(parentTag); - auto childComponent = cppComponentRegistry->getComponentInstance( - mutation.newChildShadowView.tag); - parentComponent->unmountChildComponent(childComponent, mutation.index); - break; - } - case ShadowViewMutation::Delete: { - cppComponentRegistry->deleteComponentInstance(tag); - break; - } - case ShadowViewMutation::Update: { - auto component = cppComponentRegistry->getComponentInstance(tag); - if (mutation.oldChildShadowView.props != - mutation.newChildShadowView.props) { - component->updateProps( - mutation.oldChildShadowView.props, - mutation.newChildShadowView.props); - } - break; - } - case ShadowViewMutation::Insert: { - auto parentTag = mutation.parentShadowView.tag; - auto parentComponent = - cppComponentRegistry->getComponentInstance(parentTag); - auto childTag = mutation.newChildShadowView.tag; - auto childComponent = - cppComponentRegistry->getComponentInstance(childTag); - auto oldProps = mutation.oldChildShadowView.props; - auto newProps = mutation.newChildShadowView.props; - childComponent->updateProps(oldProps, newProps); - - if (childComponent && parentComponent) { - parentComponent->mountChildComponent(childComponent, mutation.index); - } - break; - } - default: { - break; - } - } - } -} - -} // namespace react -} // namespace facebook diff --git a/ReactAndroid/src/main/jni/react/fabric/CppViewMutationsWrapper.h b/ReactAndroid/src/main/jni/react/fabric/CppViewMutationsWrapper.h deleted file mode 100644 index 6e875b6d647..00000000000 --- a/ReactAndroid/src/main/jni/react/fabric/CppViewMutationsWrapper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ - -#pragma once - -#include - -#include -#include -#include - -namespace facebook { -namespace react { - -class CppViewMutationsWrapper - : public jni::HybridClass { - public: - constexpr static const char *const kJavaDescriptor = - "Lcom/facebook/react/fabric/CppViewMutationsWrapper;"; - - static void registerNatives(); - - // TODO move this to a constructor or init methods - std::shared_ptr cppViewMutations; - - std::shared_ptr cppComponentRegistry; - - void runCppViewMutations(); - - private: - static jni::local_ref initHybrid(jni::alias_ref); -}; - -} // namespace react -} // namespace facebook diff --git a/ReactAndroid/src/main/jni/react/fabric/FabricMountItem.h b/ReactAndroid/src/main/jni/react/fabric/FabricMountItem.h index adc6ed81b04..f2e82f7a23e 100644 --- a/ReactAndroid/src/main/jni/react/fabric/FabricMountItem.h +++ b/ReactAndroid/src/main/jni/react/fabric/FabricMountItem.h @@ -72,8 +72,7 @@ struct CppMountItem final { UpdateEventEmitter = 256, UpdatePadding = 512, UpdateOverflowInset = 1024, - RemoveDeleteTree = 2048, - RunCPPMutations = 4096 + RemoveDeleteTree = 2048 }; #pragma mark - Fields diff --git a/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp b/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp index 33b5eee5aa6..b260c0288df 100644 --- a/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp +++ b/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp @@ -6,7 +6,6 @@ */ #include "FabricMountingManager.h" -#include "CppViewMutationsWrapper.h" #include "EventEmitterWrapper.h" #include "StateWrapperImpl.h" @@ -77,8 +76,6 @@ static inline int getIntBufferSizeForType(CppMountItem::Type mountItemType) { return 7; // tag, parentTag, x, y, w, h, DisplayType case CppMountItem::Type::UpdateOverflowInset: return 5; // tag, left, top, right, bottom - case CppMountItem::Type::RunCPPMutations: - return 1; case CppMountItem::Undefined: case CppMountItem::Multiple: return -1; @@ -821,36 +818,6 @@ void FabricMountingManager::executeMount( } } - if (cppViewMutations.size() > 0) { - writeIntBufferTypePreamble( - CppMountItem::Type::RunCPPMutations, - 1, - env, - intBufferArray, - intBufferPosition); - - // TODO review this logic and memory mamangement - // this might not be necessary: - // temp[0] = 1234; - // env->SetIntArrayRegion(intBufferArray, intBufferPosition, 1, temp); - // intBufferPosition += 1; - - // Do not hold a reference to javaCppMutations from the C++ side. - auto javaCppMutations = CppViewMutationsWrapper::newObjectJavaArgs(); - CppViewMutationsWrapper *cppViewMutationsWrapper = cthis(javaCppMutations); - - // TODO move this to init methods - cppViewMutationsWrapper->cppComponentRegistry = cppComponentRegistry_; - // TODO is moving the cppViewMutations safe / thread safe? - // cppViewMutations will be accessed from the UI Thread in a near future - // can they dissapear? - cppViewMutationsWrapper->cppViewMutations = - std::make_shared>( - std::move(cppViewMutations)); - - (*objBufferArray)[objBufferPosition++] = javaCppMutations.get(); - } - // If there are no items, we pass a nullptr instead of passing the object // through the JNI auto batch = createMountItemsIntBufferBatchContainer( diff --git a/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp b/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp index b7825d4bb9f..7ebf9b5247e 100644 --- a/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp @@ -10,7 +10,6 @@ #include "Binding.h" #include "ComponentFactory.h" #include "CoreComponentsRegistry.h" -#include "CppViewMutationsWrapper.h" #include "EventBeatManager.h" #include "EventEmitterWrapper.h" #include "StateWrapperImpl.h" @@ -21,7 +20,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { facebook::react::Binding::registerNatives(); facebook::react::EventBeatManager::registerNatives(); facebook::react::EventEmitterWrapper::registerNatives(); - facebook::react::CppViewMutationsWrapper::registerNatives(); facebook::react::StateWrapperImpl::registerNatives(); facebook::react::ComponentFactory::registerNatives(); facebook::react::CoreComponentsRegistry::registerNatives();