mirror of
https://github.com/mihonapp/mihon.git
synced 2025-01-13 19:57:16 +01:00
WebViewScreen: Use Scaffold (#7958)
This commit is contained in:
parent
26d8e47bb9
commit
032b377de7
@ -4,9 +4,8 @@ import android.content.pm.ApplicationInfo
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebView
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.ArrowForward
|
||||
@ -14,10 +13,9 @@ import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.google.accompanist.web.AccompanistWebViewClient
|
||||
import com.google.accompanist.web.LoadingState
|
||||
import com.google.accompanist.web.WebView
|
||||
@ -25,6 +23,7 @@ import com.google.accompanist.web.rememberWebViewNavigator
|
||||
import com.google.accompanist.web.rememberWebViewState
|
||||
import eu.kanade.presentation.components.AppBar
|
||||
import eu.kanade.presentation.components.AppBarActions
|
||||
import eu.kanade.presentation.components.Scaffold
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
||||
@ -39,11 +38,12 @@ fun WebViewScreen(
|
||||
onOpenInBrowser: (String) -> Unit,
|
||||
onClearCookies: (String) -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val state = rememberWebViewState(url = url, additionalHttpHeaders = headers)
|
||||
val navigator = rememberWebViewNavigator()
|
||||
|
||||
Column {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
Box {
|
||||
AppBar(
|
||||
title = state.pageTitle ?: initialTitle,
|
||||
subtitle = state.content.getCurrentUrl(),
|
||||
@ -92,18 +92,23 @@ fun WebViewScreen(
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
Box {
|
||||
val loadingState = state.loadingState
|
||||
if (loadingState is LoadingState.Loading) {
|
||||
LinearProgressIndicator(
|
||||
progress = loadingState.progress,
|
||||
when (val loadingState = state.loadingState) {
|
||||
is LoadingState.Initializing -> LinearProgressIndicator(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.zIndex(1f),
|
||||
.align(Alignment.BottomCenter),
|
||||
)
|
||||
is LoadingState.Loading -> LinearProgressIndicator(
|
||||
progress = (loadingState as? LoadingState.Loading)?.progress ?: 1f,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.BottomCenter),
|
||||
)
|
||||
else -> {}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
) { contentPadding ->
|
||||
val webClient = remember {
|
||||
object : AccompanistWebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(
|
||||
@ -120,13 +125,15 @@ fun WebViewScreen(
|
||||
|
||||
WebView(
|
||||
state = state,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
modifier = Modifier.padding(contentPadding),
|
||||
navigator = navigator,
|
||||
onCreated = { webView ->
|
||||
webView.setDefaultSettings()
|
||||
|
||||
// Debug mode (chrome://inspect/#devices)
|
||||
if (BuildConfig.DEBUG && 0 != context.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) {
|
||||
if (BuildConfig.DEBUG &&
|
||||
0 != webView.context.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE
|
||||
) {
|
||||
WebView.setWebContentsDebuggingEnabled(true)
|
||||
}
|
||||
|
||||
@ -138,4 +145,3 @@ fun WebViewScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user