mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Cache ViewManagerDelegate on ViewManagers (#48550)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48550 Cache ViewManagerDelegate on ViewManagers changelog: [internal] internal Reviewed By: javache Differential Revision: D67957883 fbshipit-source-id: 8ec2f34fca04833e391b0bd5b9329cdc9ee12f08
This commit is contained in:
committed by
Facebook GitHub Bot
parent
980458c061
commit
2d320fbd76
+14
-4
@@ -41,6 +41,9 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
|
||||
private static final String NAME = ViewManager.class.getSimpleName();
|
||||
|
||||
private boolean mIsDelegateLoaded = false;
|
||||
private @Nullable ViewManagerDelegate<T> mDelegate = null;
|
||||
|
||||
/**
|
||||
* For View recycling: we store a Stack of unused, dead Views. This is null by default, and when
|
||||
* null signals that View Recycling is disabled. `enableViewRecycling` must be explicitly called
|
||||
@@ -88,7 +91,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* @param props {@link ReactStylesDiffMap} props to update the view with
|
||||
*/
|
||||
public void updateProperties(@NonNull T viewToUpdate, ReactStylesDiffMap props) {
|
||||
final ViewManagerDelegate<T> delegate = getDelegate();
|
||||
final ViewManagerDelegate<T> delegate = getOrCreateViewManagerDelegate();
|
||||
if (delegate != null) {
|
||||
ViewManagerPropertyUpdater.updateProps(delegate, viewToUpdate, props);
|
||||
} else {
|
||||
@@ -109,11 +112,18 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* @return an instance of {@link ViewManagerDelegate} if the props of the view managed by this
|
||||
* view manager should be set via this delegate
|
||||
*/
|
||||
@Nullable
|
||||
protected ViewManagerDelegate<T> getDelegate() {
|
||||
protected @Nullable ViewManagerDelegate<T> getDelegate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private @Nullable ViewManagerDelegate<T> getOrCreateViewManagerDelegate() {
|
||||
if (!mIsDelegateLoaded) {
|
||||
mDelegate = getDelegate();
|
||||
mIsDelegateLoaded = true;
|
||||
}
|
||||
return mDelegate;
|
||||
}
|
||||
|
||||
/** Creates a view with knowledge of props and state. */
|
||||
public @NonNull T createView(
|
||||
int reactTag,
|
||||
@@ -306,7 +316,7 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
* @param args optional arguments for the command
|
||||
*/
|
||||
public void receiveCommand(@NonNull T root, String commandId, @Nullable ReadableArray args) {
|
||||
final ViewManagerDelegate<T> delegate = getDelegate();
|
||||
final ViewManagerDelegate<T> delegate = getOrCreateViewManagerDelegate();
|
||||
if (delegate != null) {
|
||||
delegate.receiveCommand(root, commandId, args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user