From 5e5ea5204acfa566b6c3e1408823f8fa6c511706 Mon Sep 17 00:00:00 2001 From: "dima.avdeev" <99798741+dima-avdeev-jb@users.noreply.github.com> Date: Thu, 29 Jun 2023 14:02:51 +0300 Subject: [PATCH] fix iOS TextField Context menu blink bug (#735) Issue: https://github.com/JetBrains/compose-multiplatform/issues/3276 --- .../kotlin/org/jetbrains/skiko/SkikoUIView.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoUIView.kt b/skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoUIView.kt index 360eb7dc8..819624d61 100644 --- a/skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoUIView.kt +++ b/skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoUIView.kt @@ -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() {