From 3dc0534ed26dc65a7601186638eadca3087b14f3 Mon Sep 17 00:00:00 2001 From: Varun Santhanam Date: Sat, 19 Aug 2023 14:51:01 -0700 Subject: [PATCH] Split SafariView and WebAuthentication into separate packages --- Package.swift | 17 ++++++ .../SafariUI.docc/ExcludedActivityTypes.md | 6 +- .../SafariUI.docc/IncludedActivities.md | 6 +- Sources/SafariUI/SafariUI.docc/View.md | 12 ++-- Sources/SafariUI/SafariUI.swift | 29 ++++++++++ .../DismissButtonStyle.swift | 0 .../Environment.swift | 13 ----- .../ExcludedActivityTypes.swift | 0 .../IncludedActivities.swift | 0 .../{SafariUI => SafariView}/Modifiers.swift | 26 --------- .../Presentation.swift | 29 ---------- .../PrewarmingToken.swift | 0 .../{SafariUI => SafariView}/SafariView.swift | 0 Sources/WebAuthentication/Environment.swift | 43 ++++++++++++++ Sources/WebAuthentication/Modifiers.swift | 56 +++++++++++++++++++ Sources/WebAuthentication/Presentation.swift | 55 ++++++++++++++++++ .../WebAuthentication.swift | 0 17 files changed, 212 insertions(+), 80 deletions(-) create mode 100644 Sources/SafariUI/SafariUI.swift rename Sources/{SafariUI => SafariView}/DismissButtonStyle.swift (100%) rename Sources/{SafariUI => SafariView}/Environment.swift (91%) rename Sources/{SafariUI => SafariView}/ExcludedActivityTypes.swift (100%) rename Sources/{SafariUI => SafariView}/IncludedActivities.swift (100%) rename Sources/{SafariUI => SafariView}/Modifiers.swift (93%) rename Sources/{SafariUI => SafariView}/Presentation.swift (90%) rename Sources/{SafariUI => SafariView}/PrewarmingToken.swift (100%) rename Sources/{SafariUI => SafariView}/SafariView.swift (100%) create mode 100644 Sources/WebAuthentication/Environment.swift create mode 100644 Sources/WebAuthentication/Modifiers.swift create mode 100644 Sources/WebAuthentication/Presentation.swift rename Sources/{SafariUI => WebAuthentication}/WebAuthentication.swift (100%) diff --git a/Package.swift b/Package.swift index 1b91b97ef..a86347218 100644 --- a/Package.swift +++ b/Package.swift @@ -14,6 +14,15 @@ let package = Package( name: "SafariUI", targets: ["SafariUI"] ), + .library( + name: "SafariView", + targets: ["SafariView"] + ), + .library( + name: "WebAuthentication", + targets: ["WebAuthentication"] + ), + ], dependencies: [ .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), @@ -22,6 +31,14 @@ let package = Package( targets: [ .target( name: "SafariUI", + dependencies: ["SafariView", "WebAuthentication"] + ), + .target( + name: "SafariView", + dependencies: [] + ), + .target( + name: "WebAuthentication", dependencies: [] ), .testTarget( diff --git a/Sources/SafariUI/SafariUI.docc/ExcludedActivityTypes.md b/Sources/SafariUI/SafariUI.docc/ExcludedActivityTypes.md index fdbdebeb3..59b26b170 100644 --- a/Sources/SafariUI/SafariUI.docc/ExcludedActivityTypes.md +++ b/Sources/SafariUI/SafariUI.docc/ExcludedActivityTypes.md @@ -12,14 +12,14 @@ You can initialize instances of this type using an array literal of `UIActivity. let excluded: SafariView.ExcludedActivityTypes = [.addToReadingList, .airDrop, .print, .sharePlay] ``` -To change the the excluded activity types used by ``SafariView`` at the current scope, use the ``SwiftUI/View/excludedSafariActivityTypes(_:)-4omxw`` view modifier, or the ``SwiftUI/EnvironmentValues/safariViewExcludedActivityTypes`` environment value. +To change the the excluded activity types used by ``SafariView`` at the current scope, use the ``SwiftUI/View/excludedSafariActivityTypes(_:)-tvrg`` view modifier, or the ``SwiftUI/EnvironmentValues/safariViewExcludedActivityTypes`` environment value. ## Topics ### Initializers -- ``init(_:)-92zvd`` -- ``init(_:)-93kn9`` +- ``init(_:)-1ktmq`` +- ``init(_:)-67duh`` ### Operators diff --git a/Sources/SafariUI/SafariUI.docc/IncludedActivities.md b/Sources/SafariUI/SafariUI.docc/IncludedActivities.md index 9fdf47c24..d692c4cf0 100644 --- a/Sources/SafariUI/SafariUI.docc/IncludedActivities.md +++ b/Sources/SafariUI/SafariUI.docc/IncludedActivities.md @@ -12,14 +12,14 @@ You can initialize instances of this type using an array literal of `UIActivity` let excluded: SafariView.IncludedActivities = [someActivity, someOtherActivity] ``` -To change the the included activities used by ``SafariView`` at the current scope, use the ``SwiftUI/View/includedSafariActivities(_:)-7buso`` view modifier, or the ``SwiftUI/EnvironmentValues/safariViewIncludedActivities`` environment value. +To change the the included activities used by ``SafariView`` at the current scope, use the ``SwiftUI/View/includedSafariActivities(_:)-2u8l9`` view modifier, or the ``SwiftUI/EnvironmentValues/safariViewIncludedActivities`` environment value. ## Topics ### Initializers -- ``init(_:)-6ig8b`` -- ``init(_:)-43y6f`` +- ``init(_:)-6d955`` +- ``init(_:)-9q5v6`` ### Operators diff --git a/Sources/SafariUI/SafariUI.docc/View.md b/Sources/SafariUI/SafariUI.docc/View.md index 9037ff908..e3ec30ca3 100644 --- a/Sources/SafariUI/SafariUI.docc/View.md +++ b/Sources/SafariUI/SafariUI.docc/View.md @@ -24,10 +24,10 @@ SwiftUI view modifiers used to configure a ``SafariView`` or a ``WebAuthenticati ### SafarView Custom Activities -- ``SwiftUI/View/includedSafariActivities(_:)-1yaml`` -- ``SwiftUI/View/includedSafariActivities(_:)-7buso`` -- ``SwiftUI/View/excludedSafariActivityTypes(_:)-5sf78`` -- ``SwiftUI/View/excludedSafariActivityTypes(_:)-4omxw`` +- ``SwiftUI/View/includedSafariActivities(_:)-362lz`` +- ``SwiftUI/View/includedSafariActivities(_:)-2u8l9`` +- ``SwiftUI/View/excludedSafariActivityTypes(_:)-1v8zq`` +- ``SwiftUI/View/excludedSafariActivityTypes(_:)-tvrg`` ### WebAuthentication Configuration @@ -35,6 +35,6 @@ SwiftUI view modifiers used to configure a ``SafariView`` or a ``WebAuthenticati ### WebAuthentication Presentation -- ``SwiftUI/View/webAuthentication(_:webAuthentication:)-5m8qc`` -- ``SwiftUI/View/webAuthentication(_:webAuthentication:)-9e7q7`` +- ``SwiftUI/View/webAuthentication(_:webAuthentication:)-74m38`` +- ``SwiftUI/View/webAuthentication(_:webAuthentication:)-5x82p`` - ``SwiftUI/View/webAuthentication(_:id:webAuthentication:)`` diff --git a/Sources/SafariUI/SafariUI.swift b/Sources/SafariUI/SafariUI.swift new file mode 100644 index 000000000..99f246f27 --- /dev/null +++ b/Sources/SafariUI/SafariUI.swift @@ -0,0 +1,29 @@ +// SafariUI +// SafariUI.swift +// +// MIT License +// +// Copyright (c) 2021 Varun Santhanam +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +@_exported import SafariView +@_exported import WebAuthentication + +struct SafariUIHolder {} diff --git a/Sources/SafariUI/DismissButtonStyle.swift b/Sources/SafariView/DismissButtonStyle.swift similarity index 100% rename from Sources/SafariUI/DismissButtonStyle.swift rename to Sources/SafariView/DismissButtonStyle.swift diff --git a/Sources/SafariUI/Environment.swift b/Sources/SafariView/Environment.swift similarity index 91% rename from Sources/SafariUI/Environment.swift rename to Sources/SafariView/Environment.swift index c45dffcee..f1fb407a9 100644 --- a/Sources/SafariUI/Environment.swift +++ b/Sources/SafariView/Environment.swift @@ -91,11 +91,6 @@ extension EnvironmentValues { set { self[SafariViewDismissButtonStyleEnvironmentKey.self] = newValue } } - var webAuthenticationPrefersEphemeralWebBrowserSession: Bool { - get { self[WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey.self] } - set { self[WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey.self] = newValue } - } - } private struct SafariViewEntersReaderIfAvailableEnvironmentKey: EnvironmentKey { @@ -167,11 +162,3 @@ private struct SafariViewExcludedActivityTypesEnvironmentKey: EnvironmentKey { static let defaultValue: Value = .default } - -private struct WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey: EnvironmentKey { - - typealias Value = Bool - - static let defaultValue: Bool = false - -} diff --git a/Sources/SafariUI/ExcludedActivityTypes.swift b/Sources/SafariView/ExcludedActivityTypes.swift similarity index 100% rename from Sources/SafariUI/ExcludedActivityTypes.swift rename to Sources/SafariView/ExcludedActivityTypes.swift diff --git a/Sources/SafariUI/IncludedActivities.swift b/Sources/SafariView/IncludedActivities.swift similarity index 100% rename from Sources/SafariUI/IncludedActivities.swift rename to Sources/SafariView/IncludedActivities.swift diff --git a/Sources/SafariUI/Modifiers.swift b/Sources/SafariView/Modifiers.swift similarity index 93% rename from Sources/SafariUI/Modifiers.swift rename to Sources/SafariView/Modifiers.swift index 7717da2f3..f43a99557 100644 --- a/Sources/SafariUI/Modifiers.swift +++ b/Sources/SafariView/Modifiers.swift @@ -202,11 +202,6 @@ 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 { @@ -361,24 +356,3 @@ 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 -} diff --git a/Sources/SafariUI/Presentation.swift b/Sources/SafariView/Presentation.swift similarity index 90% rename from Sources/SafariUI/Presentation.swift rename to Sources/SafariView/Presentation.swift index 69f255ade..58ed834f2 100644 --- a/Sources/SafariUI/Presentation.swift +++ b/Sources/SafariView/Presentation.swift @@ -274,32 +274,3 @@ public extension View { ) } } - -public extension View { - - func webAuthentication( - _ isPresented: Binding, - webAuthentication: @escaping () -> WebAuthentication - ) -> some View { - let modifier = WebAuthentication.BoolModifier(isPresented: isPresented, build: webAuthentication) - return ModifiedContent(content: self, modifier: modifier) - } - - func webAuthentication( - _ item: Binding, - webAuthentication: @escaping (Item) -> WebAuthentication - ) -> some View where Item: Identifiable { - let modifier = WebAuthentication.IdentifiableItemModitifer(item: item, build: webAuthentication) - return ModifiedContent(content: self, modifier: modifier) - } - - func webAuthentication( - _ item: Binding, - id: KeyPath, - webAuthentication: @escaping (Item) -> WebAuthentication - ) -> some View where Identifier: Hashable { - let modifier = WebAuthentication.ItemModifier(item: item, id: id, build: webAuthentication) - return ModifiedContent(content: self, modifier: modifier) - } - -} diff --git a/Sources/SafariUI/PrewarmingToken.swift b/Sources/SafariView/PrewarmingToken.swift similarity index 100% rename from Sources/SafariUI/PrewarmingToken.swift rename to Sources/SafariView/PrewarmingToken.swift diff --git a/Sources/SafariUI/SafariView.swift b/Sources/SafariView/SafariView.swift similarity index 100% rename from Sources/SafariUI/SafariView.swift rename to Sources/SafariView/SafariView.swift diff --git a/Sources/WebAuthentication/Environment.swift b/Sources/WebAuthentication/Environment.swift new file mode 100644 index 000000000..b78f3fb0a --- /dev/null +++ b/Sources/WebAuthentication/Environment.swift @@ -0,0 +1,43 @@ +// SafariUI +// Environment.swift +// +// MIT License +// +// Copyright (c) 2021 Varun Santhanam +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +import SwiftUI + +extension EnvironmentValues { + + var webAuthenticationPrefersEphemeralWebBrowserSession: Bool { + get { self[WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey.self] } + set { self[WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey.self] = newValue } + } + +} + +private struct WebAuthenticationPrefersEphemeralWebBrowserSessionEnvironmentKey: EnvironmentKey { + + typealias Value = Bool + + static let defaultValue: Bool = false + +} diff --git a/Sources/WebAuthentication/Modifiers.swift b/Sources/WebAuthentication/Modifiers.swift new file mode 100644 index 000000000..6a9e3290a --- /dev/null +++ b/Sources/WebAuthentication/Modifiers.swift @@ -0,0 +1,56 @@ +// SafariUI +// Modifiers.swift +// +// MIT License +// +// Copyright (c) 2021 Varun Santhanam +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +import SwiftUI + +public extension View { + + func webAuthenticationPrefersEphemeralWebBrowserSession(_ prefersEphemeralWebBrowserSession: Bool = true) -> some View { + let modifer = WebAuthenticationPrefersEphemeralWebBrowserSessionModifier(prefersEphemeralWebBrowserSession: prefersEphemeralWebBrowserSession) + return ModifiedContent(content: self, modifier: modifer) + } + +} + +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 +} diff --git a/Sources/WebAuthentication/Presentation.swift b/Sources/WebAuthentication/Presentation.swift new file mode 100644 index 000000000..ca43bb61c --- /dev/null +++ b/Sources/WebAuthentication/Presentation.swift @@ -0,0 +1,55 @@ +// SafariUI +// Presentation.swift +// +// MIT License +// +// Copyright (c) 2021 Varun Santhanam +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +import SwiftUI + +public extension View { + + func webAuthentication( + _ isPresented: Binding, + webAuthentication: @escaping () -> WebAuthentication + ) -> some View { + let modifier = WebAuthentication.BoolModifier(isPresented: isPresented, build: webAuthentication) + return ModifiedContent(content: self, modifier: modifier) + } + + func webAuthentication( + _ item: Binding, + webAuthentication: @escaping (Item) -> WebAuthentication + ) -> some View where Item: Identifiable { + let modifier = WebAuthentication.IdentifiableItemModitifer(item: item, build: webAuthentication) + return ModifiedContent(content: self, modifier: modifier) + } + + func webAuthentication( + _ item: Binding, + id: KeyPath, + webAuthentication: @escaping (Item) -> WebAuthentication + ) -> some View where Identifier: Hashable { + let modifier = WebAuthentication.ItemModifier(item: item, id: id, build: webAuthentication) + return ModifiedContent(content: self, modifier: modifier) + } + +} diff --git a/Sources/SafariUI/WebAuthentication.swift b/Sources/WebAuthentication/WebAuthentication.swift similarity index 100% rename from Sources/SafariUI/WebAuthentication.swift rename to Sources/WebAuthentication/WebAuthentication.swift