Swiftpack.co - bestler/SafariView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by bestler.
bestler/SafariView 1.0.0
Swift Package to use the functionalities of SFSafariViewController inside SwiftUI
⭐️ 0
🕓 1 year ago
iOS
.package(url: "https://github.com/bestler/SafariView.git", from: "1.0.0")

SafariView

license

About

SafariView is a package that you can use if you want to display content of the web (e.g. your website) inside your application. In UIKit there is a component for that called SFSafariController, but this component is not available for SwiftUI. If you use this package you can use it the same way as you would interact with a native SwiftUI View.

⚠️ Important
Because this view is using SFSafariViewController be aware on the rules from Apple for that specific component. You can check the documentation here:
"In accordance with App Store Review Guidelines, this view (controller) must be used to visibly present information to users; the controller may not be hidden or obscured by other views or layers. Additionally, an app may not use this view to track users without their knowledge and consent."

Installation and Usage

Installation

  1. Import the SwiftPackage into XCode
  2. The package should show up in the Navigator on the left panel
  3. Add SafariView to a sheet() or fullscreen() modifier
  4. Rebuild your code

Example Code

import SwiftUI
import SafariView

struct ContentView: View {

    @State private var isPresented = false

    var body: some View {
        Button("Open in SafariView") {
            isPresented.toggle()
        }
        .sheet(isPresented: $isPresented) {
            SafariView(url: URL(string: "https://apple.com")!)
        }
    }
}

If you want to see a whole Demo Project on how to use it, take a look here.

Screenshots

Customization

The only mandatory parameter in the initalization of this view is url. ⚠️ Make sure that you provide a valid URL.
Besides that there are optional parameters that you can specify in the initializer for customization. Available parameters:

  • dismissButtonStyle: Specifices which type of Button to use to dismiss the screen
  • preferredBarTintColor: The color to tint the background of the navigation bar and the toolbar (default: .systemBackground)
  • preferredControlTintColor: The color to tint the control buttons on the navigation bar and the toolbar (default: .tintColor/.accentColor)
  • isBarCollapsing: If you scroll the title bar (default: false)
  • entersReaderIfAvailable: A value that specifies whether Safari should enter Reader mode, if it is available (default: false)

A possible initialtation for example could be:

SafariView(
	url: URL(string: "https://apple.com")!,
	isBarCollapsing: true,
	entersReaderIfAvailable: true)

Issues

If you find any bugs or you have ideas for improvements, you can create here an issue. Try to describe your problem as precise as possible. Feel also free to contribute and create a Pull Request.

License

This project is licensed under the MIT License.

See LICENSE for more information.

GitHub

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics