refactor(chat): improve FloatingChatWidget layout safety and back button handling
This commit is contained in:
parent
1cf1ffd9e8
commit
30939f13fd
|
|
@ -1,5 +1,7 @@
|
||||||
package com.stand.standapp.ui.chat
|
package com.stand.standapp.ui.chat
|
||||||
|
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
|
@ -10,6 +12,7 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.draw.shadow
|
import androidx.compose.ui.draw.shadow
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Popup
|
import androidx.compose.ui.window.Popup
|
||||||
import androidx.compose.ui.window.PopupProperties
|
import androidx.compose.ui.window.PopupProperties
|
||||||
|
|
@ -18,6 +21,14 @@ import com.stand.standapp.ui.chat.components.ChatScaffold
|
||||||
@Composable
|
@Composable
|
||||||
fun FloatingChatWidget() {
|
fun FloatingChatWidget() {
|
||||||
var isExpanded by remember { mutableStateOf(false) }
|
var isExpanded by remember { mutableStateOf(false) }
|
||||||
|
val configuration = LocalConfiguration.current
|
||||||
|
val maxHeight = (configuration.screenHeightDp * 0.75f).dp
|
||||||
|
|
||||||
|
if (isExpanded) {
|
||||||
|
BackHandler {
|
||||||
|
isExpanded = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
// 右下角悬浮按钮
|
// 右下角悬浮按钮
|
||||||
|
|
@ -44,9 +55,10 @@ fun FloatingChatWidget() {
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(16.dp)
|
.padding(16.dp)
|
||||||
.padding(bottom = 32.dp)
|
.padding(bottom = 32.dp)
|
||||||
.width(340.dp) // 限定卡片宽度
|
.widthIn(max = 340.dp) // 限定卡片宽度
|
||||||
.height(500.dp) // 限定卡片高度
|
.heightIn(max = maxHeight) // 限定卡片高度
|
||||||
.shadow(8.dp, RoundedCornerShape(16.dp))
|
.shadow(8.dp, RoundedCornerShape(16.dp))
|
||||||
|
.background(MaterialTheme.colorScheme.surface, RoundedCornerShape(16.dp))
|
||||||
.clip(RoundedCornerShape(16.dp))
|
.clip(RoundedCornerShape(16.dp))
|
||||||
) {
|
) {
|
||||||
ChatScaffold(
|
ChatScaffold(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue