Skip to content

Commit f9694f3

Browse files
committed
library: Optimize ListPopup performance
* No need to calculate position when not expanded
1 parent 3dba7cb commit f9694f3

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

example/src/commonMain/kotlin/SecondPage.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fun SecondPage(
3636

3737
val dropdownOptions = listOf("Option 1", "Option 2", "Option 3", "Option 4")
3838
val dropdownSelectedOption = remember { mutableStateOf(0) }
39-
var ii = remember { mutableStateOf(10) }
39+
var ii = remember { mutableStateOf(8) }
4040

4141
LaunchedEffect(pullToRefreshState.isRefreshing) {
4242
if (pullToRefreshState.isRefreshing) {
@@ -50,7 +50,7 @@ fun SecondPage(
5050

5151
PullToRefresh(
5252
pullToRefreshState = pullToRefreshState,
53-
onRefresh = { ii.value++ },
53+
onRefresh = { ii.value += 4 },
5454
contentPadding = PaddingValues(top = padding.calculateTopPadding())
5555
) {
5656
LazyColumn(

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/ListPopup.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ fun ListPopup(
7474
minWidth: Dp = 200.dp,
7575
content: @Composable () -> Unit
7676
) {
77+
if (!show.value) return
78+
7779
val currentOnDismissRequest by rememberUpdatedState(onDismissRequest)
7880
val currentContent by rememberUpdatedState(content)
7981

@@ -159,7 +161,7 @@ fun ListPopup(
159161
enableWindowDim = enableWindowDim,
160162
transformOrigin = { rememberedTransformOrigin },
161163
) {
162-
val currentOffset by rememberUpdatedState(offset) // Used for placement
164+
val currentOffset by rememberUpdatedState(offset)
163165
val shape: Shape = remember { SmoothRoundedCornerShape(16.dp) }
164166
val rememberedElevationPx = remember(density, shadowElevation) { with(density) { shadowElevation.toPx() } }
165167

@@ -177,7 +179,7 @@ fun ListPopup(
177179
windowSize
178180
) {
179181
popupModifier
180-
.pointerInput(currentOnDismissRequest) { // Keyed by the updated state object
182+
.pointerInput(currentOnDismissRequest) {
181183
detectTapGestures {
182184
currentOnDismissRequest?.invoke()
183185
}

0 commit comments

Comments
 (0)