Skip to content

Commit d90baa8

Browse files
committed
Add usage examples for JVM in README.md, including setup and composable integration
1 parent 8442a31 commit d90baa8

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,62 @@ Kotlin/JVM WebView using `wry` (Rust) with Gobley/UniFFI bindings, plus a Compos
88
- `wrywebview-compose` - Compose `WryWebView` composable.
99
- `demo` - sample Compose app.
1010

11+
## Usage (JVM)
12+
13+
1) Add the Compose wrapper module:
14+
15+
```kotlin
16+
dependencies {
17+
implementation(project(":wrywebview-compose"))
18+
}
19+
```
20+
21+
2) Enable native access for the JVM process (required by JNA):
22+
23+
```kotlin
24+
compose.desktop {
25+
application {
26+
jvmArgs += "--enable-native-access=ALL-UNNAMED"
27+
}
28+
}
29+
```
30+
31+
3) Use the composable:
32+
33+
```kotlin
34+
import androidx.compose.foundation.layout.fillMaxSize
35+
import androidx.compose.runtime.Composable
36+
import androidx.compose.ui.Modifier
37+
import io.github.kdroidfilter.composewebview.WryWebView
38+
39+
@Composable
40+
fun App() {
41+
WryWebView(
42+
url = "https://example.com",
43+
modifier = Modifier.fillMaxSize(),
44+
)
45+
}
46+
```
47+
48+
Stateful usage (navigation, loading, current URL):
49+
50+
```kotlin
51+
import androidx.compose.foundation.layout.fillMaxSize
52+
import androidx.compose.runtime.Composable
53+
import androidx.compose.ui.Modifier
54+
import io.github.kdroidfilter.composewebview.WryWebView
55+
import io.github.kdroidfilter.composewebview.rememberWebViewState
56+
57+
@Composable
58+
fun App() {
59+
val state = rememberWebViewState("https://example.com")
60+
61+
// Use state.canGoBack, state.canGoForward, state.isLoading, state.currentUrl
62+
// and trigger state.goBack(), state.goForward(), state.reload(), state.loadUrl(...)
63+
WryWebView(state = state, modifier = Modifier.fillMaxSize())
64+
}
65+
```
66+
1167
## Run the demo
1268

1369
```shell

0 commit comments

Comments
 (0)