英文:
Bottom Sheet: Unresolved reference: fraction
问题
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?
英文:
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?
答案1
得分: 2
你可以使用sheetState.currentFraction
来获取底部抽屉的当前位置的分数。
修改代码如下:
Button(onClick = {
scope.launch {
if (sheetState.isCollapsed) {
sheetState.expand()
} else {
sheetState.collapse()
}
}
}) {
Text(
text = "切换抽屉分数 ${sheetState.currentValue}",
color = Color.White
)
}
通过使用sheetState.currentFraction
而不是sheetState.progress.fraction
,你应该能够访问底部抽屉当前位置的分数。
英文:
you can use sheetState.currentFraction to get the current fraction of the bottom sheet's position
edit the code like this:
Button(onClick = {
scope.launch {
if (sheetState.isCollapsed) {
sheetState.expand()
} else {
sheetState.collapse()
}
}
}) {
Text(
text = "Toggle Sheet fraction ${sheetState.currentValue}",
color = Color.White
)
}
By using sheetState.currentFraction instead of sheetState.progress.fraction, you should be able to access the current fraction of the bottom sheet's position.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论