From 48314835c1542ed8d48323bc690f88d45033efa5 Mon Sep 17 00:00:00 2001 From: just-software-dev Date: Tue, 10 Dec 2024 16:14:14 -0300 Subject: [PATCH] [trello.com/c/mJMhirqv] Incorrect position fix --- .../AdvancedContextMenuManager.swift | 11 ++++++++++- .../Implementation/ContextMenuOverlayViewModel.swift | 2 ++ .../Implementation/OverlayViewDelegate.swift | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/AdvancedContextMenuManager.swift b/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/AdvancedContextMenuManager.swift index e1164be2c..0ca2e8529 100644 --- a/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/AdvancedContextMenuManager.swift +++ b/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/AdvancedContextMenuManager.swift @@ -188,8 +188,17 @@ private extension AdvancedContextMenuManager { } // MARK: Delegate - + extension AdvancedContextMenuManager: OverlayViewDelegate { + func willDissmis() { + guard + let newPosition = getPositionOnScreen?(), + newPosition != locationOnScreen + else { return } + + viewModel?.update(locationOnScreen: newPosition) + } + func didDissmis() { didDismissMenuAction?(messageId) getPositionOnScreen = nil diff --git a/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/Implementation/ContextMenuOverlayViewModel.swift b/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/Implementation/ContextMenuOverlayViewModel.swift index 815fd1cef..721e2bf6d 100644 --- a/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/Implementation/ContextMenuOverlayViewModel.swift +++ b/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/Implementation/ContextMenuOverlayViewModel.swift @@ -62,6 +62,8 @@ final class ContextMenuOverlayViewModel: ObservableObject { } @MainActor func dismiss() async { + delegate?.willDissmis() + await animate(duration: animationDuration) { self.additionalMenuVisible.toggle() } diff --git a/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/Implementation/OverlayViewDelegate.swift b/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/Implementation/OverlayViewDelegate.swift index 4c143ff71..00eb7c087 100644 --- a/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/Implementation/OverlayViewDelegate.swift +++ b/pckg/AdvancedContextMenuKit/Sources/AdvancedContextMenuKit/Implementation/OverlayViewDelegate.swift @@ -9,6 +9,7 @@ import Foundation @MainActor protocol OverlayViewDelegate: AnyObject { + func willDissmis() func didDissmis() func didAppear() }