Skip to content

Commit

Permalink
library: Fix effect of displayCutoutSize on Dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Oct 15, 2024
1 parent ebe10f7 commit fc4832c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import top.yukonga.miuix.kmp.basic.BasicComponent
Expand Down Expand Up @@ -190,6 +191,9 @@ fun SuperDropdown(
with(density) { WindowInsets.captionBar.asPaddingValues().calculateBottomPadding().toPx() }.roundToInt()
)
val insideHeightPx by rememberUpdatedState(with(density) { insideMargin.height.toPx() }.roundToInt())
val displayCutoutLeftSize = rememberUpdatedState(with(density) {
WindowInsets.displayCutout.asPaddingValues(density).calculateLeftPadding(LayoutDirection.Ltr).toPx()
}.roundToInt())
val paddingPx by rememberUpdatedState(with(density) { horizontalPadding.toPx() }.roundToInt())

BackHandler(enabled = isDropdownExpanded.value) { dismissPopup(isDropdownExpanded) }
Expand Down Expand Up @@ -217,9 +221,9 @@ fun SuperDropdown(
modifier = Modifier
.onGloballyPositioned { layoutCoordinates ->
offsetXPx = if (alwaysRight || !alignLeft) {
dropdownOffsetXPx + componentWidthPx - layoutCoordinates.size.width - paddingPx
dropdownOffsetXPx + componentWidthPx - layoutCoordinates.size.width - paddingPx - if (defaultWindowInsetsPadding) displayCutoutLeftSize.value else 0
} else {
dropdownOffsetXPx + paddingPx
dropdownOffsetXPx + paddingPx - if (defaultWindowInsetsPadding) displayCutoutLeftSize.value else 0
}
offsetYPx = calculateOffsetYPx(
windowHeightPx,
Expand Down

0 comments on commit fc4832c

Please sign in to comment.