Skip to content

Commit

Permalink
Replace modifier specific context providers with a generic (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsanthanam committed Aug 19, 2023
1 parent f5f1075 commit acbcc2b
Showing 1 changed file with 27 additions and 42 deletions.
69 changes: 27 additions & 42 deletions Sources/SafariUI/WebAuthentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public struct WebAuthentication {
context.coordinator.isPresented = isPresented
}

final class Coordinator: NSObject {
final class Coordinator: NSObject, WebAuthenticationCoordinator {
init(parent: Presenter) {
self.parent = parent
}
Expand All @@ -119,7 +119,7 @@ public struct WebAuthentication {
}
}

private lazy var contextProvider = ContextProvider(coordinator: self)
private lazy var contextProvider = ContextProvider<Coordinator>(coordinator: self)

private weak var session: ASWebAuthenticationSession?

Expand All @@ -146,25 +146,6 @@ public struct WebAuthentication {

self.session = session
}

private final class ContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding {

// MARK: - Initializers

init(coordinator: Coordinator) {
self.coordinator = coordinator
}

// MARK: - API

unowned var coordinator: Coordinator

// MARK: - ASWebAuthenticationPresentationContextProviding

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
coordinator.view.window ?? ASPresentationAnchor()
}
}
}
}
}
Expand Down Expand Up @@ -222,7 +203,7 @@ public struct WebAuthentication {
context.coordinator.item = item
}

final class Coordinator: NSObject {
final class Coordinator: NSObject, WebAuthenticationCoordinator {

// MARK: - Initializers

Expand Down Expand Up @@ -252,7 +233,7 @@ public struct WebAuthentication {

// MARK: - Private

private lazy var contextProvider = ContextProvider(coordinator: self)
private lazy var contextProvider = ContextProvider<Coordinator>(coordinator: self)

private weak var session: ASWebAuthenticationSession?

Expand All @@ -279,25 +260,6 @@ public struct WebAuthentication {

self.session = session
}

private final class ContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding {

// MARK: - Initializers

init(coordinator: Coordinator) {
self.coordinator = coordinator
}

// MARK: - API

unowned var coordinator: Coordinator

// MARK: - ASWebAuthenticationPresentationContextProviding

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
coordinator.view.window ?? ASPresentationAnchor()
}
}
}
}
}
Expand Down Expand Up @@ -344,4 +306,27 @@ public struct WebAuthentication {
}
}

private final class ContextProvider<T: WebAuthenticationCoordinator>: NSObject, ASWebAuthenticationPresentationContextProviding {

// MARK: - Initializers

init(coordinator: T) {
self.coordinator = coordinator
}

// MARK: - API

unowned var coordinator: T

// MARK: - ASWebAuthenticationPresentationContextProviding

func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
coordinator.view.window ?? ASPresentationAnchor()
}
}

private protocol WebAuthenticationCoordinator: NSObject {
var view: UIView { get }
}

private struct UnknownError: Error {}

0 comments on commit acbcc2b

Please sign in to comment.