Fix topLeftOffset calculation on iOS in Split View #678
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
ComposeWindow.getTopLeftOffset
return the offset betweenComposeWindow
and the current window, not the current screen, following Skiko's behavior. Before this change, when the application was in the Split View or a Slide Over window (especially when the window is on the right), Composables were not responding to touch events. Also, when the application was in a Slide Over window on the left, Composables slightly off (on the left upper part) from the touch position were responding.Testing
Test: Tested using the Android & iOS template on the following devices:
App.kt
is modified as follows:ContentView.swift
is modified as follows to ensure that this still works even whenComposeWindow
is inserted as a subview.Issues Fixed
Fixes: JetBrains/compose-multiplatform#3100
Run Result
Before the fix (1.4.1):
Before.Physical.Device.mov
After the fix:
After.Physical.Device.mov
Behavior Differences of the Simulator and Physical Devices
The behavior of the simulator and physical devices are different when the application is in the right Split View. On the simulator, the origin of
UIScreen.mainScreen
's coordinate space is at the top center of the screen, while on physical devices, the origin is at the top left corner of the screen. Here's the experiment result with modifiedgetTopLeftOffset
as follows:Physical Device:
Physical.Device.Split.RIght.mp4
Simulator:
Simulator.Split.Right.mov
Due to this, even without this fix, the app responds to touch events normally when on the right Split View on the simulator, while not on physical devices.