|
|
@@ -1,11 +1,14 @@
|
|
|
package com.iscs.bozzys.ui.dialog
|
|
|
|
|
|
+import android.view.WindowManager
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.clickable
|
|
|
+import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
+import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
@@ -14,15 +17,21 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.DisposableEffect
|
|
|
+import androidx.compose.runtime.SideEffect
|
|
|
+import androidx.compose.runtime.remember
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.draw.clip
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
import androidx.compose.ui.window.Dialog
|
|
|
+import androidx.compose.ui.window.DialogProperties
|
|
|
+import com.iscs.bozzys.ui.common.PageBase
|
|
|
import com.iscs.bozzys.ui.theme.Text
|
|
|
|
|
|
/**
|
|
|
@@ -38,54 +47,84 @@ fun TipsDialog(
|
|
|
confirmText: String = "确认",
|
|
|
onConfirm: () -> Unit = {}
|
|
|
) {
|
|
|
- if (show) {
|
|
|
- Dialog(onDismissRequest = {}) {
|
|
|
+ val ctx = LocalContext.current
|
|
|
+ if (show && ctx is PageBase) {
|
|
|
+ Dialog(onDismissRequest = {}, properties = DialogProperties(decorFitsSystemWindows = false)) {
|
|
|
+ val activityWindow = ctx.window
|
|
|
+ val dialogWindow = ctx.getDialogWindow()
|
|
|
+ SideEffect {
|
|
|
+ if (activityWindow != null && dialogWindow != null) {
|
|
|
+ val attributes = WindowManager.LayoutParams()
|
|
|
+ // 复制Activity窗口属性
|
|
|
+ attributes.copyFrom(activityWindow.attributes)
|
|
|
+ // 这个一定要设置
|
|
|
+ attributes.type = dialogWindow.attributes.type
|
|
|
+ // 更新窗口属性
|
|
|
+ dialogWindow.attributes = attributes
|
|
|
+ // 设置窗口的宽度和高度,这段代码Dialog源码中就有哦,可以自己去查看
|
|
|
+ dialogWindow.setLayout(
|
|
|
+ activityWindow.decorView.width,
|
|
|
+ activityWindow.decorView.height
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
|
- .clip(RoundedCornerShape(12.dp))
|
|
|
- .background(Color.White)
|
|
|
+ .fillMaxSize()
|
|
|
+ .background(Color.Black.copy(alpha = 0.5f))
|
|
|
+ .clickable(
|
|
|
+ indication = null,
|
|
|
+ interactionSource = remember { MutableInteractionSource() }
|
|
|
+ ) {},
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
) {
|
|
|
- Column(modifier = Modifier.width(240.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
|
|
- Text(title, fontSize = 16.sp, lineHeight = 36.sp, fontWeight = FontWeight.Bold, color = Text)
|
|
|
- Spacer(
|
|
|
- Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .height(1.dp)
|
|
|
- .background(Color(0xFFEEEEEE))
|
|
|
- )
|
|
|
- Text(
|
|
|
- content,
|
|
|
- fontSize = 15.sp,
|
|
|
- color = Text.copy(alpha = 0.8f),
|
|
|
- modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp)
|
|
|
- )
|
|
|
- Row(Modifier.padding(horizontal = 5.dp, vertical = 10.dp)) {
|
|
|
- Text(
|
|
|
- cancelText, color = Color.White, modifier = Modifier
|
|
|
- .padding(horizontal = 5.dp)
|
|
|
- .weight(1f)
|
|
|
- .clip(RoundedCornerShape(6.dp))
|
|
|
- .background(Color.Gray.copy(alpha = 0.6f))
|
|
|
- .clickable(onClick = { onCancel() })
|
|
|
- .padding(vertical = 5.dp),
|
|
|
- textAlign = TextAlign.Center,
|
|
|
- fontSize = 16.sp,
|
|
|
- fontWeight = FontWeight.Bold
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .clip(RoundedCornerShape(12.dp))
|
|
|
+ .background(Color.White)
|
|
|
+ ) {
|
|
|
+ Column(modifier = Modifier.width(320.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
|
|
+ Text(title, fontSize = 16.sp, lineHeight = 48.sp, fontWeight = FontWeight.Bold, color = Text)
|
|
|
+ Spacer(
|
|
|
+ Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(1.dp)
|
|
|
+ .background(Color(0xFFEEEEEE))
|
|
|
)
|
|
|
Text(
|
|
|
- confirmText,
|
|
|
- color = Color.White,
|
|
|
- modifier = Modifier
|
|
|
- .padding(horizontal = 5.dp)
|
|
|
- .weight(1f)
|
|
|
- .clip(RoundedCornerShape(6.dp))
|
|
|
- .background(MaterialTheme.colorScheme.primary)
|
|
|
- .clickable(onClick = { onConfirm() })
|
|
|
- .padding(vertical = 5.dp),
|
|
|
- textAlign = TextAlign.Center,
|
|
|
- fontSize = 16.sp,
|
|
|
- fontWeight = FontWeight.Bold
|
|
|
+ content,
|
|
|
+ fontSize = 15.sp,
|
|
|
+ color = Text.copy(alpha = 0.8f),
|
|
|
+ modifier = Modifier.padding(horizontal = 16.dp, vertical = 20.dp)
|
|
|
)
|
|
|
+ Row(Modifier.padding(horizontal = 5.dp, vertical = 10.dp)) {
|
|
|
+ Text(
|
|
|
+ cancelText, color = Color.White, modifier = Modifier
|
|
|
+ .padding(horizontal = 5.dp)
|
|
|
+ .weight(1f)
|
|
|
+ .clip(RoundedCornerShape(6.dp))
|
|
|
+ .background(Color.Gray.copy(alpha = 0.6f))
|
|
|
+ .clickable(onClick = { onCancel() })
|
|
|
+ .padding(vertical = 5.dp),
|
|
|
+ textAlign = TextAlign.Center,
|
|
|
+ fontSize = 16.sp,
|
|
|
+ fontWeight = FontWeight.Bold
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ confirmText,
|
|
|
+ color = Color.White,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(horizontal = 5.dp)
|
|
|
+ .weight(1f)
|
|
|
+ .clip(RoundedCornerShape(6.dp))
|
|
|
+ .background(MaterialTheme.colorScheme.primary)
|
|
|
+ .clickable(onClick = { onConfirm() })
|
|
|
+ .padding(vertical = 5.dp),
|
|
|
+ textAlign = TextAlign.Center,
|
|
|
+ fontSize = 16.sp,
|
|
|
+ fontWeight = FontWeight.Bold
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|