fix: match the tap hint to the screenshot's orientation - #454
nongvantinh wants to merge 1 commit into
Conversation
When a landscape app is in front, the screenshot is landscape but the screen size mobilecli reports is still the device's natural portrait size, so the hint scaled x and y by different factors and sent taps to the wrong place. Turn the screen size to match the screenshot before working out the ratios. Fixes mobile-next#453
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The orientation-aware tap hint change has no identified merge-blocking issue; it is ready for normal checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Hi! This is a small fix for #453.
What was going on
When a landscape app is in front on a phone that's normally portrait, the screenshot comes back landscape (for example 1024×461), but the screen size from
mobilecli device infois still the phone's natural portrait size (720×1600).describeCoordinateMappingthen scales x and y by very different factors (0.703 and 3.471 here), so an agent that follows the hint taps the wrong spot. Sometimes the spot is off the screen entirely.The fix
Before working out the ratios,
describeCoordinateMappingnow checks whether the screenshot and the reported screen size have the same orientation. If they don't, it swaps the screen's width and height. The screenshot always shows the display as it's rotated right now, and taps land in that rotation's coordinates, so it's the more trustworthy of the two.It compares orientation, not exact sizes, so the existing iOS case (a pixel screenshot of a screen measured in points) keeps working.
Tests
I added four cases to
test/coordinate-mapping.ts:npm run lintandnpm run buildare clean, and all the tests that don't need a device pass locally (68, including the new ones).Checked on a real device
I tried it on a Samsung Galaxy A04 (Android 14) running a landscape-locked Godot game:
Screen coordinates are 1600x720 … multiply its x by 1.563 and y by 1.562.I didn't run the Android device suite in
test/android.ts. It exercises the legacy robot rather than this code, and it changes the phone's rotation setting, which I'd rather not do on a personal phone.What this doesn't touch
The underlying screen size from mobilecli is still the portrait one. So
mobile_get_screen_size,mobile_get_orientation(which says "portrait" here), and aswipe()called without coordinates, which centres on the reported height, probably still see the unrotated values. Fixing that properly probably belongs in mobilecli itself. I kept this PR to the hint so it stays small, but I'm happy to look at the rest separately if that would help.Thanks for taking a look!
Fixes #453