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
This commit is contained in:
David Vacca
2019-07-31 23:30:55 -07:00
committed by Facebook Github Bot
parent 0e8d571298
commit 1054930d45
6 changed files with 2 additions and 213 deletions
@@ -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<UIManager> {
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<UIManager> {
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();
@@ -1,57 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* <p>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<ThemedReactContext, ViewPool> 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;
}
}
@@ -42,12 +42,10 @@ public class MountingManager {
private final ConcurrentHashMap<Integer, ViewState> 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);
}
@@ -1,24 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>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);
}
@@ -1,40 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>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
}
}
@@ -1,73 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* <p>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<String, ClearableSynchronizedPool<View>> mViewPool = new HashMap<>();
private final ViewManagerRegistry mViewManagerRegistry;
ViewPool(ViewManagerRegistry viewManagerRegistry) {
mViewManagerRegistry = viewManagerRegistry;
}
@UiThread
void createView(
String componentName,
ReactStylesDiffMap props,
StateWrapper stateWrapper,
ThemedReactContext context) {
ClearableSynchronizedPool<View> 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<View> 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<View> viewPool = mViewPool.get(componentName);
if (viewPool != null) {
viewPool.release(view);
}
}
private ClearableSynchronizedPool<View> getViewPoolForComponent(String componentName) {
ClearableSynchronizedPool<View> viewPool = mViewPool.get(componentName);
if (viewPool == null) {
viewPool = new ClearableSynchronizedPool<>(POOL_SIZE);
mViewPool.put(componentName, viewPool);
}
return viewPool;
}
}