Skip to content

Commit a03c179

Browse files
author
Liangjin Huang
committed
webview reload issue try out
1 parent e4b2672 commit a03c179

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

app/src/main/java/com/dena/mobage/webviewreloadissue/GoogleWebView.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ fun GoogleWebView(
7777
onDispose: (WebView) -> Unit = {},
7878
client: AccompanistWebViewClient = remember { AccompanistWebViewClient() },
7979
chromeClient: AccompanistWebChromeClient = remember { AccompanistWebChromeClient() },
80-
factory: ((Context) -> WebView)? = null
80+
factory: ((Context) -> WebView)? = null,
81+
existingWebView: WebView? = null
8182
) {
8283
var webView by remember { mutableStateOf<WebView?>(null) }
8384

@@ -108,7 +109,7 @@ fun GoogleWebView(
108109

109110
AndroidView(
110111
factory = { context ->
111-
(factory?.invoke(context) ?: WebView(context)).apply {
112+
existingWebView ?: WebView(context).apply {
112113
onCreated(this)
113114

114115
layoutParams = ViewGroup.LayoutParams(

app/src/main/java/com/dena/mobage/webviewreloadissue/MainScreen.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package com.dena.mobage.webviewreloadissue
22

33
import android.util.Log
4+
import android.webkit.WebView
45
import androidx.compose.foundation.layout.height
56
import androidx.compose.foundation.layout.padding
67
import androidx.compose.material.*
78
import androidx.compose.material.icons.Icons
8-
import androidx.compose.material.icons.filled.Call
9-
import androidx.compose.material.icons.filled.Chat
109
import androidx.compose.material.icons.filled.Home
1110
import androidx.compose.material.icons.filled.ShoppingCart
1211
import androidx.compose.runtime.Composable
1312
import androidx.compose.ui.Modifier
1413
import androidx.compose.ui.unit.dp
15-
import androidx.navigation.NavGraph.Companion.findStartDestination
1614
import androidx.navigation.compose.NavHost
1715
import androidx.navigation.compose.composable
1816
import androidx.navigation.compose.rememberNavController
@@ -91,7 +89,8 @@ fun WebView1(
9189
},
9290
onDispose = {
9391
Log.d("WebView1", "onDispose")
94-
}
92+
},
93+
existingWebView = viewModel.webView1
9594
)
9695
}
9796

@@ -114,6 +113,7 @@ fun WebView2(
114113
},
115114
onDispose = {
116115
Log.d("WebView2", "onDispose")
117-
}
116+
},
117+
existingWebView = viewModel.webView2
118118
)
119119
}

0 commit comments

Comments
 (0)