Skip to content

Commit

Permalink
showSafari(url:) (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick <[email protected]>
  • Loading branch information
SwiftfulThinking and swiftfulthinking-llc committed Aug 25, 2023
1 parent 2fd38d6 commit 23149ce
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Sources/SwiftfulRouting/Core/AnyRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ public struct AnyRouter: Router {
public func dismissModal() {
object.dismissModal()
}

/// Open URL in Safari app. To open url in in-app browser, use showSheet with a WebView.
public func showSafari(_ url: @escaping () -> URL) {
object.showSafari(url)
}

}
2 changes: 2 additions & 0 deletions Sources/SwiftfulRouting/Core/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public protocol Router {

func showModal<V:View>(transition: AnyTransition, animation: Animation, alignment: Alignment, backgroundColor: Color?, backgroundEffect: BackgroundEffect?, useDeviceBounds: Bool, @ViewBuilder destination: @escaping () -> V)
func dismissModal()

func showSafari(_ url: @escaping () -> URL)
}
12 changes: 7 additions & 5 deletions Sources/SwiftfulRouting/Core/RouterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct OnFirstAppearModifier: ViewModifier {
public struct RouterView<T:View>: View, Router {

@Environment(\.presentationMode) var presentationMode
@Environment(\.openURL) var openURL

let addNavigationView: Bool
let content: (AnyRouter) -> T

Expand All @@ -41,11 +43,7 @@ public struct RouterView<T:View>: View, Router {
@State public var screens: [AnyDestination] = []

// Binding to view stack from previous RouterViews
@Binding private var screenStack: [AnyDestination] {
didSet {
print("DID SET SCREEN STACK: \(screenStack.map({ $0.destination }))")
}
}
@Binding private var screenStack: [AnyDestination]
@State private var screenStackCount: Int = 0

// Configuration for resizable sheet on iOS 16+
Expand Down Expand Up @@ -205,6 +203,10 @@ public struct RouterView<T:View>: View, Router {
public func dismissModal() {
self.modal = nil
}

public func showSafari(_ url: @escaping () -> URL) {
openURL(url())
}
}

struct RouterView_Previews: PreviewProvider {
Expand Down
13 changes: 13 additions & 0 deletions Sources/SwiftfulRouting/Options/UrlOption.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UrlOption.swift
//
//
// Created by Nick Sarno on 8/24/23.
//

import Foundation

public enum UrlOption: Equatable {
case inAppBrowser(segue: SegueOption)
case safari, urlSchema
}

0 comments on commit 23149ce

Please sign in to comment.