-
Notifications
You must be signed in to change notification settings - Fork 648
feat: target the currentDisplayId display with W3C actions #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ce34bf2
d8cf1b8
35d9e85
4f152bc
5505557
e1b1bda
05636fb
1070044
3eb77b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| #import "FBMacros.h" | ||
| #import "FBMathUtils.h" | ||
| #import "FBProtocolHelpers.h" | ||
| #import "FBScreen.h" | ||
| #import "FBW3CActionsHelpers.h" | ||
| #import "FBXCodeCompatibility.h" | ||
| #import "FBXCTestDaemonsProxy.h" | ||
|
|
@@ -28,6 +29,7 @@ | |
| #import "XCSynthesizedEventRecord.h" | ||
| #import "XCPointerEventPath.h" | ||
| #import "XCPointerEvent.h" | ||
| #import "XCUIScreen.h" | ||
|
|
||
|
|
||
| static NSString *const FB_KEY_TYPE = @"type"; | ||
|
|
@@ -849,9 +851,35 @@ @implementation FBW3CActionsSynthesizer | |
|
|
||
| - (nullable XCSynthesizedEventRecord *)synthesizeWithError:(NSError **)error | ||
| { | ||
| XCSynthesizedEventRecord *eventRecord = [[XCSynthesizedEventRecord alloc] | ||
| initWithName:@"W3C Touch Action" | ||
| interfaceOrientation:self.application.interfaceOrientation]; | ||
| XCUIScreen *screen = [FBScreen currentScreenWithError:error]; | ||
| if (nil == screen) { | ||
| return nil; | ||
| } | ||
| XCSynthesizedEventRecord *eventRecord; | ||
| CGVector displayCorrection = CGVectorMake(0, 0); | ||
| if (screen.isMainScreen) { | ||
| eventRecord = [[XCSynthesizedEventRecord alloc] initWithName:@"W3C Touch Action" | ||
| interfaceOrientation:self.application.interfaceOrientation]; | ||
| } else { | ||
| if (![XCSynthesizedEventRecord instancesRespondToSelector:@selector(initWithName:displayID:interfaceOrientation:)]) { | ||
| if (error) { | ||
| *error = [[FBErrorBuilder.builder | ||
| withDescription:@"Actions on a display other than the main one are not supported by this XCTest version"] build]; | ||
| } | ||
| return nil; | ||
| } | ||
| eventRecord = [[XCSynthesizedEventRecord alloc] initWithName:@"W3C Touch Action" | ||
| displayID:(unsigned long long)screen.displayID | ||
| interfaceOrientation:self.application.interfaceOrientation]; | ||
| // XCUICoordinate.screenPoint uses the main display's size when rotating | ||
| // coordinates. Selecting an event display does not change that transform; | ||
| // compensate for the difference before dispatching to the selected display. | ||
| XCUIScreen *mainScreen = XCUIScreen.mainScreen; | ||
| displayCorrection = FBDisplayCoordinateOffset( | ||
| CGSizeMake(mainScreen.bounds.size.width / mainScreen.scale, mainScreen.bounds.size.height / mainScreen.scale), | ||
| CGSizeMake(screen.bounds.size.width / screen.scale, screen.bounds.size.height / screen.scale), | ||
| eventRecord.interfaceOrientation); | ||
| } | ||
| NSMutableDictionary<NSString *, NSDictionary<NSString *, id> *> *actionsMapping = [NSMutableDictionary new]; | ||
| NSMutableArray<NSString *> *actionIds = [NSMutableArray new]; | ||
| for (NSDictionary<NSString *, id> *action in self.actions) { | ||
|
|
@@ -893,6 +921,12 @@ - (nullable XCSynthesizedEventRecord *)synthesizeWithError:(NSError **)error | |
| return nil; | ||
| } | ||
| for (XCPointerEventPath *eventPath in eventPaths) { | ||
| if (displayCorrection.dx != 0 || displayCorrection.dy != 0) { | ||
| for (XCPointerEvent *pointerEvent in eventPath.pointerEvents) { | ||
| CGPoint point = pointerEvent.coordinate; | ||
| pointerEvent.coordinate = CGPointMake(point.x + displayCorrection.dx, point.y + displayCorrection.dy); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Avoid correcting coordinates already transformed for the secondary display This adds the main-to-secondary offset to every pointer event, including element-origin actions whose coordinates are already transformed for the selected display. In Xcode 27.1, I verified the transform using the installed XCTest framework with mocked display metadata: with main size 402×874 and secondary size 669×951, the secondary snapshot transforms (100, 100) to (569, 100) in landscape-right; this correction then shifts it to (836, 100). This was framework-level verification, not an end-to-end device run. Please derive the correction from each coordinate's source display and add secondary-display element-origin coverage. The added integration tests currently exercise viewport origins only. |
||
| } | ||
| } | ||
| [eventRecord addPointerEventPath:eventPath]; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this correction is needed? shouldn't xctest automatically adjust coordinates?