diff --git a/Sources/SafariView/Presentation.swift b/Sources/SafariView/Presentation.swift index f8379fbf2..11ffaf3e8 100644 --- a/Sources/SafariView/Presentation.swift +++ b/Sources/SafariView/Presentation.swift @@ -257,7 +257,7 @@ public extension View { /// ``` /// /// - Parameters: - /// - item: A binding to an optional source of truth for the ``SafariView``. When the URL is non-nil, the system passes the URL to the modifier’s closure. You display this content in a ``SafariView`` that you create that the system displays to the user. If the URL changes, the system dismisses the ``SafariView`` and replaces it with a new one using the same process. + /// - url: A binding to an optional source of truth for the ``SafariView``. When the URL is non-nil, the system passes the URL to the modifier’s closure. You display this content in a ``SafariView`` that you create that the system displays to the user. If the URL changes, the system dismisses the ``SafariView`` and replaces it with a new one using the same process. /// - onDismiss: The closure to execute when dismissing the ``SafariView`` /// - safariView: A closure that returns the ``SafariView`` to present /// - Returns: The modified view @@ -274,4 +274,49 @@ public extension View { ) } + /// Presents a ``SafariView`` using the given URL as a data source for the ``SafariView``'s content + /// + /// Use this method when you need to present a ``SafariView`` with content from a custom data source. The example below shows a custom data source `InventoryItem` that the closure uses to populate the ``SafariView`` before it is shown to the user: + /// + /// ```swift + /// import Foundation + /// import SafariView + /// import SwiftUI + /// + /// struct InventoryItem { + /// let title: String + /// let url: URL + /// } + /// + /// struct InventoryList: View { + /// + /// init(inventory: [InventoryItem]) { + /// self.inventory = inventory + /// } + /// + /// var inventory: [InventoryItem] + /// + /// @State private var selectedURL: URL? + /// + /// var body: some View { + /// List(inventory.indices, id: \.self) { index in + /// Button(action: { + /// self.selectedURL = inventory[index].url + /// }) { + /// Text(inventory[index].title) + /// } + /// } + /// .safari(item: $selectedURL) + /// } + /// + /// } + /// ``` + /// + /// - Parameter url: A binding to an optional source of truth for the ``SafariView``. When the URL is non-nil, the system passes the URL to the modifier’s closure. You display this content in a ``SafariView`` that you create that the system displays to the user. If the URL changes, the system dismisses the ``SafariView`` and replaces it with a new one using the same process. + /// - Returns: The modified view + func safari(url: Binding) -> some View { + safari(item: url, id: \.hashValue) { url in + SafariView(url: url) + } + } }