Skip to content

Commit 53bcdf2

Browse files
author
Jonah Williams
authored
[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.
1 parent 6cca066 commit 53bcdf2

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

dev/integration_tests/android_engine_test/android/app/src/main/kotlin/com/example/native_driver_test/MainActivity.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@ class MainActivity : FlutterActivity() {
3232
add(NativeDriverSupportPlugin())
3333
}
3434

35-
// TODO(jonahwilliams): make platform view controllers share platform view registry.
36-
flutterEngine
37-
.platformViewsController2
38-
.registry
39-
.apply {
40-
registerViewFactory("blue_orange_gradient_platform_view", BlueOrangeGradientPlatformViewFactory())
41-
registerViewFactory("blue_orange_gradient_surface_view_platform_view", BlueOrangeGradientSurfaceViewPlatformViewFactory())
42-
registerViewFactory("changing_color_button_platform_view", ChangingColorButtonPlatformViewFactory())
43-
registerViewFactory("box_platform_view", BoxPlatformViewFactory())
44-
}
45-
4635
flutterEngine
4736
.platformViewsController
4837
.registry

engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ public FlutterEngine(
364364
}
365365

366366
PlatformViewsController2 platformViewsController2 = new PlatformViewsController2();
367+
platformViewsController2.setRegistry(platformViewsController.getRegistry());
367368

368369
flutterJNI.addEngineLifecycleListener(engineLifecycleListener);
369370
flutterJNI.setPlatformViewsController(platformViewsController);

engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController2.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
public class PlatformViewsController2 implements PlatformViewsAccessibilityDelegate {
4747
private static final String TAG = "PlatformViewsController2";
4848

49-
private final PlatformViewRegistryImpl registry;
49+
private PlatformViewRegistryImpl registry;
5050
private AndroidTouchProcessor androidTouchProcessor;
5151
private Context context;
5252
private FlutterView flutterView;
@@ -65,7 +65,6 @@ public class PlatformViewsController2 implements PlatformViewsAccessibilityDeleg
6565
private Surface overlayerSurface = null;
6666

6767
public PlatformViewsController2() {
68-
registry = new PlatformViewRegistryImpl();
6968
accessibilityEventsDelegate = new AccessibilityEventsDelegate();
7069
platformViews = new SparseArray<>();
7170
platformViewParent = new SparseArray<>();
@@ -74,6 +73,10 @@ public PlatformViewsController2() {
7473
motionEventTracker = MotionEventTracker.getInstance();
7574
}
7675

76+
public void setRegistry(@NonNull PlatformViewRegistry registry) {
77+
this.registry = (PlatformViewRegistryImpl) registry;
78+
}
79+
7780
@Override
7881
public boolean usesVirtualDisplay(int id) {
7982
return false;

engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsController2Test.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ public void onFlutterViewDetached() {
9595
@Test
9696
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
9797
public void itRemovesPlatformViewBeforeDiposeIsCalled() {
98+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
9899
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
100+
PlatformViewsController2.setRegistry(registryImpl);
99101
FlutterJNI jni = new FlutterJNI();
100102
attach(jni, PlatformViewsController2);
101103
// Get the platform view registry.
@@ -127,7 +129,9 @@ public PlatformView create(Context context, int viewId, Object args) {
127129
@Test
128130
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
129131
public void itNotifiesPlatformViewsOfEngineAttachmentAndDetachment() {
132+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
130133
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
134+
PlatformViewsController2.setRegistry(registryImpl);
131135
FlutterJNI jni = new FlutterJNI();
132136
attach(jni, PlatformViewsController2);
133137
// Get the platform view registry.
@@ -165,7 +169,9 @@ public PlatformView create(Context context, int viewId, Object args) {
165169
@Test
166170
public void itUsesActionEventTypeFromFrameworkEventAsActionChanged() {
167171
MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
172+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
168173
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
174+
PlatformViewsController2.setRegistry(registryImpl);
169175

170176
MotionEvent original =
171177
MotionEvent.obtain(
@@ -257,7 +263,9 @@ private MotionEvent makePlatformViewTouchAndInvokeToMotionEvent(
257263

258264
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
259265
public void getPlatformViewById() {
266+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
260267
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
268+
PlatformViewsController2.setRegistry(registryImpl);
261269

262270
int platformViewId = 0;
263271
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
@@ -285,7 +293,9 @@ public void getPlatformViewById() {
285293
@Test
286294
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
287295
public void createPlatformViewMessage_initializesAndroidView() {
296+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
288297
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
298+
PlatformViewsController2.setRegistry(registryImpl);
289299

290300
int platformViewId = 0;
291301
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
@@ -307,7 +317,9 @@ public void createPlatformViewMessage_initializesAndroidView() {
307317
@Test
308318
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
309319
public void createPlatformViewMessage_setsAndroidViewLayoutDirection() {
320+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
310321
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
322+
PlatformViewsController2.setRegistry(registryImpl);
311323

312324
int platformViewId = 0;
313325
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
@@ -331,7 +343,9 @@ public void createPlatformViewMessage_setsAndroidViewLayoutDirection() {
331343
@Test
332344
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
333345
public void createPlatformViewMessage_throwsIfViewIsNull() {
346+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
334347
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
348+
PlatformViewsController2.setRegistry(registryImpl);
335349

336350
int platformViewId = 0;
337351
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
@@ -355,7 +369,9 @@ public void createPlatformViewMessage_throwsIfViewIsNull() {
355369
@Test
356370
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
357371
public void createHybridPlatformViewMessage_throwsIfViewIsNull() {
372+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
358373
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
374+
PlatformViewsController2.setRegistry(registryImpl);
359375

360376
int platformViewId = 0;
361377
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
@@ -379,7 +395,9 @@ public void createHybridPlatformViewMessage_throwsIfViewIsNull() {
379395
@Test
380396
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
381397
public void setPlatformViewDirection_throwIfPlatformViewNotFound() {
398+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
382399
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
400+
PlatformViewsController2.setRegistry(registryImpl);
383401

384402
int platformViewId = 0;
385403
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
@@ -413,7 +431,9 @@ public void setPlatformViewDirection_throwIfPlatformViewNotFound() {
413431
@Test
414432
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
415433
public void disposeAndroidView() {
434+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
416435
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
436+
PlatformViewsController2.setRegistry(registryImpl);
417437

418438
int platformViewId = 0;
419439
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));
@@ -454,7 +474,9 @@ public void disposeAndroidView() {
454474
@Test
455475
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
456476
public void disposeNullAndroidView() {
477+
PlatformViewRegistryImpl registryImpl = new PlatformViewRegistryImpl();
457478
PlatformViewsController2 PlatformViewsController2 = new PlatformViewsController2();
479+
PlatformViewsController2.setRegistry(registryImpl);
458480

459481
int platformViewId = 0;
460482
assertNull(PlatformViewsController2.getPlatformViewById(platformViewId));

engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@ public void scheduleFrame() {}
16651665
platformViewsController.attach(context, registry, executor);
16661666

16671667
PlatformViewsController2 secondController = new PlatformViewsController2();
1668+
secondController.setRegistry(new PlatformViewRegistryImpl());
16681669

16691670
final FlutterEngine engine = mock(FlutterEngine.class);
16701671
when(engine.getRenderer()).thenReturn(new FlutterRenderer(jni));

0 commit comments

Comments
 (0)