@@ -83,6 +83,18 @@ @implementation FlutterPlatformViewsTestMockFlutterPlatformFactory
8383
8484@end
8585
86+ @interface FlutterPlatformViewsTestNilFlutterPlatformFactory : NSObject <FlutterPlatformViewFactory>
87+ @end
88+
89+ @implementation FlutterPlatformViewsTestNilFlutterPlatformFactory
90+ - (NSObject <FlutterPlatformView>*)createWithFrame : (CGRect)frame
91+ viewIdentifier : (int64_t )viewId
92+ arguments : (id _Nullable)args {
93+ return nil ;
94+ }
95+
96+ @end
97+
8698namespace flutter {
8799namespace {
88100class FlutterPlatformViewsTestMockPlatformViewDelegate : public PlatformView ::Delegate {
@@ -3692,6 +3704,73 @@ - (void)testOnlyPlatformViewsAreRemovedWhenReset {
36923704 XCTAssertEqual (flutterView.subviews .firstObject , someView);
36933705}
36943706
3707+ - (void )testNilPlatformViewDoesntCrash {
3708+ flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
3709+
3710+ flutter::TaskRunners runners (/* label=*/ self.name .UTF8String ,
3711+ /* platform=*/ GetDefaultTaskRunner (),
3712+ /* raster=*/ GetDefaultTaskRunner (),
3713+ /* ui=*/ GetDefaultTaskRunner (),
3714+ /* io=*/ GetDefaultTaskRunner ());
3715+ auto flutterPlatformViewsController = std::make_shared<flutter::PlatformViewsController>();
3716+ flutterPlatformViewsController->SetTaskRunner (GetDefaultTaskRunner ());
3717+ auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
3718+ /* delegate=*/ mock_delegate,
3719+ /* rendering_api=*/ mock_delegate.settings_ .enable_impeller
3720+ ? flutter::IOSRenderingAPI::kMetal
3721+ : flutter::IOSRenderingAPI::kSoftware ,
3722+ /* platform_views_controller=*/ flutterPlatformViewsController,
3723+ /* task_runners=*/ runners,
3724+ /* worker_task_runner=*/ nil ,
3725+ /* is_gpu_disabled_jsync_switch=*/ std::make_shared<fml::SyncSwitch>());
3726+
3727+ FlutterPlatformViewsTestNilFlutterPlatformFactory* factory =
3728+ [[FlutterPlatformViewsTestNilFlutterPlatformFactory alloc ] init ];
3729+ flutterPlatformViewsController->RegisterViewFactory (
3730+ factory, @" MockFlutterPlatformView" ,
3731+ FlutterPlatformViewGestureRecognizersBlockingPolicyEager);
3732+ FlutterResult result = ^(id result) {
3733+ };
3734+ flutterPlatformViewsController->OnMethodCall (
3735+ [FlutterMethodCall
3736+ methodCallWithMethodName: @" create"
3737+ arguments: @{@" id" : @2 , @" viewType" : @" MockFlutterPlatformView" }],
3738+ result);
3739+ UIView* flutterView = [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , 500 , 500 )];
3740+ flutterPlatformViewsController->SetFlutterView (flutterView);
3741+
3742+ // Create embedded view params
3743+ flutter::MutatorsStack stack;
3744+ // Layer tree always pushes a screen scale factor to the stack
3745+ SkMatrix screenScaleMatrix =
3746+ SkMatrix::Scale ([UIScreen mainScreen ].scale , [UIScreen mainScreen ].scale );
3747+ stack.PushTransform (screenScaleMatrix);
3748+ // Push a translate matrix
3749+ SkMatrix translateMatrix = SkMatrix::Translate (100 , 100 );
3750+ stack.PushTransform (translateMatrix);
3751+ SkMatrix finalMatrix;
3752+ finalMatrix.setConcat (screenScaleMatrix, translateMatrix);
3753+
3754+ auto embeddedViewParams =
3755+ std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make (300 , 300 ), stack);
3756+
3757+ flutterPlatformViewsController->PrerollCompositeEmbeddedView (2 , std::move (embeddedViewParams));
3758+
3759+ // SKSurface is required if the root FlutterView is present.
3760+ const SkImageInfo image_info = SkImageInfo::MakeN32Premul (1000 , 1000 );
3761+ sk_sp<SkSurface> mock_sk_surface = SkSurfaces::Raster (image_info);
3762+ flutter::SurfaceFrame::FramebufferInfo framebuffer_info;
3763+ auto mock_surface = std::make_unique<flutter::SurfaceFrame>(
3764+ std::move (mock_sk_surface), framebuffer_info,
3765+ [](const flutter::SurfaceFrame& surface_frame, flutter::DlCanvas* canvas) { return true ; },
3766+ [](const flutter::SurfaceFrame& surface_frame) { return true ; },
3767+ /* frame_size=*/ SkISize::Make (800 , 600 ));
3768+
3769+ flutterPlatformViewsController->SubmitFrame (nullptr , nullptr , std::move (mock_surface));
3770+
3771+ XCTAssertEqual (flutterView.subviews .count , 1u );
3772+ }
3773+
36953774- (void )testFlutterTouchInterceptingViewLinksToAccessibilityContainer {
36963775 FlutterTouchInterceptingView* touchInteceptorView = [[FlutterTouchInterceptingView alloc ] init ];
36973776 NSObject * container = [[NSObject alloc ] init ];
0 commit comments