Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional logging for deep links methods #120

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions Sources/Deeplink/DeeplinkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -516,22 +532,30 @@ 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.
///
/// - 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
Expand Down
4 changes: 4 additions & 0 deletions Sources/Deeplink/Errors/DeeplinkWarningsError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ internal struct DeeplinkWarningsError: DeeplinkError {
"""
}

internal var isWarning: Bool {
true
}

internal let deeplinkType: Any.Type
internal let warnings: [Error]

Expand Down
14 changes: 5 additions & 9 deletions Sources/Screen/Actions/Modal/ScreenPresentAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
Expand Down
Loading