From 715cb91280e1a539635793f221c8a24e7dd97639 Mon Sep 17 00:00:00 2001 From: Almaz Ibragimov Date: Mon, 27 May 2024 20:29:43 +0300 Subject: [PATCH 1/3] Fixed containerAlreadyPresenting error handing --- .../Screen/Actions/Modal/ScreenPresentAction.swift | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Sources/Screen/Actions/Modal/ScreenPresentAction.swift b/Sources/Screen/Actions/Modal/ScreenPresentAction.swift index cfebe36..eb6fb91 100755 --- a/Sources/Screen/Actions/Modal/ScreenPresentAction.swift +++ b/Sources/Screen/Actions/Modal/ScreenPresentAction.swift @@ -36,18 +36,14 @@ public struct ScreenPresentAction< ) { navigator.logInfo("Presenting \(screen) on \(type(of: container))") - let canPresent = container.presented.map { presented in - presented.isBeingDismissed || presented.modalPresentationStyle == .overCurrentContext - } ?? true - - guard canPresent else { - return completion(.containerAlreadyPresenting(container, for: self)) - } - let presented = screen.build(navigator: navigator) container.present(presented, animated: animated) { - completion(.success(presented)) + if container.presented === presented { + completion(.success(presented)) + } else { + completion(.containerAlreadyPresenting(container, for: self)) + } } } } From 0afd4da91051c6b983d1256cb14e4e4842fca418 Mon Sep 17 00:00:00 2001 From: Timur Shafigullin Date: Tue, 28 May 2024 22:57:02 +0900 Subject: [PATCH 2/3] Add new parameter `shouldLogError` --- Sources/Deeplink/DeeplinkManager.swift | 42 ++++++++++++++++++++------ 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/Sources/Deeplink/DeeplinkManager.swift b/Sources/Deeplink/DeeplinkManager.swift index 72b6e27..e637735 100644 --- a/Sources/Deeplink/DeeplinkManager.swift +++ b/Sources/Deeplink/DeeplinkManager.swift @@ -420,20 +420,27 @@ public final class DeeplinkManager: DeeplinkHandler { /// Handle the URL by a suitable ``URLDeeplink`` and perform navigation, if possible. /// - /// This method does not raise an exception. Instead the error is logged through the navigator. + /// This method does not raise an exception. Instead the error is logged through the navigator if needed. /// - Parameters: /// - url: A URL Scheme or Universal Link from `UIApplicationDelegate` or `UIWindowSceneDelegate`. /// /// - context: Additional context for checking and creating ``URLDeeplink``. /// Must match the context type of ``URLDeeplink/URLContext``. /// + /// - shouldLogError: A Boolean flag indicating whether errors should be logged. The default value is `true`. /// - Returns: `false` if there is no suitable ``URLDeeplink`` to handle the URL; otherwise `true`. @discardableResult - public func handleURLIfPossible(_ url: URL, context: Any?) -> Bool { + public func handleURLIfPossible( + _ url: URL, + context: Any?, + shouldLogError: Bool = true + ) -> Bool { do { return try handleURL(url, context: context) } catch { - navigator.logError(error) + if shouldLogError { + navigator.logError(error) + } } return false @@ -468,19 +475,28 @@ public final class DeeplinkManager: DeeplinkHandler { /// Handle the Notification by a suitable ``NotificationDeeplink`` and perform navigation, if possible. /// - /// This method does not raise an exception. Instead the error is logged through the navigator. + /// This method does not raise an exception. Instead the error is logged through the navigator if needed. /// - Parameters: /// - response: The user’s response to an actionable notification. + /// /// - context: Additional context for checking and creating ``NotificationDeeplink``. /// Must match the context type of ``NotificationDeeplink/NotificationContext``. + /// + /// - shouldLogError: A Boolean flag indicating whether errors should be logged. The default value is `true`. /// - Returns: `false` if there is no suitable ``NotificationDeeplink`` to handle the Notification; /// otherwise `true`. @discardableResult - public func handleNotificationIfPossible(response: UNNotificationResponse, context: Any?) -> Bool { + public func handleNotificationIfPossible( + response: UNNotificationResponse, + context: Any?, + shouldLogError: Bool = true + ) -> Bool { do { return try handleNotification(response: response, context: context) } catch { - navigator.logError(error) + if shouldLogError { + navigator.logError(error) + } } return false @@ -516,7 +532,7 @@ public final class DeeplinkManager: DeeplinkHandler { /// Handle the Notification by a suitable ``NotificationDeeplink`` and perform navigation, if possible. /// - /// This method does not raise an exception. Instead the error is logged through the navigator. + /// This method does not raise an exception. Instead the error is logged through the navigator if needed. /// - Parameters: /// - shortcut: An application shortcut item, also called a *Home screen dynamic quick action*, /// that specifies a user-initiated action for your app. @@ -524,14 +540,22 @@ public final class DeeplinkManager: DeeplinkHandler { /// - context: Additional context for checking and creating ``ShortcutDeeplink``. /// Must match the context type of ``ShortcutDeeplink/ShortcutContext``. /// + /// - shouldLogError: A Boolean flag indicating whether errors should be logged. The default value is `true`. + /// /// - Returns: `false` if there is no suitable ``ShortcutDeeplink`` to handle the Shortcut App; /// otherwise `true`. @discardableResult - public func handleShortcutIfPossible(_ shortcut: UIApplicationShortcutItem, context: Any?) -> Bool { + public func handleShortcutIfPossible( + _ shortcut: UIApplicationShortcutItem, + context: Any?, + shouldLogError: Bool = true + ) -> Bool { do { return try handleShortcut(shortcut, context: context) } catch { - navigator.logError(error) + if shouldLogError { + navigator.logError(error) + } } return false From 5e58bb3d58a4a8e9349bebeb6c7d8aa022162d2b Mon Sep 17 00:00:00 2001 From: Timur Shafigullin Date: Tue, 28 May 2024 22:57:37 +0900 Subject: [PATCH 3/3] Make `DeeplinkWarningsError` to warning --- Sources/Deeplink/Errors/DeeplinkWarningsError.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/Deeplink/Errors/DeeplinkWarningsError.swift b/Sources/Deeplink/Errors/DeeplinkWarningsError.swift index 42dcd04..71dd430 100644 --- a/Sources/Deeplink/Errors/DeeplinkWarningsError.swift +++ b/Sources/Deeplink/Errors/DeeplinkWarningsError.swift @@ -14,6 +14,10 @@ internal struct DeeplinkWarningsError: DeeplinkError { """ } + internal var isWarning: Bool { + true + } + internal let deeplinkType: Any.Type internal let warnings: [Error]