Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a logical error causing Compose tree corruption and consequent crash on iOS #1163

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion compose/mpp/demo/src/uikitMain/kotlin/bugs/IosBugs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ val IosBugs = Screen.Selection(
DropdownMenuIssue,
KeyboardIMEActionPopup,
ProperContainmentDisposal,
ComposeAndNativeScroll
ComposeAndNativeScroll,
MeasureAndLayoutCrash
)
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)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ internal actual class SortedSet<E> actual constructor(
var index = list.binarySearch(element, comparator)
if (index < 0) {
index = -index - 1
} else {
return false
}
list.add(index, element)
MatkovIvan marked this conversation as resolved.
Show resolved Hide resolved
return true
Expand Down