I am facing problem here in sheetState.progress.fraction.
It was working fine, but now it is unresolved. don't know why?
Text(
text = "Toggle Sheet fraction ${sheetState.progress.fraction}",
color = Color.White
)
here is what I have been doing...
@ExperimentalMaterialApi
class BottomSheetActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyComposableTheme {
val sheetState = rememberBottomSheetState(
initialValue = BottomSheetValue.Collapsed
,animationSpec = SpringSpec(
dampingRatio = Spring.DampingRatioHighBouncy
)
)
val scaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = sheetState
)
val scope = rememberCoroutineScope()
BottomSheetScaffold(
scaffoldState = scaffoldState,
sheetContent = {
Box(
modifier = Modifier
.fillMaxWidth()
.height(300.dp),
contentAlignment = Alignment.Center
) {
Text(
text = "BottomSheet",
fontSize = 60.sp,
color = Color.White
)
}
},
sheetBackgroundColor = Color.Black,
sheetPeekHeight = 0.dp
) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Button(onClick = {
scope.launch {
if (sheetState.isCollapsed) {
sheetState.expand()
} else {
sheetState.collapse()
}
}
}) {
Text(
text = "Toggle Sheet fraction ${sheetState.progress.fraction}",
color = Color.White
)
}
}
}
}
}
}
}
can anyone help me to resolve this problem please?
In the material3 version androidx.compose.material3:material3:1.1.2 corresponding to the BOM version(23.10.01) you can create the state by the following code below
val offsetBottomSheet by remember(sheetState) {
derivedStateOf {
runCatching { sheetState.requireOffset() }.getOrDefault(0F)
}
}
I have wrapped the sheetState.requireOffset() in runCatching as requireOffset will throw IllegalStateException when sheetConent has not been through a measurement pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With