bestler/SafariView
Swift Package to use the functionalities of SFSafariViewController inside SwiftUI
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
- Import the SwiftPackage into XCode
- (File/Add Packages ...) - Search for https://github.com/bestler/SafariView - Press Add Package
- The package should show up in the Navigator on the left panel
- Add SafariView to a sheet() or fullscreen() modifier
- 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
<p align=center> <img src="https://user-images.githubusercontent.com/68077359/228607206-2ef75d06-dc5b-4d41-829f-9bdac865531a.png" width=50%> </p>
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 screenpreferredBarTintColor: 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.
Package Metadata
Repository: bestler/SafariView
Stars: 7
Forks: 1
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: safari, swift, swiftpackage, swiftui, swiftui-components
README: README.md