70 行
2.3 KiB
Kotlin
70 行
2.3 KiB
Kotlin
|
|
package com.xuqm.sdk.webview
|
||
|
|
|
||
|
|
import androidx.activity.compose.BackHandler
|
||
|
|
import androidx.compose.foundation.layout.Column
|
||
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
||
|
|
import androidx.compose.material.icons.Icons
|
||
|
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||
|
|
import androidx.compose.material.icons.filled.Close
|
||
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||
|
|
import androidx.compose.material3.Icon
|
||
|
|
import androidx.compose.material3.IconButton
|
||
|
|
import androidx.compose.material3.MaterialTheme
|
||
|
|
import androidx.compose.material3.Scaffold
|
||
|
|
import androidx.compose.material3.Text
|
||
|
|
import androidx.compose.material3.TopAppBar
|
||
|
|
import androidx.compose.runtime.Composable
|
||
|
|
import androidx.compose.ui.Modifier
|
||
|
|
|
||
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
||
|
|
@Composable
|
||
|
|
fun XWebViewScreen(
|
||
|
|
modifier: Modifier = Modifier,
|
||
|
|
config: XWebViewConfig = getXWebViewConfig(),
|
||
|
|
onBack: (() -> Unit)? = null,
|
||
|
|
onClose: (() -> Unit)? = null,
|
||
|
|
) {
|
||
|
|
val controller = XWebViewControl
|
||
|
|
val canGoBack = controller.canGoBack()
|
||
|
|
|
||
|
|
BackHandler(enabled = canGoBack) {
|
||
|
|
controller.goBack()
|
||
|
|
}
|
||
|
|
|
||
|
|
Scaffold(
|
||
|
|
modifier = modifier,
|
||
|
|
topBar = {
|
||
|
|
if (!config.hideToolbar) {
|
||
|
|
TopAppBar(
|
||
|
|
title = { Text(text = config.title.ifBlank { "WebView" }) },
|
||
|
|
navigationIcon = {
|
||
|
|
IconButton(onClick = {
|
||
|
|
if (canGoBack) {
|
||
|
|
controller.goBack()
|
||
|
|
} else {
|
||
|
|
onBack?.invoke() ?: onClose?.invoke()
|
||
|
|
}
|
||
|
|
}) {
|
||
|
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
|
||
|
|
}
|
||
|
|
},
|
||
|
|
actions = {
|
||
|
|
if (onClose != null) {
|
||
|
|
IconButton(onClick = onClose) {
|
||
|
|
Icon(Icons.Default.Close, contentDescription = "Close")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
)
|
||
|
|
}
|
||
|
|
},
|
||
|
|
) { paddingValues ->
|
||
|
|
Column(modifier = Modifier.fillMaxSize()) {
|
||
|
|
XWebViewView(
|
||
|
|
modifier = Modifier.fillMaxSize(),
|
||
|
|
config = config,
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|