dorche
03/23/2023, 4:52 PMBottomSheetScaffold
has had a regression - it used to work fine with a LazyColumn but now the dragging of the sheet is broken if you do it in the bounds of the LazyColumn. Min repro in 🧵dorche
03/23/2023, 4:53 PMpackage com.example.bottomsheetrepro
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.material3.rememberStandardBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.bottomsheetrepro.ui.theme.BottomSheetReproTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BottomSheetReproTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
MyBottomSheetScaffold()
}
}
}
}
}
@Composable
fun MyLazyColmn() {
Column(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
.background(Color.Red)
) {
Text(
text = "drag/flick works here",
fontSize = 24.sp,
modifier = Modifier.align(alignment = CenterHorizontally)
)
}
LazyColumn(
state = rememberLazyListState(),
) {
item {
Box(
modifier = Modifier
.fillMaxWidth()
.height(500.dp)
.background(Color.Cyan)
) {
Text(
text = "but broken here",
fontSize = 24.sp,
modifier = Modifier.align(Alignment.TopCenter)
)
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MyBottomSheetScaffold() {
BottomSheetScaffold(
scaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberStandardBottomSheetState(SheetValue.PartiallyExpanded)
),
sheetContent = {
MyLazyColmn()
},
sheetDragHandle = null,
) {
Column(
Modifier
.fillMaxSize()
.background(Color.Yellow)
) {
repeat(30) {
Text(
text = "Some text",
fontSize = 24.sp,
modifier = Modifier.align(alignment = CenterHorizontally)
)
}
}
}
}
@Preview(showBackground = true)
@Composable
fun ReproPreview() {
BottomSheetReproTheme {
MyBottomSheetScaffold()
}
}
jw
03/23/2023, 4:58 PMdorche
03/23/2023, 5:01 PMdorche
03/23/2023, 5:19 PM