Directly track current WebView URL instead of relying on state
State approach doesn't work well for client-side routed apps like MangaDex. Fixes #9576
This commit is contained in:
parent
438054a0ec
commit
39a7356ed1
@ -14,7 +14,10 @@ import androidx.compose.material.icons.outlined.ArrowForward
|
|||||||
import androidx.compose.material.icons.outlined.Close
|
import androidx.compose.material.icons.outlined.Close
|
||||||
import androidx.compose.material3.LinearProgressIndicator
|
import androidx.compose.material3.LinearProgressIndicator
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@ -43,13 +46,14 @@ fun WebViewScreenContent(
|
|||||||
) {
|
) {
|
||||||
val state = rememberWebViewState(url = url, additionalHttpHeaders = headers)
|
val state = rememberWebViewState(url = url, additionalHttpHeaders = headers)
|
||||||
val navigator = rememberWebViewNavigator()
|
val navigator = rememberWebViewNavigator()
|
||||||
|
var currentUrl by remember { mutableStateOf(url) }
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
Box {
|
Box {
|
||||||
AppBar(
|
AppBar(
|
||||||
title = state.pageTitle ?: initialTitle,
|
title = state.pageTitle ?: initialTitle,
|
||||||
subtitle = state.lastLoadedUrl,
|
subtitle = currentUrl,
|
||||||
navigateUp = onNavigateUp,
|
navigateUp = onNavigateUp,
|
||||||
navigationIcon = Icons.Outlined.Close,
|
navigationIcon = Icons.Outlined.Close,
|
||||||
actions = {
|
actions = {
|
||||||
@ -81,15 +85,15 @@ fun WebViewScreenContent(
|
|||||||
),
|
),
|
||||||
AppBar.OverflowAction(
|
AppBar.OverflowAction(
|
||||||
title = stringResource(R.string.action_share),
|
title = stringResource(R.string.action_share),
|
||||||
onClick = { onShare(state.lastLoadedUrl ?: url) },
|
onClick = { onShare(currentUrl) },
|
||||||
),
|
),
|
||||||
AppBar.OverflowAction(
|
AppBar.OverflowAction(
|
||||||
title = stringResource(R.string.action_open_in_browser),
|
title = stringResource(R.string.action_open_in_browser),
|
||||||
onClick = { onOpenInBrowser(state.lastLoadedUrl ?: url) },
|
onClick = { onOpenInBrowser(currentUrl) },
|
||||||
),
|
),
|
||||||
AppBar.OverflowAction(
|
AppBar.OverflowAction(
|
||||||
title = stringResource(R.string.pref_clear_cookies),
|
title = stringResource(R.string.pref_clear_cookies),
|
||||||
onClick = { onClearCookies(state.lastLoadedUrl ?: url) },
|
onClick = { onClearCookies(currentUrl) },
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -116,7 +120,22 @@ fun WebViewScreenContent(
|
|||||||
object : AccompanistWebViewClient() {
|
object : AccompanistWebViewClient() {
|
||||||
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
||||||
super.onPageStarted(view, url, favicon)
|
super.onPageStarted(view, url, favicon)
|
||||||
url?.let { onUrlChange(it) }
|
url?.let {
|
||||||
|
currentUrl = it
|
||||||
|
onUrlChange(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun doUpdateVisitedHistory(
|
||||||
|
view: WebView,
|
||||||
|
url: String?,
|
||||||
|
isReload: Boolean,
|
||||||
|
) {
|
||||||
|
super.doUpdateVisitedHistory(view, url, isReload)
|
||||||
|
url?.let {
|
||||||
|
currentUrl = it
|
||||||
|
onUrlChange(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldOverrideUrlLoading(
|
override fun shouldOverrideUrlLoading(
|
||||||
|
Loading…
Reference in New Issue
Block a user