|
|
@@ -1,67 +1,171 @@
|
|
|
package com.iscs.bozzys.ui.dialog
|
|
|
|
|
|
+import android.view.WindowManager
|
|
|
import androidx.compose.foundation.background
|
|
|
+import androidx.compose.foundation.border
|
|
|
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.offset
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
-import androidx.compose.foundation.layout.width
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
+import androidx.compose.foundation.text.BasicTextField
|
|
|
+import androidx.compose.foundation.text.KeyboardOptions
|
|
|
+import androidx.compose.material3.LocalTextStyle
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
+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.graphics.SolidColor
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
+import androidx.compose.ui.text.input.KeyboardType
|
|
|
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.pages.compose.CardContainer
|
|
|
+import com.iscs.bozzys.ui.theme.Main
|
|
|
import com.iscs.bozzys.ui.theme.Text
|
|
|
|
|
|
/**
|
|
|
- * 默认公共弹窗
|
|
|
+ * 公共输入框Dialog
|
|
|
*/
|
|
|
@Composable
|
|
|
fun InputDialog(
|
|
|
- show: Boolean = false,
|
|
|
- title: String = "提示",
|
|
|
- content: String = "",
|
|
|
- cancelText: String = "取消",
|
|
|
+ show: Boolean,
|
|
|
+ value: String,
|
|
|
+ title: String = "",
|
|
|
+ placeholder: String = "",
|
|
|
+ onConfirm: () -> Unit = {},
|
|
|
onCancel: () -> Unit = {},
|
|
|
- confirmText: String = "确认",
|
|
|
- onConfirm: () -> Unit = {}
|
|
|
+ onInputChanged: (String) -> Unit
|
|
|
) {
|
|
|
- if (show) {
|
|
|
- Dialog(onDismissRequest = {}) {
|
|
|
- Box(
|
|
|
+ val ctx = LocalContext.current
|
|
|
+ if (!show || ctx !is PageBase) return
|
|
|
+
|
|
|
+ LaunchedEffect(Unit) {
|
|
|
+ ctx.setNavigationLight(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ Dialog(
|
|
|
+ onDismissRequest = onCancel,
|
|
|
+ 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
|
|
|
+ .fillMaxSize()
|
|
|
+ .background(Color.Black.copy(alpha = 0.4f))
|
|
|
+ .clickable(
|
|
|
+ indication = null,
|
|
|
+ interactionSource = remember { MutableInteractionSource() },
|
|
|
+ onClick = {}),
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
+ ) {
|
|
|
+ CardContainer(
|
|
|
+ topRadius = 16.dp,
|
|
|
+ bottomRadius = 16.dp,
|
|
|
modifier = Modifier
|
|
|
- .clip(RoundedCornerShape(12.dp))
|
|
|
- .background(Color.White)
|
|
|
+ .fillMaxWidth(0.65f)
|
|
|
+ // 防止点击穿透
|
|
|
+ .clickable(
|
|
|
+ indication = null,
|
|
|
+ interactionSource = remember { MutableInteractionSource() },
|
|
|
+ onClick = {})
|
|
|
+ .background(Color.White, RoundedCornerShape(16.dp))
|
|
|
) {
|
|
|
- Column(modifier = Modifier.width(240.dp), horizontalAlignment = Alignment.CenterHorizontally) {
|
|
|
- Text(title, fontSize = 16.sp, lineHeight = 36.sp, fontWeight = FontWeight.Bold, color = Text)
|
|
|
+ Column(Modifier.fillMaxWidth()) {
|
|
|
+ Row(
|
|
|
+ Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(40.dp)
|
|
|
+ .padding(horizontal = 16.dp),
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+ Text(
|
|
|
+ title,
|
|
|
+ fontSize = 16.sp,
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
+ color = Text,
|
|
|
+ modifier = Modifier.weight(1f),
|
|
|
+ textAlign = TextAlign.Center
|
|
|
+ )
|
|
|
+ }
|
|
|
Spacer(
|
|
|
Modifier
|
|
|
.fillMaxWidth()
|
|
|
- .height(1.dp)
|
|
|
- .background(Color(0xFFEEEEEE))
|
|
|
+ .height(0.5.dp)
|
|
|
+ .background(Color.Black.copy(alpha = 0.05f))
|
|
|
)
|
|
|
- Text(
|
|
|
- content,
|
|
|
- fontSize = 15.sp,
|
|
|
- color = Text.copy(alpha = 0.8f),
|
|
|
- modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp)
|
|
|
+ BasicTextField(
|
|
|
+ value,
|
|
|
+ onValueChange = { onInputChanged(it) },
|
|
|
+ Modifier
|
|
|
+ .padding(vertical = 16.dp, horizontal = 10.dp)
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(46.dp)
|
|
|
+ .border(1.dp, shape = RoundedCornerShape(6.dp), color = Color(0xFFE5E6EB))
|
|
|
+ .padding(horizontal = 10.dp),
|
|
|
+ singleLine = true,
|
|
|
+ textStyle = LocalTextStyle.current.copy(fontSize = 16.sp, lineHeight = 20.sp),
|
|
|
+ decorationBox = { innerTextField ->
|
|
|
+ Box(contentAlignment = Alignment.CenterStart) {
|
|
|
+ innerTextField()
|
|
|
+ if (value.isEmpty()) {
|
|
|
+ Text(
|
|
|
+ placeholder,
|
|
|
+ color = Color(0xFF9CA3AF),
|
|
|
+ fontSize = 16.sp,
|
|
|
+ lineHeight = 20.sp,
|
|
|
+ modifier = Modifier.offset(y = (-1).dp)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cursorBrush = SolidColor(Main),
|
|
|
+ keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)
|
|
|
+ )
|
|
|
+ Spacer(
|
|
|
+ Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(0.5.dp)
|
|
|
+ .background(Color.Black.copy(alpha = 0.05f))
|
|
|
)
|
|
|
Row(Modifier.padding(horizontal = 5.dp, vertical = 10.dp)) {
|
|
|
Text(
|
|
|
- cancelText, color = Color.White, modifier = Modifier
|
|
|
+ "取消", color = Color.White, modifier = Modifier
|
|
|
.padding(horizontal = 5.dp)
|
|
|
.weight(1f)
|
|
|
.clip(RoundedCornerShape(6.dp))
|
|
|
@@ -73,7 +177,7 @@ fun InputDialog(
|
|
|
fontWeight = FontWeight.Bold
|
|
|
)
|
|
|
Text(
|
|
|
- confirmText,
|
|
|
+ "确定",
|
|
|
color = Color.White,
|
|
|
modifier = Modifier
|
|
|
.padding(horizontal = 5.dp)
|
|
|
@@ -91,7 +195,4 @@ fun InputDialog(
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// data class StateTips(val title: String = "", val content: String = "", val show: Boolean = false, val type: String = "")
|
|
|
+}
|