Skip to content

Commit

Permalink
Add preliminary web authentication support
Browse files Browse the repository at this point in the history
  • Loading branch information
vsanthanam committed Aug 19, 2023
1 parent ab10291 commit d452b48
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 4 deletions.
2 changes: 0 additions & 2 deletions Sources/SafariUI/DismissButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,5 @@ public extension SafariView {
case .cancel: return .cancel
}
}

}

}
13 changes: 13 additions & 0 deletions Sources/SafariUI/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ extension EnvironmentValues {
set { self[SafariViewDismissButtonStyleEnvironmentKey.self] = newValue }
}

var webAuthenticationPrefersEphemeralWebBrowserSession: Bool {
get { self[WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey.self] }
set { self[WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey.self] = newValue }
}

}

private struct SafariViewEntersReaderIfAvailableEnvironmentKey: EnvironmentKey {
Expand Down Expand Up @@ -162,3 +167,11 @@ private struct SafariViewExcludedActivityTypesEnvironmentKey: EnvironmentKey {
static let defaultValue: Value = .default

}

private struct WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey: EnvironmentKey {

typealias Value = Bool

static let defaultValue: Bool = false

}
28 changes: 27 additions & 1 deletion Sources/SafariUI/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ public extension View {
return ModifiedContent(content: self, modifier: modifier)
}

func webAuthenticationPrefersEphemeralWebBrowserSession(_ prefersEphemeralWebBrowserSession: Bool = true) -> some View {
let modifer = WebAuthenticationPrefersEphemeralWebBrowserSessionModifier(prefersEphemeralWebBrowserSession: prefersEphemeralWebBrowserSession)
return ModifiedContent(content: self, modifier: modifer)
}

}

private struct SafariViewEntersReaderIfAvailableModifier: ViewModifier {
Expand Down Expand Up @@ -343,7 +348,7 @@ private struct SafariViewExcludedActivityTypesModifier: ViewModifier {
self.activityTypes = activityTypes
}

// MARK: - ViewBuilder
// MARK: - ViewModifier

@ViewBuilder
func body(content: Content) -> some View {
Expand All @@ -356,3 +361,24 @@ private struct SafariViewExcludedActivityTypesModifier: ViewModifier {
private let activityTypes: SafariView.ExcludedActivityTypes

}

private struct WebAuthenticationPrefersEphemeralWebBrowserSessionModifier: ViewModifier {

// MARK: - Initializers

init(prefersEphemeralWebBrowserSession: Bool) {
self.prefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession
}

// MARK: - ViewModifier

@ViewBuilder
func body(content: Content) -> some View {
content
.environment(\.webAuthenticationPrefersEphemeralWebBrowserSession, prefersEphemeralWebBrowserSession)
}

// MARK: - Private

private let prefersEphemeralWebBrowserSession: Bool
}
12 changes: 12 additions & 0 deletions Sources/SafariUI/Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,15 @@ public extension View {
)
}
}

public extension View {

func webAuthentication<Item>(
_ item: Binding<Item?>,
webAuthentication: @escaping (Item) -> WebAuthentication
) -> some View where Item: Identifiable {
let modifier = WebAuthentication.IdentifiableItemModitifer(item: item, build: webAuthentication)
return ModifiedContent(content: self, modifier: modifier)
}

}
2 changes: 1 addition & 1 deletion Sources/SafariUI/SafariView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public struct SafariView: View {

}

private extension UIView {
extension UIView {

var controller: UIViewController? {
if let nextResponder = next as? UIViewController {
Expand Down
Loading

0 comments on commit d452b48

Please sign in to comment.