Skip to content

Commit 8032d5a

Browse files
committed
library: Display center dialog only in landscape orientation for tablets
1 parent 275966e commit 8032d5a

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

composeApp/src/commonMain/kotlin/component/TextComponent.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ fun dialog2(showDialog: MutableState<Boolean>) {
360360
title = "Dropdown",
361361
items = dropdownOptions,
362362
selectedIndex = dropdownSelectedOption.value,
363-
onSelectedIndexChange = { newOption -> dropdownSelectedOption.value = newOption }
363+
onSelectedIndexChange = { newOption -> dropdownSelectedOption.value = newOption },
364+
defaultWindowInsetsPadding = false
364365
)
365366
}
366367
Spacer(Modifier.height(12.dp))

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDialog.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ package top.yukonga.miuix.kmp.extra
33
import androidx.compose.foundation.background
44
import androidx.compose.foundation.gestures.detectTapGestures
55
import androidx.compose.foundation.layout.Column
6-
import androidx.compose.foundation.layout.WindowInsets
7-
import androidx.compose.foundation.layout.WindowInsetsSides
8-
import androidx.compose.foundation.layout.captionBar
9-
import androidx.compose.foundation.layout.displayCutout
106
import androidx.compose.foundation.layout.fillMaxSize
117
import androidx.compose.foundation.layout.fillMaxWidth
128
import androidx.compose.foundation.layout.imePadding
139
import androidx.compose.foundation.layout.navigationBarsPadding
14-
import androidx.compose.foundation.layout.only
1510
import androidx.compose.foundation.layout.padding
1611
import androidx.compose.foundation.layout.widthIn
17-
import androidx.compose.foundation.layout.windowInsetsPadding
1812
import androidx.compose.runtime.Composable
1913
import androidx.compose.runtime.LaunchedEffect
2014
import androidx.compose.runtime.MutableState
@@ -76,11 +70,12 @@ fun SuperDialog(
7670
content: @Composable () -> Unit
7771
) {
7872
val density = LocalDensity.current
73+
val getWindowSize by rememberUpdatedState(getWindowSize())
74+
println(getWindowSize.width.dp / density.density)
7975
val paddingModifier = remember(outsideMargin) { Modifier.padding(horizontal = outsideMargin.width).padding(bottom = outsideMargin.height) }
8076
val roundedCorner by rememberUpdatedState(getRoundedCorner())
8177
val bottomCornerRadius by remember { derivedStateOf { if (roundedCorner != 0.dp) roundedCorner - outsideMargin.width else 32.dp } }
82-
val getWindowSize by rememberUpdatedState(getWindowSize())
83-
val contentAlignment by remember { derivedStateOf { if (getWindowSize.width > getWindowSize.height || getWindowSize.width.dp / density.density > 440.dp) Alignment.Center else Alignment.BottomCenter } }
78+
val contentAlignment by remember { derivedStateOf { if (getWindowSize.width > getWindowSize.height && getWindowSize.width.dp / density.density > 1200.dp) Alignment.Center else Alignment.BottomCenter } }
8479

8580
if (!dialogStates.contains(show)) dialogStates.add(show)
8681
LaunchedEffect(show.value) {
@@ -99,8 +94,6 @@ fun SuperDialog(
9994
Modifier
10095
.imePadding()
10196
.navigationBarsPadding()
102-
.windowInsetsPadding(WindowInsets.displayCutout.only(WindowInsetsSides.Horizontal))
103-
.windowInsetsPadding(WindowInsets.captionBar.only(WindowInsetsSides.Top))
10497
} else {
10598
Modifier
10699
}
@@ -117,7 +110,7 @@ fun SuperDialog(
117110
) {
118111
Column(
119112
modifier = modifier
120-
.then(if (contentAlignment != Alignment.Center) Modifier.fillMaxWidth() else Modifier.widthIn(max = 400.dp))
113+
.widthIn(max = 420.dp)
121114
.pointerInput(Unit) {
122115
detectTapGestures { /* Do nothing to consume the click */ }
123116
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import androidx.compose.ui.text.rememberTextMeasurer
5353
import androidx.compose.ui.text.style.TextAlign
5454
import androidx.compose.ui.unit.Dp
5555
import androidx.compose.ui.unit.DpSize
56+
import androidx.compose.ui.unit.LayoutDirection
5657
import androidx.compose.ui.unit.dp
5758
import androidx.compose.ui.unit.sp
5859
import top.yukonga.miuix.kmp.basic.BasicComponent
@@ -191,7 +192,6 @@ fun SuperDropdown(
191192
modifier = if (defaultWindowInsetsPadding) {
192193
modifier
193194
.windowInsetsPadding(WindowInsets.displayCutout.only(WindowInsetsSides.Horizontal))
194-
.windowInsetsPadding(WindowInsets.captionBar.only(WindowInsetsSides.Top))
195195
} else {
196196
modifier
197197
}
@@ -206,7 +206,11 @@ fun SuperDropdown(
206206
) {
207207
LazyColumn(
208208
modifier = Modifier
209-
.padding(horizontal = (windowWeightPx.dp - componentWidthPx.dp) / 2 / density.density)
209+
.padding(
210+
horizontal = (windowWeightPx.dp - componentWidthPx.dp) / 2 / density.density - if (defaultWindowInsetsPadding)
211+
(WindowInsets.displayCutout.asPaddingValues(density).calculateLeftPadding(LayoutDirection.Ltr) +
212+
WindowInsets.displayCutout.asPaddingValues(density).calculateRightPadding(LayoutDirection.Ltr)) / 2 else 0.dp
213+
)
210214
.onGloballyPositioned { layoutCoordinates ->
211215
dropdownHeightPx = layoutCoordinates.size.height
212216
offsetPx = calculateOffsetPx(

0 commit comments

Comments
 (0)