forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash, add reduced repro (#1163)
## Proposed Changes Add reduced reported issue repro, fix logical error in `SortedSet.add`. ## Testing Test: `SortedSetTest.checkExistingWhenAdded`, no crash happens in reported scenario. ## Issues Fixed Fixes: JetBrains/compose-multiplatform#4422
- Loading branch information
1 parent
6a3c503
commit 0456a30
Showing
4 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
compose/mpp/demo/src/uikitMain/kotlin/bugs/MeasureAndLayoutCrash.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package bugs | ||
|
||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.rememberLazyListState | ||
import androidx.compose.material.Checkbox | ||
import androidx.compose.material.Text | ||
import androidx.compose.mpp.demo.Screen | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import kotlinx.coroutines.delay | ||
|
||
@Composable | ||
fun RowItem(index: Int) { | ||
Row(modifier = Modifier.padding(end = 30.dp)) { | ||
var state by remember(index) { mutableStateOf<Unit?>(null) } | ||
|
||
LaunchedEffect(index) { | ||
delay((100..200).random().toLong()) | ||
state = Unit | ||
} | ||
state?.let { | ||
Text("Item $index") | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun RowItem(wrapInBox: Boolean, index: Int) { | ||
if (wrapInBox) { | ||
Box { | ||
RowItem(index) | ||
} | ||
} else { | ||
RowItem(index) | ||
} | ||
} | ||
|
||
val MeasureAndLayoutCrash = Screen.Example("MeasureAndLayoutCrash") { | ||
val lazyColumnState = rememberLazyListState() | ||
var enableCrash by remember { mutableStateOf(false) } | ||
|
||
Column( | ||
modifier = Modifier.safeContentPadding() | ||
) { | ||
Row(verticalAlignment = Alignment.CenterVertically) { | ||
Checkbox( | ||
checked = enableCrash, | ||
onCheckedChange = { enableCrash = it }, | ||
modifier = Modifier.padding(16.dp), | ||
) | ||
|
||
Text("Enable crash") | ||
} | ||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) { | ||
LazyColumn( | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
state = lazyColumnState, | ||
) { | ||
items(1000) { index -> | ||
RowItem(enableCrash, index) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters