Skip to content

Commit

Permalink
Add additional presentation modifier (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsanthanam authored Jul 15, 2023
1 parent e74e9c6 commit e0ff79a
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion Sources/SafariView/Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<URL?>) -> some View {
safari(item: url, id: \.hashValue) { url in
SafariView(url: url)
}
}
}

0 comments on commit e0ff79a

Please sign in to comment.