Swiftpack.co - Package - stleamist/FullScreenSafariView

Swift: 5.1 version SwiftPM: compatible license contact: @stleamist


FullScreenSafariView is a clean way to present a full-screen SFSafariViewController with a push transition in SwiftUI.


SwiftUI is a strong, intuitive way to build user interfaces, but was released with some part of existing elements missing. One example of those missing elements is the SFSafariViewController.

Fortunately, Apple provides a way to wrap UIKit elements into SwiftUI views. A common approach to place the SFSafariViewController inside SwiftUI is to create a simple view representing an SFSafariViewController, then present it with a sheet(isPresented:onDismiss:content:) modifier or a NavigationLink button (See ContentView.swift in the demo project).

However, there’s a problem in this approach: it can’t present the SFSafariViewController with its default presentation style — a push transition covers full screen. A sheet modifier can present the view only in a modal sheet, and a navigation link shows the two navigation bars at the top so we have to deal with them. This comes down to the conclusion that there’s no option to present it the right way except for using present(_:animated:completion:) method of an UIViewController instance, but it is prohibited and not a good design to access the UIHostingController directly from the SwiftUI view.

FullScreenSafariView clearly achieves this goal by hosting a simple UIViewController to present an SFSafariViewController as a view’s background.


You can use it easily with a safariView(isPresented:content:) modifier in a similar way to presenting a sheet.


A Binding to whether the SFSafariViewController is presented.


A closure returning the URL to load.

import SwiftUI
import FullScreenSafariView

struct ContentView: View {
    @State private var showingSafariView = false
    var body: some View {
        Button(action: {
            self.showingSafariView = true
        }) {
            Text("Show SafariView")
        .safariView(isPresented: $showingSafariView) {
            URL(string: "https://example.com/")!


Swift Package Manager

Add this repository as a dependency in your Package.swift:

// swift-tools-version:5.1

import PackageDescription

let package = Package(
    dependencies: [
        .package(url: "https://github.com/stleamist/FullScreenSafariView.git", .upToNextMajor(from: "1.0.0"))


Select File > Swift Packages > Add Package Dependency, then enter the following URL:


For more details, see Adding Package Dependencies to Your App.


You can compare the behavior of FullScreenSafariView with the other two ways above in the demo project. Check out the demo app by opening FullScreenSafariView.xcworkspace.


FullScreenSafariView is released under the MIT license. See LICENSE for details.


Stars: 3


Used By

Total: 0


1.0.0 - 2020-05-18 08:56:39

  • Initial release