File tree Expand file tree Collapse file tree
sample/shared/src/commonMain/kotlin/com/kevinnzou/sample
commonMain/kotlin/com/multiplatform/webview
iosMain/kotlin/com/multiplatform/webview/web Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ import androidx.compose.material.icons.Icons
1919import androidx.compose.material.icons.filled.ArrowBack
2020import androidx.compose.material.icons.filled.Close
2121import androidx.compose.runtime.Composable
22- import androidx.compose.runtime.DisposableEffect
2322import androidx.compose.runtime.LaunchedEffect
2423import androidx.compose.runtime.getValue
2524import androidx.compose.runtime.mutableStateOf
@@ -54,16 +53,13 @@ import kotlinx.coroutines.flow.filter
5453@Composable
5554internal 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)
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ class WebViewState(webContent: WebContent) {
110110fun 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/* *
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments