Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,25 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
17 changes: 13 additions & 4 deletions testing/scenario_app/ios/Scenarios/Scenarios/TextPlatformView.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ @interface TextPlatformView () <TestGestureRecognizerDelegate>
@end

@implementation TextPlatformView {
UIView* _containerView;
UITextView* _textView;
FlutterMethodChannel* _channel;
BOOL _viewCreated;
Expand All @@ -75,18 +76,26 @@ - (instancetype)initWithFrame:(CGRect)frame
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;
Expand All @@ -100,7 +109,7 @@ - (UIView*)view {
abort();
}
_viewCreated = YES;
return _textView;
return _containerView;
}

- (void)platformViewTapped {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,25 @@ - (void)testRejectPolicyUtilTouchesEnded {
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 {
Expand All @@ -59,15 +60,16 @@ - (void)testRejectPolicyEager {
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,
Expand All @@ -76,11 +78,11 @@ - (void)testRejectPolicyEager {
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 {
Expand All @@ -94,26 +96,27 @@ - (void)testAccept {
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");
}

Expand All @@ -128,30 +131,31 @@ - (void)testGestureWithMaskViewBlockingPlatformView {
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");
}

Expand Down
Loading