From 80187be23491b0093ed95f128b21e7781007887d Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Mon, 22 Jun 2020 16:19:50 +0800 Subject: [PATCH 01/14] [iOS] Fixes accessibilityIdentifier of platform views --- .../darwin/ios/framework/Source/FlutterPlatformViews.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 1b021bc60818d..a224942753a0c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -163,13 +163,13 @@ NSObject* embedded_view = [factory createWithFrame:CGRectZero viewIdentifier:viewId arguments:params]; + UIView* platform_view = [embedded_view view]; // Set a unique view identifier, so the platform view can be identified in unit tests. - [embedded_view view].accessibilityIdentifier = - [NSString stringWithFormat:@"platform_view[%ld]", viewId]; + platform_view.accessibilityIdentifier = [NSString stringWithFormat:@"platform_view[%ld]", viewId]; views_[viewId] = fml::scoped_nsobject>([embedded_view retain]); FlutterTouchInterceptingView* touch_interceptor = [[[FlutterTouchInterceptingView alloc] - initWithEmbeddedView:embedded_view.view + initWithEmbeddedView:platform_view flutterViewController:flutter_view_controller_.get() gestureRecognizersBlockingPolicy:gesture_recognizers_blocking_policies[viewType]] autorelease]; From fd6ac5cc7c52df6dcf5d28780ab81b239b5818c6 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Mon, 22 Jun 2020 19:07:27 +0800 Subject: [PATCH 02/14] Call embedded view only once --- .../darwin/ios/framework/Source/FlutterPlatformViews.mm | 8 +++++++- .../ios/framework/Source/FlutterPlatformViews_Internal.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index a224942753a0c..ff202af0215fd 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -458,7 +458,7 @@ } SkRect FlutterPlatformViewsController::GetPlatformViewRect(int view_id) { - UIView* platform_view = [views_[view_id].get() view]; + UIView* platform_view = [touch_interceptors_[view_id] embeddedView]; UIScreen* screen = [UIScreen mainScreen]; CGRect platform_view_cgrect = [platform_view convertRect:platform_view.bounds toView:flutter_view_]; @@ -732,6 +732,7 @@ - (instancetype)initWithTarget:(id)target @implementation FlutterTouchInterceptingView { fml::scoped_nsobject _delayingRecognizer; FlutterPlatformViewGestureRecognizersBlockingPolicy _blockingPolicy; + UIView* _embeddedView; } - (instancetype)initWithEmbeddedView:(UIView*)embeddedView flutterViewController:(UIViewController*)flutterViewController @@ -740,6 +741,7 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView self = [super initWithFrame:embeddedView.frame]; if (self) { self.multipleTouchEnabled = YES; + _embeddedView = embeddedView; embeddedView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); @@ -761,6 +763,10 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView return self; } +- (UIView*)embeddedView { + return _embeddedView; +} + - (void)releaseGesture { _delayingRecognizer.get().state = UIGestureRecognizerStateFailed; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 8c570cd97cb96..66112faaf12bb 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -31,6 +31,9 @@ // Prevent the touch sequence from ever arriving to the embedded view. - (void)blockGesture; + +// Get embedded view +- (UIView*)embeddedView; @end // The parent view handles clipping to its subviews. From 201a5bc2a110ec660c138a73872325303b933656 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 24 Jun 2020 15:59:46 +0800 Subject: [PATCH 03/14] Fix typo --- flow/embedded_views.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow/embedded_views.h b/flow/embedded_views.h index ddc2153ec6e30..912df00a90ec6 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -123,7 +123,7 @@ class Mutator { // // For example consider the following stack: [T1, T2, T3], where T1 is the top // of the stack and T3 is the bottom of the stack. Applying this mutators stack -// to a platform view P1 will result in T1(T2(T2(P1))). +// to a platform view P1 will result in T1(T2(T3(P1))). class MutatorsStack { public: MutatorsStack() = default; From 639a2bd5a54c15973bc3f7dcc73681b3053d9059 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 13 Oct 2020 10:21:34 +0800 Subject: [PATCH 04/14] sync again --- .../ios/framework/Source/FlutterPlatformViews_Internal.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index e91475f31569c..f928031a32c28 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -43,9 +43,6 @@ // The `path` is transformed with the `matrix` before adding to the queue. - (void)clipPath:(const SkPath&)path matrix:(const CATransform3D&)matrix; -// Prevent the touch sequence from ever arriving to the embedded view. -- (void)blockGesture; - // Get embedded view - (UIView*)embeddedView; @end From 77ab7aa474c1fdfe8dd6a1fc5e99f2a7202c63e7 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 13 Oct 2020 10:32:28 +0800 Subject: [PATCH 05/14] Sync again --- .../ios/framework/Source/FlutterPlatformViews_Internal.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index f928031a32c28..676fc777a0b14 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -43,8 +43,6 @@ // The `path` is transformed with the `matrix` before adding to the queue. - (void)clipPath:(const SkPath&)path matrix:(const CATransform3D&)matrix; -// Get embedded view -- (UIView*)embeddedView; @end // The parent view handles clipping to its subviews. @@ -327,6 +325,9 @@ class FlutterPlatformViewsController { // Prevent the touch sequence from ever arriving to the embedded view. - (void)blockGesture; + +// Get embedded view +- (UIView*)embeddedView; @end #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_ From 06d7083102650c5c0e95b76f44286d4ae339abff Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 14 Oct 2020 10:55:18 +0800 Subject: [PATCH 06/14] Add check when get platform view --- .../platform/darwin/ios/framework/Source/FlutterPlatformViews.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index d70f27be616d3..090134ee2a252 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -158,6 +158,7 @@ viewIdentifier:viewId arguments:params]; UIView* platform_view = [embedded_view view]; + FML_DCHECK(platform_view == [embedded_view view]) << "The [view] method of FlutterPlatformView should not return a new instance of UIView during the same frame."; // Set a unique view identifier, so the platform view can be identified in unit tests. platform_view.accessibilityIdentifier = [NSString stringWithFormat:@"platform_view[%ld]", viewId]; views_[viewId] = fml::scoped_nsobject>([embedded_view retain]); From 75ed5e70cae0ab9b6e159964bc0df96fe4f5484c Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 15 Oct 2020 09:54:30 +0800 Subject: [PATCH 07/14] Using DCheck instead --- .../darwin/ios/framework/Source/FlutterPlatformViews.mm | 8 +------- .../ios/framework/Source/FlutterPlatformViews_Internal.h | 3 --- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 090134ee2a252..b2cfd9d588db3 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -449,7 +449,7 @@ } SkRect FlutterPlatformViewsController::GetPlatformViewRect(int view_id) { - UIView* platform_view = [touch_interceptors_[view_id] embeddedView]; + UIView* platform_view = [views_[view_id].get() view]; UIScreen* screen = [UIScreen mainScreen]; CGRect platform_view_cgrect = [platform_view convertRect:platform_view.bounds toView:flutter_view_]; @@ -732,7 +732,6 @@ - (instancetype)initWithTarget:(id)target @implementation FlutterTouchInterceptingView { fml::scoped_nsobject _delayingRecognizer; FlutterPlatformViewGestureRecognizersBlockingPolicy _blockingPolicy; - UIView* _embeddedView; } - (instancetype)initWithEmbeddedView:(UIView*)embeddedView platformViewsController: @@ -742,7 +741,6 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView self = [super initWithFrame:embeddedView.frame]; if (self) { self.multipleTouchEnabled = YES; - _embeddedView = embeddedView; embeddedView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); @@ -764,10 +762,6 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView return self; } -- (UIView*)embeddedView { - return _embeddedView; -} - - (void)releaseGesture { _delayingRecognizer.get().state = UIGestureRecognizerStateFailed; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 676fc777a0b14..4fcaaf3874212 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -325,9 +325,6 @@ class FlutterPlatformViewsController { // Prevent the touch sequence from ever arriving to the embedded view. - (void)blockGesture; - -// Get embedded view -- (UIView*)embeddedView; @end #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_ From fff8d8dca0ce770eb90b17851d26c2b32d491eae Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 22 Oct 2020 10:24:52 +0800 Subject: [PATCH 08/14] Apply review --- .../framework/Source/FlutterPlatformViews.mm | 13 ++-- .../Source/FlutterPlatformViewsTest.mm | 72 +++++++++++++++++++ .../Source/FlutterPlatformViews_Internal.h | 7 +- .../ios/framework/Source/SemanticsObject.mm | 2 +- 4 files changed, 87 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index b2cfd9d588db3..66383549e0b83 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -158,7 +158,6 @@ viewIdentifier:viewId arguments:params]; UIView* platform_view = [embedded_view view]; - FML_DCHECK(platform_view == [embedded_view view]) << "The [view] method of FlutterPlatformView should not return a new instance of UIView during the same frame."; // Set a unique view identifier, so the platform view can be identified in unit tests. platform_view.accessibilityIdentifier = [NSString stringWithFormat:@"platform_view[%ld]", viewId]; views_[viewId] = fml::scoped_nsobject>([embedded_view retain]); @@ -312,11 +311,11 @@ views_to_recomposite_.insert(view_id); } -NSObject* FlutterPlatformViewsController::GetPlatformViewByID(int view_id) { +UIView* FlutterPlatformViewsController::GetPlatformViewByID(int view_id) { if (views_.empty()) { return nil; } - return views_[view_id].get(); + return [touch_interceptors_[view_id].get() embeddedView]; } std::vector FlutterPlatformViewsController::GetCurrentCanvases() { @@ -449,7 +448,7 @@ } SkRect FlutterPlatformViewsController::GetPlatformViewRect(int view_id) { - UIView* platform_view = [views_[view_id].get() view]; + UIView* platform_view = GetPlatformViewByID(view_id); UIScreen* screen = [UIScreen mainScreen]; CGRect platform_view_cgrect = [platform_view convertRect:platform_view.bounds toView:flutter_view_]; @@ -732,6 +731,7 @@ - (instancetype)initWithTarget:(id)target @implementation FlutterTouchInterceptingView { fml::scoped_nsobject _delayingRecognizer; FlutterPlatformViewGestureRecognizersBlockingPolicy _blockingPolicy; + UIView* _embeddedView; } - (instancetype)initWithEmbeddedView:(UIView*)embeddedView platformViewsController: @@ -741,6 +741,7 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView self = [super initWithFrame:embeddedView.frame]; if (self) { self.multipleTouchEnabled = YES; + _embeddedView = embeddedView; embeddedView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); @@ -762,6 +763,10 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView return self; } +- (UIView*)embeddedView { + return [[_embeddedView retain] autorelease]; +} + - (void)releaseGesture { _delayingRecognizer.get().state = UIGestureRecognizerStateFailed; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 283a86cf2ae46..b5f04f8e6f5df 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -17,6 +17,7 @@ @class FlutterPlatformViewsTestMockPlatformView; static FlutterPlatformViewsTestMockPlatformView* gMockPlatformView = nil; const float kFloatCompareEpsilon = 0.001; +BOOL enableViewCreateOnceCheck = NO; @interface FlutterPlatformViewsTestMockPlatformView : UIView @end @@ -50,6 +51,21 @@ - (instancetype)init { return self; } +- (UIView*)view { + [self checkViewCreatedOnce]; + return _view; +} + +- (void)checkViewCreatedOnce { + if (enableViewCreateOnceCheck) { + static bool created = false; + if (created) { + abort(); + } + created = true; + } +} + - (void)dealloc { [_view release]; _view = nil; @@ -113,6 +129,62 @@ @interface FlutterPlatformViewsTest : XCTestCase @implementation FlutterPlatformViewsTest +- (void)testFlutterViewOnlyCreateOnceInOneFrame { + enableViewCreateOnceCheck = YES; + 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 platform_view = std::make_unique( + /*delegate=*/mock_delegate, + /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*task_runners=*/runners); + + auto flutterPlatformViewsController = std::make_unique(); + + FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = + [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; + flutterPlatformViewsController->RegisterViewFactory( + factory, @"MockFlutterPlatformView", + FlutterPlatformViewGestureRecognizersBlockingPolicyEager); + FlutterResult result = ^(id result) { + }; + flutterPlatformViewsController->OnMethodCall( + [FlutterMethodCall + methodCallWithMethodName:@"create" + arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}], + result); + UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; + flutterPlatformViewsController->SetFlutterView(mockFlutterView); + // Create embedded view params + flutter::MutatorsStack stack; + // Layer tree always pushes a screen scale factor to the stack + SkMatrix screenScaleMatrix = + SkMatrix::MakeScale([UIScreen mainScreen].scale, [UIScreen mainScreen].scale); + stack.PushTransform(screenScaleMatrix); + // Push a translate matrix + SkMatrix translateMatrix = SkMatrix::MakeTrans(100, 100); + stack.PushTransform(translateMatrix); + SkMatrix finalMatrix; + finalMatrix.setConcat(screenScaleMatrix, translateMatrix); + + auto embeddedViewParams = + std::make_unique(finalMatrix, SkSize::Make(300, 300), stack); + + flutterPlatformViewsController->PrerollCompositeEmbeddedView(2, std::move(embeddedViewParams)); + flutterPlatformViewsController->CompositeEmbeddedView(2); + + flutterPlatformViewsController->GetPlatformViewRect(2); + + XCTAssertNotNil(gMockPlatformView); + + flutterPlatformViewsController->Reset(); + enableViewCreateOnceCheck = NO; +} + - (void)testCanCreatePlatformViewWithoutFlutterView { flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 4fcaaf3874212..42ed2a204bdcb 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -149,12 +149,12 @@ class FlutterPlatformViewsController { void PrerollCompositeEmbeddedView(int view_id, std::unique_ptr params); - // Returns the `FlutterPlatformView` object associated with the view_id. + // Returns the `FlutterPlatformView`'s `view` object associated with the view_id. // // If the `FlutterPlatformViewsController` does not contain any `FlutterPlatformView` object or // a `FlutterPlatformView` object asscociated with the view_id cannot be found, the method // returns nil. - NSObject* GetPlatformViewByID(int view_id); + UIView* GetPlatformViewByID(int view_id); PostPrerollResult PostPrerollAction(fml::RefPtr raster_thread_merger); @@ -325,6 +325,9 @@ class FlutterPlatformViewsController { // Prevent the touch sequence from ever arriving to the embedded view. - (void)blockGesture; + +// Get embedded view +- (UIView*)embeddedView; @end #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_ diff --git a/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm b/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm index d41f0a40aee6f..d54edc9a3dde1 100644 --- a/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm +++ b/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm @@ -560,7 +560,7 @@ - (instancetype)initWithSemanticsObject:(SemanticsObject*)object { flutter::FlutterPlatformViewsController* controller = object.bridge->GetPlatformViewsController(); if (controller) { - _platformView = [[controller->GetPlatformViewByID(object.node.platformViewId) view] retain]; + _platformView = [controller->GetPlatformViewByID(object.node.platformViewId) retain]; } } return self; From ef4c9ae02206c04e1ac6c166579eb5cded50e547 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 11 Nov 2020 14:28:16 +0800 Subject: [PATCH 09/14] Update tests --- .../framework/Source/FlutterPlatformViewsTest.mm | 13 ++++--------- .../ios/Scenarios/Scenarios/TextPlatformView.m | 5 +++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index b5f04f8e6f5df..3402cafa392b3 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -17,7 +17,6 @@ @class FlutterPlatformViewsTestMockPlatformView; static FlutterPlatformViewsTestMockPlatformView* gMockPlatformView = nil; const float kFloatCompareEpsilon = 0.001; -BOOL enableViewCreateOnceCheck = NO; @interface FlutterPlatformViewsTestMockPlatformView : UIView @end @@ -40,6 +39,7 @@ - (void)dealloc { @interface FlutterPlatformViewsTestMockFlutterPlatformView : NSObject @property(nonatomic, strong) UIView* view; +@property(nonatomic, assign) BOOL viewCreated; @end @implementation FlutterPlatformViewsTestMockFlutterPlatformView @@ -57,13 +57,10 @@ - (UIView*)view { } - (void)checkViewCreatedOnce { - if (enableViewCreateOnceCheck) { - static bool created = false; - if (created) { - abort(); - } - created = true; + if (self.viewCreated) { + abort(); } + self.viewCreated = YES; } - (void)dealloc { @@ -130,7 +127,6 @@ @interface FlutterPlatformViewsTest : XCTestCase @implementation FlutterPlatformViewsTest - (void)testFlutterViewOnlyCreateOnceInOneFrame { - enableViewCreateOnceCheck = YES; flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); flutter::TaskRunners runners(/*label=*/self.name.UTF8String, @@ -182,7 +178,6 @@ - (void)testFlutterViewOnlyCreateOnceInOneFrame { XCTAssertNotNil(gMockPlatformView); flutterPlatformViewsController->Reset(); - enableViewCreateOnceCheck = NO; } - (void)testCanCreatePlatformViewWithoutFlutterView { diff --git a/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m b/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m index e01bca6c61e67..89d3b1d136bba 100644 --- a/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m +++ b/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m @@ -67,6 +67,7 @@ @interface TextPlatformView () @implementation TextPlatformView { UITextView* _textView; FlutterMethodChannel* _channel; + BOOL _viewCreated; } - (instancetype)initWithFrame:(CGRect)frame @@ -92,6 +93,10 @@ - (instancetype)initWithFrame:(CGRect)frame } - (UIView*)view { + if (_viewCreated) { + abort(); + } + _viewCreated = YES; return _textView; } From 049bfafeb8f01b0bcfe04ab303dd257fbfb33ffc Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Fri, 13 Nov 2020 09:47:51 +0800 Subject: [PATCH 10/14] Init boolean explicity and add comment --- .../darwin/ios/framework/Source/FlutterPlatformViewsTest.mm | 1 + .../scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m | 3 +++ 2 files changed, 4 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 3402cafa392b3..18ee424f3ed34 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -47,6 +47,7 @@ @implementation FlutterPlatformViewsTestMockFlutterPlatformView - (instancetype)init { if (self = [super init]) { _view = [[FlutterPlatformViewsTestMockPlatformView alloc] init]; + _viewCreated = NO; } return self; } diff --git a/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m b/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m index 89d3b1d136bba..26568c3a7129f 100644 --- a/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m +++ b/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m @@ -88,11 +88,14 @@ - (instancetype)initWithFrame:(CGRect)frame [_textView addGestureRecognizer:gestureRecognizer]; gestureRecognizer.testTapGestureRecognizerDelegate = self; _textView.accessibilityLabel = @""; + + _viewCreated = NO; } return self; } - (UIView*)view { + // Engine should only call me once in my lifecycle. if (_viewCreated) { abort(); } From 2f7141d8dbe0c105205a4d8b80b8e475a464dd24 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Fri, 13 Nov 2020 20:01:29 +0800 Subject: [PATCH 11/14] Update comment --- testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m b/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m index 26568c3a7129f..c80ac8b40ba9a 100644 --- a/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m +++ b/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m @@ -95,7 +95,7 @@ - (instancetype)initWithFrame:(CGRect)frame } - (UIView*)view { - // Engine should only call me once in my lifecycle. + // Makes sure the engine only calls this method once. if (_viewCreated) { abort(); } From 22e559c225ac1e24c1ba61bff710e1b2c38da53d Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Sat, 14 Nov 2020 07:21:02 +0800 Subject: [PATCH 12/14] Format --- testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m b/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m index c80ac8b40ba9a..84c6a1691d931 100644 --- a/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m +++ b/testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m @@ -88,7 +88,7 @@ - (instancetype)initWithFrame:(CGRect)frame [_textView addGestureRecognizer:gestureRecognizer]; gestureRecognizer.testTapGestureRecognizerDelegate = self; _textView.accessibilityLabel = @""; - + _viewCreated = NO; } return self; From 9a5e0b04e460f4bfd5ac6c5d0c814ba2b2c2a31f Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 17 Nov 2020 11:07:30 +0800 Subject: [PATCH 13/14] Fixes CI failure --- .../darwin/ios/framework/Source/FlutterPlatformViewsTest.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index ce74023ee70a3..8b2dcf554df1f 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -129,9 +129,11 @@ - (void)testFlutterViewOnlyCreateOnceInOneFrame { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + auto flutterPlatformViewsController = std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); auto flutterPlatformViewsController = std::make_unique(); From 6991cb147a5a811302f722569c2c7d56bbeb337b Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Tue, 17 Nov 2020 12:11:12 +0800 Subject: [PATCH 14/14] Fixes CI break --- .../darwin/ios/framework/Source/FlutterPlatformViewsTest.mm | 2 -- 1 file changed, 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 8b2dcf554df1f..8ba26f776a1c2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -136,8 +136,6 @@ - (void)testFlutterViewOnlyCreateOnceInOneFrame { /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - auto flutterPlatformViewsController = std::make_unique(); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory(