底部面板:未解决的引用:fraction

huangapple go评论63阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月17日 13:07:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76031870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定