dorche
07/08/2022, 11:01 AMBottomSheetScaffold
is not rendering properly in Previews (only Preview as far as I can see) on androidx.compose.material:material:1.2.0-beta03
but it does on the previous version - androidx.compose.material:material:1.2.0-beta02
. More in 🧵class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BottomSheetStateIssueTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
BottomSheetBug()
}
}
}
}
}
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun BottomSheetBug() {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed)
)
val coroutineScope = rememberCoroutineScope()
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
Box(
Modifier
.fillMaxWidth()
.height(200.dp)
.background(Color.Cyan)
) {
Text(text = "Hello from sheet")
}
},
sheetPeekHeight = 50.dp,
contentColor = Color.Red
) {
Box(modifier = Modifier.height(200.dp)) {
Button(onClick = {
coroutineScope.launch {
if (bottomSheetScaffoldState.bottomSheetState.isCollapsed) {
bottomSheetScaffoldState.bottomSheetState.expand()
} else {
bottomSheetScaffoldState.bottomSheetState.collapse()
}
}
}) {
Text(text = "Expand/Collapse Bottom Sheet")
}
}
}
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
BottomSheetStateIssueTheme {
BottomSheetBug()
}
}
the Preview shows this on the beta03 version:BottomSheetScaffold
which I’m guessing broke that https://developer.android.com/jetpack/androidx/releases/compose-material#1.2.0-beta03jossiwolf
07/11/2022, 3:46 PMdorche
07/13/2022, 8:16 PMjossiwolf
07/14/2022, 4:49 PMTristan Hamilton
08/08/2022, 5:15 PMdorche
08/08/2022, 5:17 PMTristan Hamilton
08/08/2022, 5:52 PMdorche
08/08/2022, 5:56 PMimplementation("androidx.compose.material:material") {
version {
// todo remove when BottomSheetScaffold Preview Bug is fixed
strictly '1.2.0-beta02'
}
}
That’s the latest version I found to be working fine at the time.
This is what I did for our project because we absolutely depend on the previews working fineTristan Hamilton
08/09/2022, 11:17 AM1.0.0
, 1.1.0
, 1.2.0-alpha0X
etc), the preview does not show the expanded bottom sheet, only the scrim has rendered.
When you click interactive mode, the modal pops up.
This seems different to your issue listed above so I’ll submit a ticket for this case anyway.jossiwolf
08/11/2022, 12:38 PMBottomSheetScaffold
- we reverted the change that surfaced the bug in that. The issue you are seeing has the same root cause though which we are working on fixing, but it will be a bit still. I might mark your issue as duplicate and then you can follow along in the OG bug 🙂Tristan Hamilton
08/11/2022, 12:40 PM