Skip to content

Commit

Permalink
fix iOS TextField Context menu blink bug (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-avdeev-jb authored Jun 29, 2023
1 parent 20bc1d2 commit 5e5ea52
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoUIView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,24 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol,
fun showTextMenu(targetRect: Rect, textActions: TextActions) {
_currentTextMenuActions = textActions
val menu: UIMenuController = UIMenuController.sharedMenuController()
if (menu.isMenuVisible()) {
menu.hideMenu()
}
val cgRect = CGRectMake(
x = targetRect.left.toDouble(),
y = targetRect.top.toDouble(),
width = targetRect.width.toDouble(),
height = targetRect.height.toDouble()
)
menu.showMenuFromView(this, cgRect)
val isTargetVisible = CGRectIntersectsRect(bounds, cgRect)
if (isTargetVisible) {
if (menu.isMenuVisible()) {
menu.setTargetRect(cgRect, this)
} else {
menu.showMenuFromView(this, cgRect)
}
} else {
if (menu.isMenuVisible()) {
menu.hideMenu()
}
}
}

fun hideTextMenu() {
Expand Down

0 comments on commit 5e5ea52

Please sign in to comment.