From 1054930d451d27501d3ce3f34fe05c02f522466f Mon Sep 17 00:00:00 2001 From: David Vacca Date: Wed, 31 Jul 2019 23:26:22 -0700 Subject: [PATCH] Remove ViewPooling from Fabric Android Summary: View Pooling is not currently being used in Fabric Android, this diff removes all the extra abstractions that are being used becuase of the unused ViewPooling. We might add this in the future when we re-implement view correctly. Reviewed By: JoshuaGross Differential Revision: D16543439 fbshipit-source-id: f41b6e02fddc36c7ef7a1052399d2e6b2041fcfb --- .../react/fabric/FabricJSIModuleProvider.java | 8 -- .../fabric/mounting/ContextBasedViewPool.java | 57 --------------- .../fabric/mounting/MountingManager.java | 13 +--- .../react/fabric/mounting/ViewFactory.java | 24 ------ .../fabric/mounting/ViewManagerFactory.java | 40 ---------- .../react/fabric/mounting/ViewPool.java | 73 ------------------- 6 files changed, 2 insertions(+), 213 deletions(-) delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ContextBasedViewPool.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewFactory.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewManagerFactory.java delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewPool.java diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java index 2bb54b6d8b8..47f6ffbc4f6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricJSIModuleProvider.java @@ -9,12 +9,8 @@ import com.facebook.react.bridge.queue.MessageQueueThread; import com.facebook.react.fabric.events.EventBeatManager; import com.facebook.react.fabric.events.EventEmitterWrapper; import com.facebook.react.fabric.events.FabricEventEmitter; -import com.facebook.react.fabric.mounting.ContextBasedViewPool; import com.facebook.react.fabric.mounting.LayoutMetricsConversions; import com.facebook.react.fabric.mounting.MountingManager; -import com.facebook.react.fabric.mounting.ViewFactory; -import com.facebook.react.fabric.mounting.ViewManagerFactory; -import com.facebook.react.fabric.mounting.ViewPool; import com.facebook.react.fabric.mounting.mountitems.BatchMountItem; import com.facebook.react.fabric.mounting.mountitems.DeleteMountItem; import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem; @@ -98,9 +94,7 @@ public class FabricJSIModuleProvider implements JSIModuleProvider { BatchEventDispatchedListener.class.getClass(); ReactNativeConfig.class.getClass(); FabricComponents.class.getClass(); - ViewManagerFactory.class.getClass(); StateWrapper.class.getClass(); - ViewFactory.class.getClass(); FabricEventEmitter.class.getClass(); FabricUIManager.class.getClass(); GuardedFrameCallback.class.getClass(); @@ -115,10 +109,8 @@ public class FabricJSIModuleProvider implements JSIModuleProvider { UpdateLayoutMountItem.class.getClass(); UpdateLocalDataMountItem.class.getClass(); UpdatePropsMountItem.class.getClass(); - ContextBasedViewPool.class.getClass(); LayoutMetricsConversions.class.getClass(); MountingManager.class.getClass(); - ViewPool.class.getClass(); Binding.class.getClass(); ComponentFactoryDelegate.class.getClass(); EventBeatManager.class.getClass(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ContextBasedViewPool.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ContextBasedViewPool.java deleted file mode 100644 index 3a3057629d8..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ContextBasedViewPool.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - *

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; - -import android.view.View; -import androidx.annotation.UiThread; -import com.facebook.react.uimanager.ReactStylesDiffMap; -import com.facebook.react.uimanager.StateWrapper; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.ViewManagerRegistry; -import java.util.WeakHashMap; - -/** Class that provides pool for views based on {@link ThemedReactContext}. */ -public final class ContextBasedViewPool implements ViewFactory { - private final WeakHashMap mContextViewPoolHashMap = - new WeakHashMap<>(); - private final ViewManagerRegistry mViewManagerRegistry; - - ContextBasedViewPool(ViewManagerRegistry viewManagerRegistry) { - mViewManagerRegistry = viewManagerRegistry; - } - - @UiThread - void createView(ThemedReactContext context, ReactStylesDiffMap props, String componentName) { - getViewPool(context).createView(componentName, props, null, context); - } - - @UiThread - @Override - public View getOrCreateView( - String componentName, - ReactStylesDiffMap props, - StateWrapper stateWrapper, - ThemedReactContext context) { - return getViewPool(context).getOrCreateView(componentName, props, stateWrapper, context); - } - - @UiThread - @Override - public void recycle(ThemedReactContext context, String componentName, View view) { - getViewPool(context).returnToPool(componentName, view); - } - - @UiThread - private ViewPool getViewPool(ThemedReactContext context) { - ViewPool pool = mContextViewPoolHashMap.get(context); - if (pool == null) { - pool = new ViewPool(mViewManagerRegistry); - mContextViewPoolHashMap.put(context, pool); - } - return pool; - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index e8e3c77b196..8a632c66410 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -42,12 +42,10 @@ public class MountingManager { private final ConcurrentHashMap mTagToViewState; private final ViewManagerRegistry mViewManagerRegistry; private final RootViewManager mRootViewManager = new RootViewManager(); - private final ViewFactory mViewFactory; public MountingManager(ViewManagerRegistry viewManagerRegistry) { mTagToViewState = new ConcurrentHashMap<>(); mViewManagerRegistry = viewManagerRegistry; - mViewFactory = new ViewManagerFactory(viewManagerRegistry); } public void addRootView(int reactRootTag, View rootView) { @@ -89,13 +87,6 @@ public class MountingManager { } mTagToViewState.remove(reactTag); - Context context = view.getContext(); - if (context instanceof ThemedReactContext) { - // We only recycle views that were created by RN (its context is instance of - // ThemedReactContext) - mViewFactory.recycle( - (ThemedReactContext) context, Assertions.assertNotNull(viewManager).getName(), view); - } } @UiThread @@ -193,8 +184,8 @@ public class MountingManager { viewManager = mViewManagerRegistry.get(componentName); // View Managers are responsible for dealing with initial state and props. view = - mViewFactory.getOrCreateView( - componentName, propsDiffMap, stateWrapper, themedReactContext); + viewManager.createView( + themedReactContext, propsDiffMap, stateWrapper, null); view.setId(reactTag); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewFactory.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewFactory.java deleted file mode 100644 index 3fe6a13b4ea..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewFactory.java +++ /dev/null @@ -1,24 +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; - -import android.view.View; -import androidx.annotation.Nullable; -import com.facebook.react.uimanager.ReactStylesDiffMap; -import com.facebook.react.uimanager.StateWrapper; -import com.facebook.react.uimanager.ThemedReactContext; - -public interface ViewFactory { - - View getOrCreateView( - String componentName, - @Nullable ReactStylesDiffMap props, - @Nullable StateWrapper stateWrapper, - ThemedReactContext context); - - void recycle(ThemedReactContext context, String componentName, View view); -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewManagerFactory.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewManagerFactory.java deleted file mode 100644 index 9d01df98d1d..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewManagerFactory.java +++ /dev/null @@ -1,40 +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; - -import android.view.View; -import androidx.annotation.Nullable; -import androidx.annotation.UiThread; -import com.facebook.react.uimanager.ReactStylesDiffMap; -import com.facebook.react.uimanager.StateWrapper; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.ViewManagerRegistry; - -public class ViewManagerFactory implements ViewFactory { - - private ViewManagerRegistry mViewManagerRegistry; - - ViewManagerFactory(ViewManagerRegistry viewManagerRegistry) { - mViewManagerRegistry = viewManagerRegistry; - } - - @UiThread - @Override - public View getOrCreateView( - String componentName, - @Nullable ReactStylesDiffMap props, - @Nullable StateWrapper stateWrapper, - ThemedReactContext context) { - return mViewManagerRegistry.get(componentName).createView(context, props, stateWrapper, null); - } - - @UiThread - @Override - public void recycle(ThemedReactContext context, String componentName, View view) { - // do nothing - } -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewPool.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewPool.java deleted file mode 100644 index efdb8fa30dd..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/ViewPool.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - *

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; - -import android.view.View; -import androidx.annotation.UiThread; -import com.facebook.react.common.ClearableSynchronizedPool; -import com.facebook.react.uimanager.ReactStylesDiffMap; -import com.facebook.react.uimanager.StateWrapper; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.ViewManager; -import com.facebook.react.uimanager.ViewManagerRegistry; -import java.util.HashMap; -import java.util.Map; - -public final class ViewPool { - private static final int POOL_SIZE = 512; - private final Map> mViewPool = new HashMap<>(); - private final ViewManagerRegistry mViewManagerRegistry; - - ViewPool(ViewManagerRegistry viewManagerRegistry) { - mViewManagerRegistry = viewManagerRegistry; - } - - @UiThread - void createView( - String componentName, - ReactStylesDiffMap props, - StateWrapper stateWrapper, - ThemedReactContext context) { - ClearableSynchronizedPool viewPool = getViewPoolForComponent(componentName); - ViewManager viewManager = mViewManagerRegistry.get(componentName); - // TODO: T31905686 Integrate / re-implement jsResponder - View view = viewManager.createView(context, props, stateWrapper, null); - viewPool.release(view); - } - - @UiThread - View getOrCreateView( - String componentName, - ReactStylesDiffMap props, - StateWrapper stateWrapper, - ThemedReactContext context) { - ClearableSynchronizedPool viewPool = getViewPoolForComponent(componentName); - View view = viewPool.acquire(); - if (view == null) { - createView(componentName, props, stateWrapper, context); - view = viewPool.acquire(); - } - return view; - } - - @UiThread - void returnToPool(String componentName, View view) { - ClearableSynchronizedPool viewPool = mViewPool.get(componentName); - if (viewPool != null) { - viewPool.release(view); - } - } - - private ClearableSynchronizedPool getViewPoolForComponent(String componentName) { - ClearableSynchronizedPool viewPool = mViewPool.get(componentName); - if (viewPool == null) { - viewPool = new ClearableSynchronizedPool<>(POOL_SIZE); - mViewPool.put(componentName, viewPool); - } - return viewPool; - } -}