mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate Android view managers to type-safe commands generated by JS codegen
Summary: ## Changelog: [General] [Changed] - Migrate Android view managers to type-safe commands generated by JS codegen. Reviewed By: JoshuaGross, mdvacca Differential Revision: D21406461 fbshipit-source-id: 93584b240314254675a36a58c4d0c0880d6889fb
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8f90ce26a5
commit
63099c40e6
@@ -38,6 +38,13 @@ public class ReactFeatureFlags {
|
||||
*/
|
||||
public static boolean useViewManagerDelegates = false;
|
||||
|
||||
/**
|
||||
* Should this application use a {@link com.facebook.react.uimanager.ViewManagerDelegate} (if
|
||||
* provided) to execute the view commands. If {@code false}, then {@code receiveCommand} method
|
||||
* inside view manager will be called instead.
|
||||
*/
|
||||
public static boolean useViewManagerDelegatesForCommands = false;
|
||||
|
||||
/**
|
||||
* Should this application use Catalyst Teardown V2? This is an experiment to use a V2 of the
|
||||
* CatalystInstanceImpl `destroy` method.
|
||||
|
||||
@@ -113,4 +113,7 @@ public abstract class BaseViewManagerDelegate<T extends View, U extends BaseView
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveCommand(T view, String commandName, ReadableArray args) {}
|
||||
}
|
||||
|
||||
+8
-1
@@ -29,6 +29,7 @@ import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.RetryableMountingLayerException;
|
||||
import com.facebook.react.bridge.SoftAssertions;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.react.touch.JSResponderHandler;
|
||||
import com.facebook.react.uimanager.layoutanimation.LayoutAnimationController;
|
||||
import com.facebook.react.uimanager.layoutanimation.LayoutAnimationListener;
|
||||
@@ -784,7 +785,13 @@ public class NativeViewHierarchyManager {
|
||||
+ commandId);
|
||||
}
|
||||
ViewManager viewManager = resolveViewManager(reactTag);
|
||||
viewManager.receiveCommand(view, commandId, args);
|
||||
ViewManagerDelegate delegate;
|
||||
if (ReactFeatureFlags.useViewManagerDelegatesForCommands
|
||||
&& (delegate = viewManager.getDelegate()) != null) {
|
||||
delegate.receiveCommand(view, commandId, args);
|
||||
} else {
|
||||
viewManager.receiveCommand(view, commandId, args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,13 +9,17 @@ package com.facebook.react.uimanager;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
|
||||
/**
|
||||
* This is an interface that must be implemented by classes that wish to take over the
|
||||
* responsibility of setting properties of all views managed by the view manager.
|
||||
* responsibility of setting properties of all views managed by the view manager and executing view
|
||||
* commands.
|
||||
*
|
||||
* @param <T> the type of the view supported by this delegate
|
||||
*/
|
||||
public interface ViewManagerDelegate<T extends View> {
|
||||
void setProperty(T view, String propName, @Nullable Object value);
|
||||
|
||||
void receiveCommand(T view, String commandName, ReadableArray args);
|
||||
}
|
||||
|
||||
+4
-3
@@ -47,13 +47,14 @@ public class AndroidDrawerLayoutManagerDelegate<T extends View, U extends BaseVi
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveCommand(AndroidDrawerLayoutManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
|
||||
@Override
|
||||
public void receiveCommand(T view, String commandName, ReadableArray args) {
|
||||
switch (commandName) {
|
||||
case "openDrawer":
|
||||
viewManager.openDrawer(view);
|
||||
mViewManager.openDrawer(view);
|
||||
break;
|
||||
case "closeDrawer":
|
||||
viewManager.closeDrawer(view);
|
||||
mViewManager.closeDrawer(view);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -47,10 +47,11 @@ public class AndroidSwipeRefreshLayoutManagerDelegate<T extends View, U extends
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveCommand(AndroidSwipeRefreshLayoutManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
|
||||
@Override
|
||||
public void receiveCommand(T view, String commandName, ReadableArray args) {
|
||||
switch (commandName) {
|
||||
case "setNativeRefreshing":
|
||||
viewManager.setNativeRefreshing(view, args.getBoolean(0));
|
||||
mViewManager.setNativeRefreshing(view, args.getBoolean(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -56,10 +56,11 @@ public class AndroidSwitchManagerDelegate<T extends View, U extends BaseViewMana
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveCommand(AndroidSwitchManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
|
||||
@Override
|
||||
public void receiveCommand(T view, String commandName, ReadableArray args) {
|
||||
switch (commandName) {
|
||||
case "setNativeValue":
|
||||
viewManager.setNativeValue(view, args.getBoolean(0));
|
||||
mViewManager.setNativeValue(view, args.getBoolean(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -43,13 +43,14 @@ public class AndroidViewPagerManagerDelegate<T extends View, U extends BaseViewM
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveCommand(AndroidViewPagerManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
|
||||
@Override
|
||||
public void receiveCommand(T view, String commandName, ReadableArray args) {
|
||||
switch (commandName) {
|
||||
case "setPage":
|
||||
viewManager.setPage(view, args.getInt(0));
|
||||
mViewManager.setPage(view, args.getInt(0));
|
||||
break;
|
||||
case "setPageWithoutAnimation":
|
||||
viewManager.setPageWithoutAnimation(view, args.getInt(0));
|
||||
mViewManager.setPageWithoutAnimation(view, args.getInt(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,7 +15,6 @@ import com.facebook.react.bridge.ColorPropConverter;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.uimanager.BaseViewManagerDelegate;
|
||||
import com.facebook.react.uimanager.BaseViewManagerInterface;
|
||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||
|
||||
public class SwitchManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & SwitchManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
|
||||
public SwitchManagerDelegate(U viewManager) {
|
||||
@@ -53,10 +52,11 @@ public class SwitchManagerDelegate<T extends View, U extends BaseViewManagerInte
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveCommand(SwitchManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
|
||||
@Override
|
||||
public void receiveCommand(T view, String commandName, ReadableArray args) {
|
||||
switch (commandName) {
|
||||
case "setValue":
|
||||
viewManager.setValue(view, args.getBoolean(0));
|
||||
mViewManager.setValue(view, args.getBoolean(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ public class SwipeRefreshLayoutManager extends ViewGroupManager<ReactSwipeRefres
|
||||
|
||||
@Override
|
||||
public void setNativeRefreshing(ReactSwipeRefreshLayout view, boolean value) {
|
||||
// TODO(T52835863): Implement when view commands start using delegates generated by JS.
|
||||
setRefreshing(view, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -177,7 +177,7 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch>
|
||||
|
||||
@Override
|
||||
public void setNativeValue(ReactSwitch view, boolean value) {
|
||||
// TODO(T52835863): Implement when view commands start using delegates generated by JS.
|
||||
setValueInternal(view, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -160,12 +160,12 @@ public class ReactViewPagerManager extends ViewGroupManager<ReactViewPager>
|
||||
|
||||
@Override
|
||||
public void setPage(ReactViewPager view, int page) {
|
||||
// TODO(T52835863): Implement when view commands start using delegates generated by JS.
|
||||
view.setCurrentItemFromJs(page, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPageWithoutAnimation(ReactViewPager view, int page) {
|
||||
// TODO(T52835863): Implement when view commands start using delegates generated by JS.
|
||||
view.setCurrentItemFromJs(page, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user