WebViewKit adds a WebView to SwiftUI, that can be used to present local and online web pages

Overview

WebViewKit

Version Swift UI Swift 5.6 MIT License Twitter: @danielsaidi

About WebViewKit

WebViewKit adds a WebView to SwiftUI, that can be used to present local and online web pages.

WebView can handle any url and be fully configured to fit your needs.

Supported Platforms

WebViewKit supports iOS 13 and macOS 11.

Installation

WebViewKit can be installed with the Swift Package Manager:

https://github.com/danielsaidi/WebViewKit.git

Getting started

The library's main view is WebView, which can be used to present local and online web pages:

import SwiftUI
import WebViewKit

struct MyView {

    var body: some View {
        if let url = URL(string: "https://danielsaidi.com") {
            WebView(url: url)
        } else {
            Text("Invalid url")
        }
    }
}

You can also provide WebView with a configuration block that configures the wrapped WKWebView:

WebView(url: url) { view in
    // Configure the view in any way you like
}

...and that's about it. Enjoy browsing the web in SwiftUI!

Documentation

The WebViewKit documentation can be viewed online and can also be built it directly from Xcode, using Product/Build Documentation.

Demo Application

This project contains a demo app that lets you explore WebViewKit on iOS and macOS. To run it, just open and run Demo/Demo.xcodeproj.

Support

You can sponsor this project on GitHub Sponsors or get in touch for paid support.

Contact

Feel free to reach out if you have questions or if you want to contribute in any way:

License

WebViewKit is available under the MIT license. See the LICENSE file for more info.

You might also like...
PTPopupWebView is a simple and useful WebView for iOS, which can be popup and has many of the customized item.
PTPopupWebView is a simple and useful WebView for iOS, which can be popup and has many of the customized item.

PTPopupWebView PTPopupWebView is a simple and useful WebView for iOS, which can be popup and has many of the customized item. Requirement iOS 8.0 Inst

Todo is an iOS App written in Swift. This app is used for an online video training course. This app demonstrates how to use UITableViewController.
Todo is an iOS App written in Swift. This app is used for an online video training course. This app demonstrates how to use UITableViewController.

Todo Todo is an iOS App written in Swift. This app is used for an online video training course. This app demonstrates how to use UITableViewController

iOS custom controller used in Jobandtalent app to present new view controllers as cards
iOS custom controller used in Jobandtalent app to present new view controllers as cards

CardStackController iOS custom controller used in the Jobandtalent app to present new view controllers as cards. This controller behaves very similar

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR

OysterKit A Swift Framework for Tokenizing, Parsing, and Interpreting Languages OysterKit enables native Swift scanning, lexical analysis, and parsing

Twitter Text Libraries. This code is used at Twitter to tokenize and parse text to meet the expectations for what can be used on the platform.

twitter-text This repository is a collection of libraries and conformance tests to standardize parsing of Tweet text. It synchronizes development, tes

Stateful WebView for SwiftUI.
Stateful WebView for SwiftUI.

Stateful SwiftUI WebView for iOS and MacOS Fully functional, SwiftUI-ready WebView for iOS 13+ and MacOS 10.15+. Actions and state are both delivered

Swift Package used for video where I demonstrate how to extract a package to a local framework and modify it.
Swift Package used for video where I demonstrate how to extract a package to a local framework and modify it.

SegmentedPicker NOTE: This sample code is taken from the article by Frank Jia in his article titled Build a Custom iOS Segmented Control With SwiftUI

Web server serving local files

swift-web A web server serving local static files. Installation Using Mint The easiest way to install swift-web is via mint. mint install adam-fowler/

Example usage of FingerprintJS Pro inside a iOS WebView.
Example usage of FingerprintJS Pro inside a iOS WebView.

FingerprintJS Pro iOS Integrations An example app and packages demonstrating FingerprintJS Pro capabilities on the iOS platform. The repository illust

Example usage of FingerprintJS Pro inside a iOS WebView.
Example usage of FingerprintJS Pro inside a iOS WebView.

FingerprintJS Pro iOS Integrations An example app and packages demonstrating FingerprintJS Pro capabilities on the iOS platform. The repository illust

Single Webview project for xcode in swift

Single Webview project for xcode in swift An xcode project that with single webview(UIWebView) that opens external URL, for hybrid web app debug or te

MacTube is a webview wrapper for YouTube for Mac OS.
MacTube is a webview wrapper for YouTube for Mac OS.

MacTube MacTube is a webview wrapper for YouTube for Mac OS. It was made for peo

POC for a bug with react-native-webview crashing on IOS 16.1

POC Shared Worker issues with IOS 16.1 webview Apple Developers post with workaround Webkit confirmed issue Start a simple http server with shared wor

Audio player demo based on Swift and SwiftUI, which can play local or network audio.
Audio player demo based on Swift and SwiftUI, which can play local or network audio.

SwiftAudioDemo Audio player demo based on Swift and SwiftUI, which can play local or network audio. In this demo, I have made a radio player to play n

Smart Online Shopping iOS App with Augmented Reality (AR) and simple Social Media features using SwiftUI and Google Firebase Cloud Services
Smart Online Shopping iOS App with Augmented Reality (AR) and simple Social Media features using SwiftUI and Google Firebase Cloud Services

Table of contents App Demo How to Run Context Content How it's written Inspiration App Demo AR.online.shopping.iOS.demo.mp4 How to Run First make sure

100-Days-of-SwiftUI - a free online course created and delivered by Paul Hudson

100-Days-of-SwiftUI DESCRIPTION 100 Days of SwiftUI is a free online course crea

SwiftUI view enabling navigation between pages of content, imitating the behaviour of UIPageViewController for iOS and watchOS
SwiftUI view enabling navigation between pages of content, imitating the behaviour of UIPageViewController for iOS and watchOS

PageView SwiftUI view enabling page-based navigation, imitating the behaviour of UIPageViewController in iOS. Why SwiftUI doesn't have any kind of pag

A SwiftUI Weather App powered by World Weather Online API
A SwiftUI Weather App powered by World Weather Online API

SwiftUI-Weather The SwiftUI Weather app, allow users get the current weather for a particular locatio and view a 5-day weather forecast for the select

pick the voice from the local storage.you can play and pause the voice

flutter_add_voice A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you starte

Comments
  • Enable running the demo locally on the Mac

    Enable running the demo locally on the Mac

    Small project change to enable running the demo locally on the Mac.

    This just needs a change of setting from Development to Sign to Run Locally in the Signing certificate project setting, as shown below. signing_locally_mac

    This is the demo app running on the Mac. webviewkit_demo_mac

    opened by atineoSE 1
  • Added WKWebViewConfiguration setting

    Added WKWebViewConfiguration setting

    Usage

    import SwiftUI
    import WebViewKit
    import WebKit
    
    struct ContentView: View {
        @State var isPresentedWebView: Bool = false
        private let url = "https://gs.statcounter.com/detect"
        var body: some View {
            VStack {
                Button {
                    isPresentedWebView = true
                } label: {
                    Text("Show WebView")
                }
            }
            .sheet(isPresented: $isPresentedWebView) {
                WebView(url: URL(string: url), configuration: configuration) { webView in
                    webView.customUserAgent = "foo bar"
                }
            }
        }
        // Example of WKWebViewConfiguration
        var configuration: WKWebViewConfiguration {
            let disableSelectionScriptString = "document.documentElement.style.webkitUserSelect='none';"
            let disableCalloutScriptString = "document.documentElement.style.webkitTouchCallout='none';"
    
            let disableSelectionScript = WKUserScript(source: disableSelectionScriptString, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
            let disableCalloutScript = WKUserScript(source: disableCalloutScriptString, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
    
            let userContentController = WKUserContentController()
            userContentController.addUserScript(disableSelectionScript)
            userContentController.addUserScript(disableCalloutScript)
    
            let configuration = WKWebViewConfiguration()
            configuration.userContentController = userContentController
            configuration.ignoresViewportScaleLimits = false
    
            return configuration
        }
    }
    
    opened by SNQ-2001 2
Releases(0.2.1)
  • 0.2.1(Jun 26, 2022)

  • 0.2.0(Apr 24, 2022)

    This version adds a new SafariWebView.

    ✨ New features

    • SafariWebView is a new iOS view that wraps an SFSafariViewController and can be used to load a custom url.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Mar 31, 2022)

    This is the first public beta of the library.

    ✨ New features

    • WebView is a new view that wraps an WKWebView and can be used to load a custom url.
    Source code(tar.gz)
    Source code(zip)
Owner
Daniel Saidi
Freelance software engineer, focusing on mobile products and Apple platforms like iOS, tvOS and watchOS.
Daniel Saidi
Flare is a simplistic web browser for macOS built using UIKit.

Flare is a simplistic web browser for macOS built using UIKit. It demonstrates a custom address field toolbar item using an NSTextField subclass

Steven Troughton-Smith 97 Nov 1, 2022
A chromeless web browser for viewing prototypes.

Frameless Frameless is a web browser for iOS 8+ that gets out of your way. It was built for designers and prototypers who need to interact with your p

Jay Stakelon 644 Dec 12, 2022
An open-source, privacy-enhancing web browser for iOS, utilizing the Tor anonymity network

Onion Browser Official Site | Support | Release History | Donate © 2012-2020, Tigas Ventures, LLC (Mike Tigas) This is the Onion Browser 2.X branch, b

Onion Browser 2k Dec 30, 2022
SwiftWebKit - This app look like a browser, but you can navigate between 2 sites

import UIKit import WebKit My first app for WebKit. This app look like a browser

Ahmet Onur Şahin 3 Apr 18, 2022
An unofficial E-Hentai App for iOS built with SwiftUI.

EhPanda An unofficial E-Hentai App for iOS. English・ Deutsch・ 한국어・ 日本語・ 繁體中文・ 简体中文 ?? Translations Wanted ?? Please submit a pull request if you want

Tatsuzou Araki 2k Jan 1, 2023
A simple project for using WebKit and SafariServices

SafariServices VS WebKit This respository is a simple project for using WebKit and SafariServices. WebKit is the layout and rendering engine behind Sa

Lee McCormick 0 Nov 9, 2021
Swipe between pages with an interactive title navigation control. Configure horizontal or vertical chains for unlimited pages amount.

SlideController is a simple and flexible UI component fully written in Swift. Built using power of generic types, it is a nice alternative to UIPageVi

Touchlane 409 Dec 6, 2022
Swipe between pages with an interactive title navigation control. Configure horizontal or vertical chains for unlimited pages amount.

SlideController is a simple and flexible UI component fully written in Swift. Built using power of generic types, it is a nice alternative to UIPageVi

Touchlane 411 Jan 5, 2023
Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network.

Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network. This approach allows your app to use both network bandwidth and system resources more efficiently. It's built on top of Combine, allowing you to harness its full power, handle errors easily, etc.

Gordan Glavaš 12 Dec 9, 2022