{"id":18421287,"url":"https://github.com/rebeloper/wkview","last_synced_at":"2025-04-07T14:31:44.233Z","repository":{"id":169311278,"uuid":"319912858","full_name":"rebeloper/WKView","owner":"rebeloper","description":"🤩 WKWebView for SwiftUI with Delegates 🤯","archived":false,"fork":false,"pushed_at":"2022-01-06T08:17:46.000Z","size":2824,"stargazers_count":68,"open_issues_count":3,"forks_count":17,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-22T19:43:22.947Z","etag":null,"topics":["swift","swiftui","uiviewcontrollerrepresentable","uiviewrepresentable","webview","wkwebview","wkwebview-sample","wkwebviewcontroller"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rebeloper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-09T09:56:13.000Z","updated_at":"2025-02-07T21:56:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"0ccd363d-f6c3-4072-b398-595154e5fb42","html_url":"https://github.com/rebeloper/WKView","commit_stats":null,"previous_names":["rebeloper/wkview"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeloper%2FWKView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeloper%2FWKView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeloper%2FWKView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeloper%2FWKView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rebeloper","download_url":"https://codeload.github.com/rebeloper/WKView/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247669906,"owners_count":20976475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swift","swiftui","uiviewcontrollerrepresentable","uiviewrepresentable","webview","wkwebview","wkwebview-sample","wkwebviewcontroller"],"created_at":"2024-11-06T04:25:04.813Z","updated_at":"2025-04-07T14:31:44.228Z","avatar_url":"https://github.com/rebeloper.png","language":"Swift","readme":"# 🕸 WKView\n\n**WKView** is a lightweight library to present web content in your SwiftUI app with the help of `WebKit`.\n\n## 💻 Installation\n### 📦 Swift Package Manager\nUsing \u003ca href=\"https://swift.org/package-manager/\" rel=\"nofollow\"\u003eSwift Package Manager\u003c/a\u003e, add it as a Swift Package in Xcode 11.0 or later, `select File \u003e Swift Packages \u003e Add Package Dependency...` and add the repository URL:\n```\nhttps://github.com/rebeloper/WKView.git\n```\n### ✊ Manual Installation\nDownload and include the `WKView` folder and files in your codebase.\n\n### 📲 Requirements\n- iOS 14+\n- Swift 5\n\n## 🎬 Video Tutorial\n\n\u003cp\u003e\u003ca href=\"https://www.youtube.com/watch?v=FPvH3--Q3ys\u0026list=PL_csAAO9PQ8Yj7ZU7n2IJjIsqcFaLcvJN\u0026index=3\"\u003eWKWebView SwiftUI on YouTube\u003c/a\u003e\u003c/p\u003e\n\n## 👉 Import\n\nImport `WKView` into your `View`\n\n```\nimport WKView\n```\n\n## 🛠 How to use\n\nThe simplest way to use `WKView` is to call `WebView` with a `URL String`. \nIMPORTANT: `WebView` must be presented inside a `NavigationView`.\n\n```swift\nimport SwiftUI\nimport WKView\n\nstruct ContentView: View {\n    var body: some View {\n        NavigationView {\n            WebView(data: .url(\"https://rebeloper.com\"), hidesBackButton: true)\n        }\n    }\n}\n```\n\nNote: Here we are hiding the **Back button** of the web view by setting `hidesBackButton` to `false` because the `ContentView` is the root view of our app.\n\n## 🧳 Features\n\nIn the example below you can see one pushed and two presented `WebView`s. Take a look at the cool ways you may customize the `WebView` style.\n\n```swift\nimport SwiftUI\nimport WKView\n\nstruct ContentView: View {\n    \n    @State var isSheetPresented = false\n    \n    var body: some View {\n        NavigationView {\n            VStack(spacing: 12) {\n                Divider()\n                \n                // 1. Push a WebView with a url\n                NavigationLink(\"Push WebView\", destination: WebView(data: .url(\"https://rebeloper.com\"))\n                \n                Button(action: {\n                    isSheetPresented.toggle()\n                }, label: {\n                    Text(\"Present WebView\")\n                }).sheet(isPresented: $isSheetPresented, content: {\n                    NavigationView {\n                        // 2. Present WebView in a modal with hiding the back button\n//                        WebView(url: \"https://rebeloper.com\", hidesBackButton: true)\n                        \n                        // 3. Present a customized WebView in a modal\n//                        WebView(url: \"https://rebeloper.com\",\n//                                tintColor: .red,\n//                                titleColor: .yellow,\n//                                backText: Text(\"Cancel\").italic(),\n//                                reloadImage: Image(system\"figure.wave\"),\n//                                goForwardImage: Image(system\"forward.frame.fill\"),\n//                                goBackImage: Image(system\"backward.frame.fill\"))\n\n                        // 4. Present WebView in a modal with a constant title\n//                        WebView(url: \"https://rebeloper.com\", title: \"WKView\")\n                        \n                        // 5. Present a webview with onNavigationAction and optional: allowedHosts, forbiddenHosts and credential\n                        WebView(url: \"https://rebeloper.com\"//,\n//                                allowedHosts: [\"github\", \".com\"],\n//                                forbiddenHosts: [\".org\", \"google\"],\n//                                credential: URLCredential(user: \"user\", password: \"password\", persistence: .none)\n                        ){ (onNavigationAction) in\n                            switch onNavigationAction {\n                            case .decidePolicy(let webView, let navigationAction, let policy):\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e decidePolicy navigationAction: \\(navigationAction)\")\n                                switch policy {\n                                case .cancel:\n                                    print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e decidePolicy: .cancel\")\n                                    isSheetPresented = false\n                                case .allow:\n                                    print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e decidePolicy: .allow\")\n                                @unknown default:\n                                    print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e decidePolicy: @unknown default\")\n                                }\n                                \n                            case .didRecieveAuthChallenge(let webView, let challenge, let disposition, let credential):\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didRecieveAuthChallange challenge: \\(challenge.protectionSpace.host)\")\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didRecieveAuthChallange disposition: \\(disposition.rawValue)\")\n                                if let credential = credential {\n                                    print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didRecieveAuthChallange credential: \\(credential)\")\n                                }\n                                \n                            case .didStartProvisionalNavigation(let webView, let navigation):\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didStartProvisionalNavigation: \\(navigation)\")\n                            case .didReceiveServerRedirectForProvisionalNavigation(let webView, let navigation):\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didReceiveServerRedirectForProvisionalNavigation: \\(navigation)\")\n                            case .didCommit(let webView, let navigation):\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didCommit: \\(navigation)\")\n                            case .didFinish(let webView, let navigation):\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didFinish: \\(navigation)\")\n                            case .didFailProvisionalNavigation(let webView, let navigation, let error):\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didFailProvisionalNavigation: \\(navigation)\")\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didFailProvisionalNavigation: \\(error)\")\n                            case .didFail(let webView, let navigation, let error):\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didFail: \\(navigation)\")\n                                print(\"WebView -\u003e \\(String(describing: webView.url)) -\u003e didFail: \\(error)\")\n                            }\n                        }\n                        \n                    }\n                })\n                Spacer()\n            }\n            .navigationBarTitle(\"WKView\")\n            .navigationBarTitleDisplayMode(.inline)\n        }\n        \n    }\n}\n```\n## 📱 Screenshots\n\n\u003cdetails\u003e\n    \u003csummary\u003ePushed WebView\u003c/summary\u003e\n    \u003cimg src=\"../media/Sources/ReadMeAssets/WKView00000.png\" width=\"350px\"\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003ePresented WebView\u003c/summary\u003e\n    \u003cimg src=\"../media/Sources/ReadMeAssets/WKView00001.png\" width=\"350px\"\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n    \u003csummary\u003eCustom Presented WebView\u003c/summary\u003e\n    \u003cimg src=\"../media/Sources/ReadMeAssets/WKView00002.png\" width=\"350px\"\u003e\n\u003c/details\u003e\n\n## ✍️ Contact\n\n\u003ca href=\"https://rebeloper.com/\"\u003erebeloper.com\u003c/a\u003e / \n\u003ca href=\"https://www.youtube.com/rebeloper/\"\u003eYouTube\u003c/a\u003e / \n\u003ca href=\"https://store.rebeloper.com/\"\u003eShop\u003c/a\u003e / \n\u003ca href=\"https://rebeloper.com/mentoring\"\u003eMentoring\u003c/a\u003e\n\n## 📃 License\n\nThe MIT License (MIT)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebeloper%2Fwkview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frebeloper%2Fwkview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebeloper%2Fwkview/lists"}