我在sheetState.progress.fraction
中遇到了问题。
它本来工作得很好,但现在没有解决。不知道为什么?
Text(
text = "Toggle Sheet fraction ${sheetState.progress.fraction}",
color = Color.White
)
这是我一直在做的事
@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
)
}
}
}
}
}
}
}
有谁能帮我解决这个问题吗?
1条答案
按热度按时间qhhrdooz1#
你可以使用sheetState.currentFraction来获取底部工作表位置的当前分数
这样编辑代码:
通过使用sheetState.currentFraction而不是sheetState.progress.fraction,您应该能够访问底部工作表位置的当前分数。