From efdc56e5ec6f65a2a28044174ad86e96d119c145 Mon Sep 17 00:00:00 2001 From: elmetal Date: Sat, 19 Oct 2024 11:12:28 +0900 Subject: [PATCH 1/5] make USAGE more useful --- README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/README.md b/README.md index e892224..471a9c4 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,23 @@ WebUI is available through [Swift Package Manager](https://github.com/apple/swif ``` ## Usage +Using `WebUI`, you can build a WebView in `SwiftUI` with simple APIs. + +For more in-depth infomation, see API Documentation. + +### Display Web Page +Use `WebView(request:)`. + +```swift +struct ContentView: View { + var body: some View { + WebView(request: URLRequest(url: URL(string: "https://example.com/")!)) + } +} +``` + +### Manipulating WebView +Use `WebViewReader`.Within the scope of `WebViewReader`, you can receive `WebViewProxy`.You can manipulate `WebView` within the scope of `WebViewReader` via `WebViewProxy`. ```swift struct ContentView: View { @@ -81,12 +98,62 @@ struct ContentView: View { .onAppear { proxy.load(request: URLRequest(url: URL(string: "https://www.example.com")!)) } + + Button("Reload") { + proxy.reload() + } } .padding() } } ``` +### Customizing WebView +Use `WebView(configuration:)`. + +```swift +struct ContentView: View { + let configuration: WKWebViewConfiguration + + init() { + configuration = .init() + configuration.allowsInlineMediaPlayback = true + } + + var body: some View { + WebView(configuration: configuration) + } +} +``` + +Other useful APIs are available. + +```swift +struct ContentView: View { + var body: some View { + WebView() + .allowsLinkPreview(true) + .refreshable() + } +} +``` + +### Using with Delegates +Use `uiDelegate(_:)`, `navigationDelegate(_:)` method. + +```swift +final class MyUIDelegate: NSObject, WKUIDelegate {} + +final class MyNavigationDelegate: NSObject, WKNavigationDelegate {} + +struct ContentView: View { + var body: some View { + WebView() + .uiDelegate(MyUIDelegate()) + .navigationDelegate(MyNavigationDelegate()) + } +} +``` ## Demo This repository includes demonstration app for iOS & macOS. From d108f1cf25e81fa2ce547533a22b10afc8a5801a Mon Sep 17 00:00:00 2001 From: elmetal Date: Sat, 19 Oct 2024 11:19:42 +0900 Subject: [PATCH 2/5] add documentation link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 471a9c4..6aa9b28 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ WebUI is available through [Swift Package Manager](https://github.com/apple/swif ## Usage Using `WebUI`, you can build a WebView in `SwiftUI` with simple APIs. -For more in-depth infomation, see API Documentation. +For more in-depth infomation, see [API Documentation](https://cybozu.github.io/WebUI/documentation/webui/). ### Display Web Page Use `WebView(request:)`. From c5e9c5db93f5bd1d556cf323ba5f1ea6d8be7c0b Mon Sep 17 00:00:00 2001 From: "Takuto NAKAMURA (Kyome)" Date: Sat, 19 Oct 2024 20:27:06 +0900 Subject: [PATCH 3/5] Adjustment between sentences --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6aa9b28..1bfb178 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,8 @@ struct ContentView: View { ``` ### Manipulating WebView -Use `WebViewReader`.Within the scope of `WebViewReader`, you can receive `WebViewProxy`.You can manipulate `WebView` within the scope of `WebViewReader` via `WebViewProxy`. +Use `WebViewReader`.Within the scope of `WebViewReader`, you can receive `WebViewProxy`. +You can manipulate `WebView` within the scope of `WebViewReader` via `WebViewProxy`. ```swift struct ContentView: View { From 8e8e6435bd4d20f8856091c78fc557b7c8cc07ee Mon Sep 17 00:00:00 2001 From: "Takuto NAKAMURA (Kyome)" Date: Sat, 19 Oct 2024 20:33:05 +0900 Subject: [PATCH 4/5] Adjustment line spacing --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1bfb178..e79d6dd 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,10 @@ WebUI is available through [Swift Package Manager](https://github.com/apple/swif **CLI** 1. Create `Package.swift` that describes dependencies. - ```swift // swift-tools-version: 5.9 import PackageDescription - + let package = Package( name: "SomeProduct", products: [ @@ -65,18 +64,19 @@ WebUI is available through [Swift Package Manager](https://github.com/apple/swif ] ) ``` - 2. Run the following command in Terminal. ```sh $ swift package resolve ``` ## Usage + Using `WebUI`, you can build a WebView in `SwiftUI` with simple APIs. For more in-depth infomation, see [API Documentation](https://cybozu.github.io/WebUI/documentation/webui/). ### Display Web Page + Use `WebView(request:)`. ```swift @@ -88,7 +88,8 @@ struct ContentView: View { ``` ### Manipulating WebView -Use `WebViewReader`.Within the scope of `WebViewReader`, you can receive `WebViewProxy`. + +Use `WebViewReader`.Within the scope of `WebViewReader`, you can receive `WebViewProxy`. You can manipulate `WebView` within the scope of `WebViewReader` via `WebViewProxy`. ```swift @@ -110,6 +111,7 @@ struct ContentView: View { ``` ### Customizing WebView + Use `WebView(configuration:)`. ```swift @@ -140,6 +142,7 @@ struct ContentView: View { ``` ### Using with Delegates + Use `uiDelegate(_:)`, `navigationDelegate(_:)` method. ```swift @@ -155,6 +158,7 @@ struct ContentView: View { } } ``` + ## Demo This repository includes demonstration app for iOS & macOS. From 215d2e2a150549a2feb6730a2ad16de13e60329c Mon Sep 17 00:00:00 2001 From: "Takuto NAKAMURA (Kyome)" Date: Tue, 22 Oct 2024 09:50:23 +0900 Subject: [PATCH 5/5] Rearranged the paragraphs. --- README.md | 100 +++++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index e79d6dd..37f4aa9 100644 --- a/README.md +++ b/README.md @@ -19,56 +19,6 @@ WebUI is a Swift package that provides WKWebView wrapped by SwiftUI. - Compatible with iOS 16.4+ - Compatible with macOS 13.3+ -## Documentation - -[Latest (Swift-DocC)](https://cybozu.github.io/WebUI/documentation/webui/) - -## Privacy Manifest - -This library does not collect or track user information, so it does not include a PrivacyInfo.xcprivacy file. - -## Installation - -WebUI is available through [Swift Package Manager](https://github.com/apple/swift-package-manager/). - -**Xcode** - -1. File > Add Package Dependencies… -2. Search `https://github.com/cybozu/WebUI.git`. - -3. Add package and link `WebUI` to your application target. - - -**CLI** - -1. Create `Package.swift` that describes dependencies. - ```swift - // swift-tools-version: 5.9 - import PackageDescription - - let package = Package( - name: "SomeProduct", - products: [ - .library(name: "SomeProduct", targets: ["SomeProduct"]) - ], - dependencies: [ - .package(url: "https://github.com/cybozu/WebUI.git", exact: "2.0.0") - ], - targets: [ - .target( - name: "SomeProduct", - dependencies: [ - .product(name: "WebUI", package: "WebUI") - ] - ) - ] - ) - ``` -2. Run the following command in Terminal. - ```sh - $ swift package resolve - ``` - ## Usage Using `WebUI`, you can build a WebView in `SwiftUI` with simple APIs. @@ -159,6 +109,56 @@ struct ContentView: View { } ``` +## Documentation + +[Latest (Swift-DocC)](https://cybozu.github.io/WebUI/documentation/webui/) + +## Installation + +WebUI is available through [Swift Package Manager](https://github.com/apple/swift-package-manager/). + +**Xcode** + +1. File > Add Package Dependencies… +2. Search `https://github.com/cybozu/WebUI.git`. + +3. Add package and link `WebUI` to your application target. + + +**CLI** + +1. Create `Package.swift` that describes dependencies. + ```swift + // swift-tools-version: 5.9 + import PackageDescription + + let package = Package( + name: "SomeProduct", + products: [ + .library(name: "SomeProduct", targets: ["SomeProduct"]) + ], + dependencies: [ + .package(url: "https://github.com/cybozu/WebUI.git", exact: "2.0.0") + ], + targets: [ + .target( + name: "SomeProduct", + dependencies: [ + .product(name: "WebUI", package: "WebUI") + ] + ) + ] + ) + ``` +2. Run the following command in Terminal. + ```sh + $ swift package resolve + ``` + +## Privacy Manifest + +This library does not collect or track user information, so it does not include a PrivacyInfo.xcprivacy file. + ## Demo This repository includes demonstration app for iOS & macOS.