diff --git a/client/ios/DivKit/DivKitComponents.swift b/client/ios/DivKit/DivKitComponents.swift index 96d5f8b96..89ebe82b9 100644 --- a/client/ios/DivKit/DivKitComponents.swift +++ b/client/ios/DivKit/DivKitComponents.swift @@ -154,26 +154,11 @@ public final class DivKitComponents { self.patchProvider = patchProvider ?? DivPatchDownloader(requestPerformer: requestPerformer) - weak var weakTimerStorage: DivTimerStorage? - weak var weakActionHandler: DivActionHandler? - - #if os(iOS) - self.tooltipManager = tooltipManager ?? DefaultTooltipManager( - shownTooltips: .init(), - handleAction: { - switch $0.payload { - case let .divAction(params: params): - weakActionHandler?.handle(params: params, sender: nil) - default: break - } - } - ) - #else self.tooltipManager = tooltipManager ?? DefaultTooltipManager() - #endif functionsStorage = DivFunctionsStorage(reporter: reporter) + weak var weakTimerStorage: DivTimerStorage? actionHandler = DivActionHandler( stateUpdater: stateManagement, blockStateStorage: blockStateStorage, @@ -213,11 +198,21 @@ public final class DivKitComponents { reporter: reporter ) - weakActionHandler = actionHandler weakTimerStorage = timerStorage variablesStorage.changeEvents.addObserver { [weak self] event in self?.onVariablesChanged(event: event) }.dispose(in: disposePool) + + #if os(iOS) + self.tooltipManager.setHandler { [weak self] in + switch $0.payload { + case let .divAction(params): + self?.actionHandler.handle(params: params, sender: nil) + default: + break + } + } + #endif } public func reset() { diff --git a/client/ios/LayoutKit/Interface/UserInterfaceAction.swift b/client/ios/LayoutKit/Interface/UserInterfaceAction.swift index 235674e42..157455e1a 100644 --- a/client/ios/LayoutKit/Interface/UserInterfaceAction.swift +++ b/client/ios/LayoutKit/Interface/UserInterfaceAction.swift @@ -274,7 +274,7 @@ extension UserInterfaceAction.Payload { public var divActionParams: UserInterfaceAction.DivActionParams? { switch self { - case let .divAction(params: params): + case let .divAction(params): return params case .empty, .menu, .url: return nil diff --git a/client/ios/LayoutKit/LayoutKit/Tooltips/TooltipManager.swift b/client/ios/LayoutKit/LayoutKit/Tooltips/TooltipManager.swift index 6af52bae5..0a000674f 100644 --- a/client/ios/LayoutKit/LayoutKit/Tooltips/TooltipManager.swift +++ b/client/ios/LayoutKit/LayoutKit/Tooltips/TooltipManager.swift @@ -53,9 +53,16 @@ public protocol TooltipManager: AnyObject, TooltipActionPerformer, RenderingDele /// Removes all tooltips. func reset() + + /// Sets handler for the tooltip view UI events. + func setHandler(_ handler: @escaping (UIActionEvent) -> Void) } -public final class DefaultTooltipManager: TooltipManager { +extension TooltipManager { + public func setHandler(_: @escaping (UIActionEvent) -> Void) {} +} + +public class DefaultTooltipManager: TooltipManager { public struct Tooltip { public let id: String public let duration: Duration @@ -64,15 +71,15 @@ public final class DefaultTooltipManager: TooltipManager { public var shownTooltips: Property> - private let handleAction: (UIActionEvent) -> Void + private var handleAction: (UIActionEvent) -> Void private var existingAnchorViews = WeakCollection() private var showingTooltips = [String: TooltipContainerView]() private var tooltipWindow: UIWindow? private var previousOrientation = UIDevice.current.orientation public init( - shownTooltips: Property>, - handleAction: @escaping (UIActionEvent) -> Void + shownTooltips: Property> = Property(), + handleAction: @escaping (UIActionEvent) -> Void = { _ in } ) { self.handleAction = handleAction self.shownTooltips = shownTooltips @@ -140,6 +147,10 @@ public final class DefaultTooltipManager: TooltipManager { tooltipWindow = nil } + public func setHandler(_ handler: @escaping (UIActionEvent) -> Void) { + handleAction = handler + } + deinit { NotificationCenter.default.removeObserver( self,