Add warning message when PlatformView's origin is not 0 (flutter/engine#35501)

This commit is contained in:
Chris Yang
2022-08-29 12:51:16 -07:00
committed by GitHub
parent 2853e8da60
commit 8e1a4eebed
15 changed files with 117 additions and 78 deletions

View File

@@ -454,7 +454,25 @@ void FlutterPlatformViewsController::ApplyMutators(const MutatorsStack& mutators
void FlutterPlatformViewsController::CompositeWithParams(int view_id,
const EmbeddedViewParams& params) {
CGRect frame = CGRectMake(0, 0, params.sizePoints().width(), params.sizePoints().height());
UIView* touchInterceptor = touch_interceptors_[view_id].get();
FlutterTouchInterceptingView* touchInterceptor = touch_interceptors_[view_id].get();
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
FML_DCHECK(CGPointEqualToPoint([touchInterceptor embeddedView].frame.origin, CGPointZero));
if (non_zero_origin_views_.find(view_id) == non_zero_origin_views_.end() &&
!CGPointEqualToPoint([touchInterceptor embeddedView].frame.origin, CGPointZero)) {
non_zero_origin_views_.insert(view_id);
NSLog(
@"A Embedded PlatformView's origin is not CGPointZero.\n"
" View id: %@\n"
" View info: \n %@ \n"
"A non-zero origin might cause undefined behavior.\n"
"See https://github.com/flutter/flutter/issues/109700 for more details.\n"
"If you are the author of the PlatformView, please update the implementation of the "
"PlatformView to have a (0, 0) origin.\n"
"If you have a valid case of using a non-zero origin, "
"please leave a comment at https://github.com/flutter/flutter/issues/109700 with details.",
@(view_id), [touchInterceptor embeddedView]);
}
#endif
touchInterceptor.layer.transform = CATransform3DIdentity;
touchInterceptor.frame = frame;
touchInterceptor.alpha = 1;

View File

@@ -307,6 +307,14 @@ class FlutterPlatformViewsController {
// WeakPtrFactory must be the last member.
std::unique_ptr<fml::WeakPtrFactory<FlutterPlatformViewsController>> weak_factory_;
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
// A set to keep track of embedded views that does not have (0, 0) origin.
// An insertion triggers a warning message about non-zero origin logged on the debug console.
// See https://github.com/flutter/flutter/issues/109700 for details.
std::unordered_set<int64_t> non_zero_origin_views_;
#endif
FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewsController);
};

View File

@@ -65,6 +65,7 @@
@end
@implementation TextPlatformView {
UIView* _containerView;
UITextView* _textView;
FlutterMethodChannel* _channel;
BOOL _viewCreated;
@@ -75,18 +76,26 @@
arguments:(id _Nullable)args
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
if ([super init]) {
_textView = [[UITextView alloc] initWithFrame:CGRectMake(50.0, 50.0, 250.0, 100.0)];
_textView.textColor = UIColor.blueColor;
_containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 100)];
_containerView.backgroundColor = UIColor.lightGrayColor;
_containerView.clipsToBounds = YES;
_containerView.accessibilityIdentifier = @"platform_view";
_textView = [[UITextView alloc] initWithFrame:CGRectMake(50.0, 50.0, 250, 100)];
_textView.backgroundColor = UIColor.lightGrayColor;
_textView.textColor = UIColor.blueColor;
[_textView setFont:[UIFont systemFontOfSize:52]];
_textView.text = args;
_textView.accessibilityIdentifier = @"platform_view";
_textView.autoresizingMask =
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[_containerView addSubview:_textView];
TestTapGestureRecognizer* gestureRecognizer =
[[TestTapGestureRecognizer alloc] initWithTarget:self action:@selector(platformViewTapped)];
[_textView addGestureRecognizer:gestureRecognizer];
gestureRecognizer.testTapGestureRecognizerDelegate = self;
_textView.accessibilityLabel = @"";
_viewCreated = NO;
@@ -100,7 +109,7 @@
abort();
}
_viewCreated = YES;
return _textView;
return _containerView;
}
- (void)platformViewTapped {

View File

@@ -28,24 +28,25 @@ static const NSInteger kSecondsToWaitForPlatformView = 30;
XCUIElement* element = evaluatedObject;
return [element.identifier hasPrefix:@"platform_view"];
}];
XCUIElement* platformView = [app.textViews elementMatchingPredicate:predicateToFindPlatformView];
if (![platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
XCUIElement* textView =
[app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
NSLog(@"%@", app.debugDescription);
XCTFail(@"Failed due to not able to find any platformView with %@ seconds",
XCTFail(@"Failed due to not able to find any textView with %@ seconds",
@(kSecondsToWaitForPlatformView));
}
XCTAssertNotNil(platformView);
XCTAssertEqualObjects(platformView.label, @"");
XCTAssertNotNil(textView);
XCTAssertEqualObjects(textView.label, @"");
NSPredicate* predicate =
[NSPredicate predicateWithFormat:@"label == %@", @"-gestureTouchesBegan-gestureTouchesEnded"];
XCTNSPredicateExpectation* exception =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:platformView];
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
[platformView tap];
[textView tap];
[self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
XCTAssertEqualObjects(platformView.label, @"-gestureTouchesBegan-gestureTouchesEnded");
XCTAssertEqualObjects(textView.label, @"-gestureTouchesBegan-gestureTouchesEnded");
}
- (void)testRejectPolicyEager {
@@ -59,15 +60,16 @@ static const NSInteger kSecondsToWaitForPlatformView = 30;
XCUIElement* element = evaluatedObject;
return [element.identifier hasPrefix:@"platform_view"];
}];
XCUIElement* platformView = [app.textViews elementMatchingPredicate:predicateToFindPlatformView];
if (![platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
XCUIElement* textView =
[app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
NSLog(@"%@", app.debugDescription);
XCTFail(@"Failed due to not able to find any platformView with %@ seconds",
XCTFail(@"Failed due to not able to find any textView with %@ seconds",
@(kSecondsToWaitForPlatformView));
}
XCTAssertNotNil(platformView);
XCTAssertEqualObjects(platformView.label, @"");
XCTAssertNotNil(textView);
XCTAssertEqualObjects(textView.label, @"");
NSPredicate* predicate =
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
@@ -76,11 +78,11 @@ static const NSInteger kSecondsToWaitForPlatformView = 30;
return [view.label containsString:@"-gestureTouchesBegan"];
}];
XCTNSPredicateExpectation* exception =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:platformView];
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
[platformView tap];
[textView tap];
[self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
XCTAssertTrue([platformView.label containsString:@"-gestureTouchesBegan"]);
XCTAssertTrue([textView.label containsString:@"-gestureTouchesBegan"]);
}
- (void)testAccept {
@@ -94,26 +96,27 @@ static const NSInteger kSecondsToWaitForPlatformView = 30;
XCUIElement* element = evaluatedObject;
return [element.identifier hasPrefix:@"platform_view"];
}];
XCUIElement* platformView = [app.textViews elementMatchingPredicate:predicateToFindPlatformView];
if (![platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
XCUIElement* textView =
[app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
NSLog(@"%@", app.debugDescription);
XCTFail(@"Failed due to not able to find any platformView with %@ seconds",
XCTFail(@"Failed due to not able to find any textView with %@ seconds",
@(kSecondsToWaitForPlatformView));
}
XCTAssertNotNil(platformView);
XCTAssertEqualObjects(platformView.label, @"");
XCTAssertNotNil(textView);
XCTAssertEqualObjects(textView.label, @"");
NSPredicate* predicate = [NSPredicate
predicateWithFormat:@"label == %@",
@"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped"];
XCTNSPredicateExpectation* exception =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:platformView];
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
[platformView tap];
[textView tap];
[self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
XCTAssertEqualObjects(platformView.label,
XCTAssertEqualObjects(textView.label,
@"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped");
}
@@ -128,30 +131,31 @@ static const NSInteger kSecondsToWaitForPlatformView = 30;
XCUIElement* element = evaluatedObject;
return [element.identifier hasPrefix:@"platform_view"];
}];
XCUIElement* platformView = [app.textViews elementMatchingPredicate:predicateToFindPlatformView];
if (![platformView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
XCUIElement* textView =
[app.otherElements elementMatchingPredicate:predicateToFindPlatformView].textViews.firstMatch;
if (![textView waitForExistenceWithTimeout:kSecondsToWaitForPlatformView]) {
NSLog(@"%@", app.debugDescription);
XCTFail(@"Failed due to not able to find any platformView with %@ seconds",
@(kSecondsToWaitForPlatformView));
}
XCTAssertNotNil(platformView);
XCTAssertEqualObjects(platformView.label, @"");
XCTAssertNotNil(textView);
XCTAssertEqualObjects(textView.label, @"");
NSPredicate* predicate = [NSPredicate
predicateWithFormat:@"label == %@",
@"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped"];
XCTNSPredicateExpectation* exception =
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:platformView];
[[XCTNSPredicateExpectation alloc] initWithPredicate:predicate object:textView];
XCUICoordinate* coordinate =
[self getNormalizedCoordinate:app
point:CGVectorMake(platformView.frame.origin.x + 10,
platformView.frame.origin.y + 10)];
point:CGVectorMake(textView.frame.origin.x + 10,
textView.frame.origin.y + 10)];
[coordinate tap];
[self waitForExpectations:@[ exception ] timeout:kSecondsToWaitForPlatformView];
XCTAssertEqualObjects(platformView.label,
XCTAssertEqualObjects(textView.label,
@"-gestureTouchesBegan-gestureTouchesEnded-platformViewTapped");
}

View File

@@ -27,10 +27,10 @@ static const CGFloat kCompareAccuracy = 0.001;
@[ @"--platform-view-no-overlay-intersection", @"--enable-software-rendering" ];
[app launch];
XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
XCUIElement* platform_view = app.otherElements[@"platform_view[0]"];
XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
XCTAssertEqual(platform_view.frame.origin.x, 25);
XCTAssertEqual(platform_view.frame.origin.y, 25);
XCTAssertEqual(platform_view.frame.origin.x, 0);
XCTAssertEqual(platform_view.frame.origin.y, 0);
XCTAssertEqual(platform_view.frame.size.width, 250);
XCTAssertEqual(platform_view.frame.size.height, 250);
@@ -49,10 +49,10 @@ static const CGFloat kCompareAccuracy = 0.001;
app.launchArguments = @[ @"--platform-view" ];
[app launch];
XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
XCUIElement* platform_view = app.otherElements[@"platform_view[0]"];
XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
XCTAssertEqual(platform_view.frame.origin.x, 25);
XCTAssertEqual(platform_view.frame.origin.y, 25);
XCTAssertEqual(platform_view.frame.origin.x, 0);
XCTAssertEqual(platform_view.frame.origin.y, 0);
XCTAssertEqual(platform_view.frame.size.width, 250);
XCTAssertEqual(platform_view.frame.size.height, 250);
@@ -83,20 +83,20 @@ static const CGFloat kCompareAccuracy = 0.001;
app.launchArguments = @[ @"--platform-view-partial-intersection" ];
[app launch];
XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
XCUIElement* platform_view = app.otherElements[@"platform_view[0]"];
XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
XCTAssertEqual(platform_view.frame.origin.x, 25);
XCTAssertEqual(platform_view.frame.origin.y, 25);
XCTAssertEqual(platform_view.frame.origin.x, 0);
XCTAssertEqual(platform_view.frame.origin.y, 0);
XCTAssertEqual(platform_view.frame.size.width, 250);
XCTAssertEqual(platform_view.frame.size.height, 250);
XCUIElement* overlay = app.otherElements[@"platform_view[0].overlay[0]"];
XCTAssertTrue(overlay.exists);
XCTAssertEqual(overlay.frame.origin.x, 200);
XCTAssertEqual(overlay.frame.origin.y, 250);
XCTAssertEqual(overlay.frame.origin.y, 245);
XCTAssertEqual(overlay.frame.size.width, 50);
// Half the height of the overlay.
XCTAssertEqual(overlay.frame.size.height, 25);
XCTAssertEqual(overlay.frame.size.height, 5);
XCUIElement* overlayView = app.otherElements[@"platform_view[0].overlay_view[0]"];
XCTAssertTrue(overlayView.exists);
@@ -120,10 +120,10 @@ static const CGFloat kCompareAccuracy = 0.001;
app.launchArguments = @[ @"--platform-view-two-intersecting-overlays" ];
[app launch];
XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
XCUIElement* platform_view = app.otherElements[@"platform_view[0]"];
XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
XCTAssertEqual(platform_view.frame.origin.x, 25);
XCTAssertEqual(platform_view.frame.origin.y, 25);
XCTAssertEqual(platform_view.frame.origin.x, 0);
XCTAssertEqual(platform_view.frame.origin.y, 0);
XCTAssertEqual(platform_view.frame.size.width, 250);
XCTAssertEqual(platform_view.frame.size.height, 250);
@@ -149,10 +149,10 @@ static const CGFloat kCompareAccuracy = 0.001;
app.launchArguments = @[ @"--platform-view-one-overlay-two-intersecting-overlays" ];
[app launch];
XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
XCUIElement* platform_view = app.otherElements[@"platform_view[0]"];
XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
XCTAssertEqual(platform_view.frame.origin.x, 25);
XCTAssertEqual(platform_view.frame.origin.y, 25);
XCTAssertEqual(platform_view.frame.origin.x, 0);
XCTAssertEqual(platform_view.frame.origin.y, 0);
XCTAssertEqual(platform_view.frame.size.width, 250);
XCTAssertEqual(platform_view.frame.size.height, 250);
@@ -168,7 +168,7 @@ static const CGFloat kCompareAccuracy = 0.001;
XCTAssertEqual(overlay2.frame.origin.x, 75);
XCTAssertEqual(overlay2.frame.origin.y, 225);
XCTAssertEqual(overlay2.frame.size.width, 50);
XCTAssertEqual(overlay2.frame.size.height, 50);
XCTAssertEqual(overlay2.frame.size.height, 25);
XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"];
XCTAssertTrue(overlayView0.exists);
@@ -201,17 +201,17 @@ static const CGFloat kCompareAccuracy = 0.001;
app.launchArguments = @[ @"--platform-view-multiple-without-overlays" ];
[app launch];
XCUIElement* platform_view1 = app.textViews[@"platform_view[0]"];
XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"];
XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]);
XCTAssertEqual(platform_view1.frame.origin.x, 25);
XCTAssertEqual(platform_view1.frame.origin.y, 325);
XCTAssertEqual(platform_view1.frame.origin.x, 0);
XCTAssertEqual(platform_view1.frame.origin.y, 300);
XCTAssertEqual(platform_view1.frame.size.width, 250);
XCTAssertEqual(platform_view1.frame.size.height, 250);
XCUIElement* platform_view2 = app.textViews[@"platform_view[1]"];
XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"];
XCTAssertTrue(platform_view2.exists);
XCTAssertEqual(platform_view2.frame.origin.x, 25);
XCTAssertEqual(platform_view2.frame.origin.y, 25);
XCTAssertEqual(platform_view2.frame.origin.x, 0);
XCTAssertEqual(platform_view2.frame.origin.y, 0);
XCTAssertEqual(platform_view2.frame.size.width, 250);
XCTAssertEqual(platform_view2.frame.size.height, 250);
@@ -233,32 +233,32 @@ static const CGFloat kCompareAccuracy = 0.001;
app.launchArguments = @[ @"--platform-view-multiple-background-foreground" ];
[app launch];
XCUIElement* platform_view1 = app.textViews[@"platform_view[0]"];
XCUIElement* platform_view1 = app.otherElements[@"platform_view[0]"];
XCTAssertTrue([platform_view1 waitForExistenceWithTimeout:1.0]);
XCTAssertEqual(platform_view1.frame.origin.x, 50);
XCTAssertEqual(platform_view1.frame.origin.y, 325);
XCTAssertEqual(platform_view1.frame.origin.x, 25);
XCTAssertEqual(platform_view1.frame.origin.y, 300);
XCTAssertEqual(platform_view1.frame.size.width, 250);
XCTAssertEqual(platform_view1.frame.size.height, 250);
XCUIElement* platform_view2 = app.textViews[@"platform_view[1]"];
XCUIElement* platform_view2 = app.otherElements[@"platform_view[1]"];
XCTAssertTrue(platform_view2.exists);
XCTAssertEqual(platform_view2.frame.origin.x, 50);
XCTAssertEqual(platform_view2.frame.origin.y, 25);
XCTAssertEqual(platform_view2.frame.origin.x, 25);
XCTAssertEqual(platform_view2.frame.origin.y, 0);
XCTAssertEqual(platform_view2.frame.size.width, 250);
XCTAssertEqual(platform_view2.frame.size.height, 250);
XCUIElement* overlay1 = app.otherElements[@"platform_view[0].overlay[0]"];
XCTAssertTrue(overlay1.exists);
XCTAssertEqual(overlay1.frame.origin.x, 50);
XCTAssertEqual(overlay1.frame.origin.y, 325);
XCTAssertEqual(overlay1.frame.size.width, 200);
XCTAssertEqual(overlay1.frame.size.height, 175);
XCTAssertEqual(overlay1.frame.origin.x, 25);
XCTAssertEqual(overlay1.frame.origin.y, 300);
XCTAssertEqual(overlay1.frame.size.width, 225);
XCTAssertEqual(overlay1.frame.size.height, 200);
XCUIElement* overlay2 = app.otherElements[@"platform_view[1].overlay[0]"];
XCTAssertTrue(overlay2.exists);
XCTAssertEqual(overlay2.frame.origin.x, 50);
XCTAssertEqual(overlay2.frame.origin.y, 25);
XCTAssertEqual(overlay2.frame.size.width, 200);
XCTAssertEqual(overlay2.frame.origin.x, 25);
XCTAssertEqual(overlay2.frame.origin.y, 0);
XCTAssertEqual(overlay2.frame.size.width, 225);
XCTAssertEqual(overlay2.frame.size.height, 250);
XCUIElement* overlayView0 = app.otherElements[@"platform_view[0].overlay_view[0]"];
@@ -293,10 +293,10 @@ static const CGFloat kCompareAccuracy = 0.001;
app.launchArguments = @[ @"--platform-view-max-overlays" ];
[app launch];
XCUIElement* platform_view = app.textViews[@"platform_view[0]"];
XCUIElement* platform_view = app.otherElements[@"platform_view[0]"];
XCTAssertTrue([platform_view waitForExistenceWithTimeout:1.0]);
XCTAssertEqual(platform_view.frame.origin.x, 25);
XCTAssertEqual(platform_view.frame.origin.y, 25);
XCTAssertEqual(platform_view.frame.origin.x, 0);
XCTAssertEqual(platform_view.frame.origin.y, 0);
XCTAssertEqual(platform_view.frame.size.width, 250);
XCTAssertEqual(platform_view.frame.size.height, 250);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

@@ -177,7 +177,7 @@ class PlatformViewPartialIntersectionScenario extends Scenario
finishBuilder(
builder,
overlayOffset: const Offset(150, 250),
overlayOffset: const Offset(150, 240),
);
}
}