Skip to content
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

Fix IME window insets and view offset when keyboard appears #1199

Merged
merged 16 commits into from
Apr 15, 2024

Conversation

ASalavei
Copy link
Collaborator

@ASalavei ASalavei commented Mar 17, 2024

Proposed Changes

  • Properly handle life cycle of the UIViewComposeSceneLayer. Untie it from the view controller life cycle.
  • Extract keyboard listener to a separate class object.
  • Use ImeWindowInsets class and State<Float> to calculate and pass insets for each individual compose window.

Fixes JetBrains/compose-multiplatform#4016
Fixes JetBrains/compose-multiplatform#4618

# Conflicts:
#	compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/scene/ComposeSceneMediator.uikit.kt
#	compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/scene/UIViewComposeSceneLayer.uikit.kt
@ASalavei
Copy link
Collaborator Author

ASalavei commented Apr 1, 2024

Updates: Keyboard overlapping logic was updated. Also lots of bugs connected with platform layers where fixed. PTAL.

@ASalavei ASalavei mentioned this pull request Apr 4, 2024
@ASalavei ASalavei requested a review from MatkovIvan April 4, 2024 12:34
Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion with @ASalavei we found that the problem is in incorrect coordinates conversion, so it must be fixed instead of introducing a new offset for selection handles.

# Conflicts:
#	compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/scene/ComposeSceneMediator.uikit.kt
Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nitpicks, but looks good overall.

Could you please also add a couple of unit tests to avoid regressions?

Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the code LGTM. But it requires second approval from team mates

animationView.setFrame(animationTargetFrame)
},
completion = { isFinished ->
keyboardDisplayLink.invalidate()
Copy link

@elijah-semyonov elijah-semyonov Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also set keyboardAnimationListener to nil here? Unlike usual target:selector: APIs, CADisplayLink strongly retains its target. Could that lead to a retain-cycle that GC can't break?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's make sense! I added nullification code.

Comment on lines +225 to +226
dispatch_async(dispatch_get_main_queue()) {
keyboardDisplayLink.addToRunLoop(NSRunLoop.mainRunLoop(), NSDefaultRunLoopMode)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can that potentially trigger race condition if for some reason animation at 208 is immediately cancelled for some reason? Its completion handler will execute with displayLink being invalidated, but then the displayLink will be added to runloop after.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting. I checked various scenarios and it looks like everything works pretty fine. Invalidated display ling can be added successfully to run loop with no further effect.

Copy link

@elijah-semyonov elijah-semyonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two mildly suspicious places, but otherwise LGTM.

@ASalavei ASalavei merged commit a6cdcfe into jb-main Apr 15, 2024
6 checks passed
@ASalavei ASalavei deleted the andrei.salavei/fix-ime-windows-insets branch April 15, 2024 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants