[PlatformViewsController] Clear root_views_ in Reset (flutter/engine#22403)
This commit is contained in:
@@ -438,11 +438,7 @@ void FlutterPlatformViewsController::Reset() {
|
||||
for (UIView* sub_view in [flutter_view subviews]) {
|
||||
[sub_view removeFromSuperview];
|
||||
}
|
||||
// See: https://github.com/flutter/flutter/issues/69305
|
||||
for (auto it = touch_interceptors_.begin(); it != touch_interceptors_.end(); it++) {
|
||||
FlutterTouchInterceptingView* view = it->second.get();
|
||||
[view removeFromSuperview];
|
||||
}
|
||||
root_views_.clear();
|
||||
touch_interceptors_.clear();
|
||||
views_.clear();
|
||||
composition_order_.clear();
|
||||
|
||||
@@ -658,6 +658,58 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
|
||||
flutterPlatformViewsController->Reset();
|
||||
}
|
||||
|
||||
- (void)
|
||||
testFlutterPlatformViewControllerResetDeallocsPlatformViewWhenRootViewsNotBindedToFlutterView {
|
||||
flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate;
|
||||
auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest");
|
||||
flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
|
||||
/*platform=*/thread_task_runner,
|
||||
/*raster=*/thread_task_runner,
|
||||
/*ui=*/thread_task_runner,
|
||||
/*io=*/thread_task_runner);
|
||||
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
|
||||
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
|
||||
/*delegate=*/mock_delegate,
|
||||
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
|
||||
/*ios_surface_factory=*/surface_factory,
|
||||
/*task_runners=*/runners);
|
||||
|
||||
auto flutterPlatformViewsController =
|
||||
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
|
||||
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
|
||||
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
|
||||
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
|
||||
|
||||
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
|
||||
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
|
||||
flutterPlatformViewsController->RegisterViewFactory(
|
||||
factory, @"MockFlutterPlatformView",
|
||||
FlutterPlatformViewGestureRecognizersBlockingPolicyEager);
|
||||
FlutterResult result = ^(id result) {
|
||||
};
|
||||
// autorelease pool to trigger an autorelease for all the root_views_ and touch_interceptors_.
|
||||
@autoreleasepool {
|
||||
flutterPlatformViewsController->OnMethodCall(
|
||||
[FlutterMethodCall
|
||||
methodCallWithMethodName:@"create"
|
||||
arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}],
|
||||
result);
|
||||
|
||||
flutter::MutatorsStack stack;
|
||||
SkMatrix finalMatrix;
|
||||
auto embeddedViewParams =
|
||||
std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack);
|
||||
flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams));
|
||||
flutterPlatformViewsController->CompositeEmbeddedView(2);
|
||||
// Not calling |flutterPlatformViewsController::SubmitFrame| so that the platform views are not
|
||||
// added to flutter_view_.
|
||||
|
||||
XCTAssertNotNil(gMockPlatformView);
|
||||
flutterPlatformViewsController->Reset();
|
||||
}
|
||||
XCTAssertNil(gMockPlatformView);
|
||||
}
|
||||
|
||||
- (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view {
|
||||
unsigned char pixel[4] = {0};
|
||||
|
||||
|
||||
@@ -210,8 +210,8 @@ class FlutterPlatformViewsController {
|
||||
std::map<std::string, fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>> factories_;
|
||||
std::map<int64_t, fml::scoped_nsobject<NSObject<FlutterPlatformView>>> views_;
|
||||
std::map<int64_t, fml::scoped_nsobject<FlutterTouchInterceptingView>> touch_interceptors_;
|
||||
// Mapping a platform view ID to the top most parent view (root_view) who is a direct child to
|
||||
// the `flutter_view_`.
|
||||
// Mapping a platform view ID to the top most parent view (root_view) of a platform view. In
|
||||
// |SubmitFrame|, root_views_ are added to flutter_view_ as child views.
|
||||
//
|
||||
// The platform view with the view ID is a child of the root view; If the platform view is not
|
||||
// clipped, and no clipping view is added, the root view will be the intercepting view.
|
||||
|
||||
Reference in New Issue
Block a user