mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 17:34:07 +08:00
Disable view pooling
Summary: Temporarily disable View Pooling in Fabric Naming of classes will change in the near future Reviewed By: JoshuaGross Differential Revision: D14685009 fbshipit-source-id: 83573dd09af0202a67d0d0aa11e37c1660c3991f
This commit is contained in:
committed by
Facebook Github Bot
parent
8774229f66
commit
02562e51bd
@@ -6,15 +6,14 @@
|
||||
*/
|
||||
package com.facebook.react.fabric.mounting;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import androidx.annotation.UiThread;
|
||||
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 {
|
||||
public final class ContextBasedViewPool implements ViewFactory {
|
||||
private final WeakHashMap<ThemedReactContext, ViewPool> mContextViewPoolHashMap =
|
||||
new WeakHashMap<>();
|
||||
private final ViewManagerRegistry mViewManagerRegistry;
|
||||
@@ -25,19 +24,18 @@ public final class ContextBasedViewPool {
|
||||
|
||||
@UiThread
|
||||
void createView(ThemedReactContext context, String componentName) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
getViewPool(context).createView(componentName, context);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
View getOrCreateView(String componentName, ThemedReactContext context) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
@Override
|
||||
public View getOrCreateView(String componentName, ThemedReactContext context) {
|
||||
return getViewPool(context).getOrCreateView(componentName, context);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void returnToPool(ThemedReactContext context, String componentName, View view) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
@Override
|
||||
public void recycle(ThemedReactContext context, String componentName, View view) {
|
||||
getViewPool(context).returnToPool(componentName, view);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,12 +42,12 @@ public class MountingManager {
|
||||
private final ConcurrentHashMap<Integer, ViewState> mTagToViewState;
|
||||
private final ViewManagerRegistry mViewManagerRegistry;
|
||||
private final RootViewManager mRootViewManager = new RootViewManager();
|
||||
private final ContextBasedViewPool mViewPool;
|
||||
private final ViewFactory mViewFactory;
|
||||
|
||||
public MountingManager(ViewManagerRegistry viewManagerRegistry) {
|
||||
mTagToViewState = new ConcurrentHashMap<>();
|
||||
mViewManagerRegistry = viewManagerRegistry;
|
||||
mViewPool = new ContextBasedViewPool(viewManagerRegistry);
|
||||
mViewFactory = new ViewManagerFactory(viewManagerRegistry);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@@ -91,7 +91,7 @@ public class MountingManager {
|
||||
|
||||
mTagToViewState.remove(reactTag);
|
||||
Context context = view.getContext();
|
||||
mViewPool.returnToPool(
|
||||
mViewFactory.recycle(
|
||||
(ThemedReactContext) context, Assertions.assertNotNull(viewManager).getName(), view);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class MountingManager {
|
||||
|
||||
if (isLayoutable) {
|
||||
viewManager = mViewManagerRegistry.get(componentName);
|
||||
view = mViewPool.getOrCreateView(componentName, themedReactContext);
|
||||
view = mViewFactory.getOrCreateView(componentName, themedReactContext);
|
||||
view.setId(reactTag);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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 com.facebook.react.uimanager.ThemedReactContext;
|
||||
|
||||
public interface ViewFactory {
|
||||
|
||||
View getOrCreateView(String componentName, ThemedReactContext context);
|
||||
|
||||
void recycle(ThemedReactContext context, String componentName, View view);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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 androidx.annotation.UiThread;
|
||||
import android.view.View;
|
||||
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, ThemedReactContext context) {
|
||||
return mViewManagerRegistry.get(componentName).createView(context, null);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public void recycle(ThemedReactContext context, String componentName, View view) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user