Skip to content

Commit 06d3c82

Browse files
authored
Merge pull request #305 from sebastiangl/main
add support for iOS isInspectable property vis webSettings
2 parents 251089a + 4fe61a1 commit 06d3c82

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

sample/shared/src/commonMain/kotlin/com/kevinnzou/sample/BasicWebViewSample.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import androidx.compose.material.icons.Icons
1919
import androidx.compose.material.icons.filled.ArrowBack
2020
import androidx.compose.material.icons.filled.Close
2121
import androidx.compose.runtime.Composable
22-
import androidx.compose.runtime.DisposableEffect
2322
import androidx.compose.runtime.LaunchedEffect
2423
import androidx.compose.runtime.getValue
2524
import androidx.compose.runtime.mutableStateOf
@@ -54,16 +53,13 @@ import kotlinx.coroutines.flow.filter
5453
@Composable
5554
internal fun BasicWebViewSample(navHostController: NavHostController? = null) {
5655
val initialUrl = "https://github.com/KevinnZou/compose-webview-multiplatform"
57-
val state = rememberWebViewState(url = initialUrl)
58-
DisposableEffect(Unit) {
59-
state.webSettings.apply {
56+
val state =
57+
rememberWebViewState(url = initialUrl) {
6058
logSeverity = KLogSeverity.Debug
6159
customUserAgentString =
6260
"Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1) AppleWebKit/625.20 (KHTML, like Gecko) Version/14.3.43 Safari/625.20"
61+
iOSWebSettings.isInspectable = true
6362
}
64-
65-
onDispose { }
66-
}
6763
val navigator = rememberWebViewNavigator()
6864
var textFieldValue by remember(state.lastLoadedUrl) {
6965
mutableStateOf(state.lastLoadedUrl)

webview/src/commonMain/kotlin/com/multiplatform/webview/setting/PlatformWebSettings.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,9 @@ sealed class PlatformWebSettings {
251251
* Whether a user gesture is required to play media. The default is {@code true}.
252252
*/
253253
var mediaPlaybackRequiresUserGesture: Boolean = true,
254+
/**
255+
* Whether the WebView supports inspection via MacOS Safari. The default value is {@code false}.
256+
*/
257+
var isInspectable: Boolean = false,
254258
) : PlatformWebSettings()
255259
}

webview/src/commonMain/kotlin/com/multiplatform/webview/web/WebViewState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class WebViewState(webContent: WebContent) {
110110
fun rememberWebViewState(
111111
url: String,
112112
additionalHttpHeaders: Map<String, String> = emptyMap(),
113+
extraSettings: WebSettings.() -> Unit = {},
113114
): WebViewState =
114115
// Rather than using .apply {} here we will recreate the state, this prevents
115116
// a recomposition loop when the webview updates the url itself.
@@ -126,6 +127,7 @@ fun rememberWebViewState(
126127
url = url,
127128
additionalHttpHeaders = additionalHttpHeaders,
128129
)
130+
extraSettings(this.webSettings)
129131
}
130132

131133
/**

webview/src/iosMain/kotlin/com/multiplatform/webview/web/WebView.ios.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ fun IOSWebView(
141141
showsVerticalScrollIndicator = it.showVerticalScrollIndicator
142142
}
143143
}
144+
145+
this.setInspectable(state.webSettings.iOSWebSettings.isInspectable)
144146
}.also {
145147
val iosWebView = IOSWebView(it, scope, webViewJsBridge)
146148
state.webView = iosWebView

0 commit comments

Comments
 (0)