mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[Android] Make PVC1 and PVC2 share a platform view registry. (#162857)
This avoids the insanity of having to register everything twice. Since the object is shared a registration on pvc1 will automatically apply to pvc2.
This commit is contained in:
parent
6cca066620
commit
53bcdf2cda
@ -32,17 +32,6 @@ class MainActivity : FlutterActivity() {
|
||||
add(NativeDriverSupportPlugin())
|
||||
}
|
||||
|
||||
// TODO(jonahwilliams): make platform view controllers share platform view registry.
|
||||
flutterEngine
|
||||
.platformViewsController2
|
||||
.registry
|
||||
.apply {
|
||||
registerViewFactory("blue_orange_gradient_platform_view", BlueOrangeGradientPlatformViewFactory())
|
||||
registerViewFactory("blue_orange_gradient_surface_view_platform_view", BlueOrangeGradientSurfaceViewPlatformViewFactory())
|
||||
registerViewFactory("changing_color_button_platform_view", ChangingColorButtonPlatformViewFactory())
|
||||
registerViewFactory("box_platform_view", BoxPlatformViewFactory())
|
||||
}
|
||||
|
||||
flutterEngine
|
||||
.platformViewsController
|
||||
.registry
|
||||
|
@ -364,6 +364,7 @@ public class FlutterEngine implements ViewUtils.DisplayUpdater {
|
||||
}
|
||||
|
||||
PlatformViewsController2 platformViewsController2 = new PlatformViewsController2();
|
||||
platformViewsController2.setRegistry(platformViewsController.getRegistry());
|
||||
|
||||
flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
|
||||
flutterJNI.setPlatformViewsController(platformViewsController);
|
||||
|
@ -46,7 +46,7 @@ import java.util.List;
|
||||
public class PlatformViewsController2 implements PlatformViewsAccessibilityDelegate {
|
||||
private static final String TAG = "PlatformViewsController2";
|
||||
|
||||
private final PlatformViewRegistryImpl registry;
|
||||
private PlatformViewRegistryImpl registry;
|
||||
private AndroidTouchProcessor androidTouchProcessor;
|
||||
private Context context;
|
||||
private FlutterView flutterView;
|
||||
@ -65,7 +65,6 @@ public class PlatformViewsController2 implements PlatformViewsAccessibilityDeleg
|
||||
private Surface overlayerSurface = null;
|
||||
|
||||
public PlatformViewsController2() {
|
||||
registry = new PlatformViewRegistryImpl();
|
||||
accessibilityEventsDelegate = new AccessibilityEventsDelegate();
|
||||
platformViews = new SparseArray<>();
|
||||
platformViewParent = new SparseArray<>();
|
||||
@ -74,6 +73,10 @@ public class PlatformViewsController2 implements PlatformViewsAccessibilityDeleg
|
||||
motionEventTracker = MotionEventTracker.getInstance();
|
||||
}
|
||||
|
||||
public void setRegistry(@NonNull PlatformViewRegistry registry) {
|
||||
this.registry = (PlatformViewRegistryImpl) registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesVirtualDisplay(int id) {
|
||||
return false;
|
||||
|
@ -95,7 +95,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void itRemovesPlatformViewBeforeDiposeIsCalled() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
FlutterJNI jni = new FlutterJNI();
|
||||
attach(jni, PlatformViewsController2);
|
||||
// Get the platform view registry.
|
||||
@ -127,7 +129,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void itNotifiesPlatformViewsOfEngineAttachmentAndDetachment() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
FlutterJNI jni = new FlutterJNI();
|
||||
attach(jni, PlatformViewsController2);
|
||||
// Get the platform view registry.
|
||||
@ -165,7 +169,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
public void itUsesActionEventTypeFromFrameworkEventAsActionChanged() {
|
||||
MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
MotionEvent original =
|
||||
MotionEvent.obtain(
|
||||
@ -257,7 +263,9 @@ public class PlatformViewsController2Test {
|
||||
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void getPlatformViewById() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
int platformViewId = 0;
|
||||
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
|
||||
@ -285,7 +293,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void createPlatformViewMessage_initializesAndroidView() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
int platformViewId = 0;
|
||||
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
|
||||
@ -307,7 +317,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void createPlatformViewMessage_setsAndroidViewLayoutDirection() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
int platformViewId = 0;
|
||||
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
|
||||
@ -331,7 +343,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void createPlatformViewMessage_throwsIfViewIsNull() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
int platformViewId = 0;
|
||||
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
|
||||
@ -355,7 +369,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void createHybridPlatformViewMessage_throwsIfViewIsNull() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
int platformViewId = 0;
|
||||
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
|
||||
@ -379,7 +395,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void setPlatformViewDirection_throwIfPlatformViewNotFound() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
int platformViewId = 0;
|
||||
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
|
||||
@ -413,7 +431,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void disposeAndroidView() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
int platformViewId = 0;
|
||||
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
|
||||
@ -454,7 +474,9 @@ public class PlatformViewsController2Test {
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
public void disposeNullAndroidView() {
|
||||
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
|
||||
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
|
||||
PlatformViewsController2.setRegistry(registryImpl);
|
||||
|
||||
int platformViewId = 0;
|
||||
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
|
||||
|
@ -1665,6 +1665,7 @@ public class PlatformViewsControllerTest {
|
||||
platformViewsController.attach(context, registry, executor);
|
||||
|
||||
PlatformViewsController2 secondController = new PlatformViewsController2();
|
||||
secondController.setRegistry(new PlatformViewRegistryImpl());
|
||||
|
||||
final FlutterEngine engine = mock(FlutterEngine.class);
|
||||
when(engine.getRenderer()).thenReturn(new FlutterRenderer(jni));
|
||||
|
Loading…
Reference in New Issue
Block a user