-
Notifications
You must be signed in to change notification settings - Fork 294
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
Reland iOS landscape mode support #1974
Conversation
Make sure to run ./maestro-ios-xctest-runner/build-maestro-ios-runner.sh with every swift change |
b654f84
to
8f2a2d6
Compare
The problem is that Plot twist When the iOS simulator's orientation is manually changed (screenshot below), then
XCUIDevice.shared.orientation = .portrait Possible fix 1 If Possible fix 2 Introduce a new |
1cbab3e
to
e9a3b44
Compare
45a17aa
to
806c533
Compare
Good thing 1 is that (from my testing) all iOS (and iPadOS) simulator always startup in portrait orientation, so defaulting to Good thing 2 is that even after I changed orientation of the simulator to portrait and then closed them (and killed |
Demo: demo_2x.mp4 |
a467fdd
to
55a2ce8
Compare
55a2ce8
to
d75bd93
Compare
This was a source of bugs when device orientation changed. AndroidDriver has never cached values, instead it was always requesting them for each new command that used them. Now iOS driver does the same.
…Info() many times
how about option 3 - if it returns unknown, set it to portrait (the difference from that to option 1 is it would correct the behavior from there on, so if there's anything else that requires device orientation, it'd receive the correct value) |
val deviceName: String | ||
get() = driver.name() | ||
|
||
private var _cachedDeviceInfo: DeviceInfo? = null |
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.
aren't these two (this and the original code) functionally the same? My understanding is this is what by lazy
does behind the scenes
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.
It is.
I changed it away from using lazy
because I needed _cachedDeviceInfo
to be a var
instead of val
for $reasons which are no longer valid because I changed the code and forgot to bring it back.
@@ -160,8 +163,10 @@ class Maestro( | |||
} | |||
|
|||
fun swipeFromCenter(swipeDirection: SwipeDirection, durationMs: Long) { | |||
val deviceInfo = deviceInfo() |
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.
this doesnt seem to use the cached info - is that the intent?
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.
Yes.
If we use the cached version, then swipe will completely break if the device is rotated mid-flow (or when running maestro test
in --continuous
mode).
@@ -529,3 +507,14 @@ class IOSDriver( | |||
private const val SCREEN_SETTLE_TIMEOUT_MS: Long = 3000 | |||
} | |||
} | |||
|
|||
private fun Double.asPercentOf(total: Int): Int { |
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.
what's the advantage of this over the regular private functions from before?
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.
Conciseness, mainly.
If I were to keep using widthPercentToPoint(percent: Double)
I'd have to refactor it to widthPercentToPoint(percent: Double, width: Double)
which becomes a bit long and repetitive.
if orientation == .unknown { | ||
// If orientation is "unknown", we assume it is "portrait" to | ||
// work around https://stackoverflow.com/q/78932288/7009800 | ||
return UIDeviceOrientation.portrait |
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.
what would be the implications of setting it to portrait as a side-effect here, when it's unknown?
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.
As of now, I'm not aware of any. See "good things" above.
Updated caveatsConsider this older list of caveats to be out-of-date and not true. Here's the actual list of caveats, as of now:
|
Context for the reviewer:
Driver.deviceInfo()
is being called too many times #2031 which I don't think is worth solving (1) right now and (2) in this specific PR