[英]Floating Button goes up with Bottom Sheet Jetpack Compose
I don't understand why the FloatingButton
is going up with the BottomSheet
.我不明白为什么FloatingButton
会随着BottomSheet
上升。
I tried to change the sheetElevation
which is higher than the elevation of the FloatingButton
, but the issue remains.我试图更改高于FloatingButton
高度的sheetElevation
,但问题仍然存在。 That's because the code inside BottomSheetScaffoldStack
says to move the FloatingButton
up along with the BottomSheet
.那是因为BottomSheetScaffoldStack
中的代码说要将FloatingButton
与BottomSheet
一起向上移动。 Is there any way to avoid that?有没有办法避免这种情况?
Here is the code of the BottomSheetScaffold
:这是BottomSheetScaffold
的代码:
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
topBar = { TopBar(
areButtonShowed = true,
title = topBarTitle,
onBackPressed = { BendRouter.navigateTo(onBackDestination) }
) },
floatingActionButtonPosition = FabPosition.Center,
floatingActionButton = {
ExtendedFloatingButton(
text = context.getString(R.string.start),
onClick = {}, // TODO
modifier = Modifier
.fillMaxWidth()
.height(45.dp)
.padding(
start = 24.dp,
end = 24.dp
),
backgroundColor = PureWhite
)
Spacer(modifier = Modifier.height(150.dp))
},
sheetBackgroundColor = PureWhite,
sheetPeekHeight = 0.dp,
sheetElevation = 70.dp,
sheetShape = RoundedCornerShape(50.dp),
sheetContent = {
openStretchDetails?.let { stretch ->
BottomSheetView(stretch = stretch)
}
},
content = { RoutinePageView(viewModel) }
)
And ExtendedFloatingButton
:和ExtendedFloatingButton
:
@Composable
fun ExtendedFloatingButton(
text: String,
@DrawableRes icon: Int? = null,
onClick: () -> Unit,
modifier: Modifier = Modifier,
elevation: Dp = 12.dp,
backgroundColor: Color
) {
ExtendedFloatingActionButton(
text = {
Text(
text = text.uppercase(),
color = Gray,
fontSize = 18.sp,
maxLines = 1,
fontWeight = FontWeight.Bold,
letterSpacing = .5.sp
)
},
onClick = onClick,
icon = {
icon?.let {
Icon(
painter = painterResource(id = it),
contentDescription = ""
)
}
},
modifier = modifier,
elevation = FloatingActionButtonDefaults.elevation(elevation),
backgroundColor = backgroundColor
)
}
SOLVED!解决了! The BottomSheetScaffold
has a default behavior that you can see by clicking on it while pressing CTRL. BottomSheetScaffold
有一个默认行为,您可以通过在按住 CTRL 的同时单击它来查看它。 Looking at BottomSheetScaffoldStack
inside the BottomSheetScaffold.kt
class you'll see how the FloatingButton
is moved along with the BottomSheet
.查看BottomSheetScaffoldStack
class 中的BottomSheetScaffold.kt
您将看到FloatingButton
如何与BottomSheet
一起移动。
To solve this problem I used ModalBottomSheetLayout
instead of BottomSheetScaffold
.为了解决这个问题,我使用ModalBottomSheetLayout
而不是BottomSheetScaffold
。
ModalBottomSheetLayout(
sheetState = bottomState,
sheetContent = {
Box(Modifier.defaultMinSize(minHeight = 1.dp)) {
openStretchDetails?.let { stretch ->
BottomSheetView(stretch = stretch)
coroutineScope.launch {
bottomState.animateTo(ModalBottomSheetValue.Expanded)
}
}
}
},
sheetBackgroundColor = PureWhite,
sheetElevation = 16.dp,
sheetShape = RoundedCornerShape(50.dp),
) {
Scaffold(
topBar = { TopBar(
areButtonShowed = true,
title = topBarTitle,
onBackPressed = { BendRouter.navigateTo(onBackDestination) }
) },
floatingActionButtonPosition = FabPosition.Center,
floatingActionButton = {
ExtendedFloatingButton(
text = context.getString(R.string.start),
onClick = {}, // TODO
modifier = Modifier
.fillMaxWidth()
.height(45.dp)
.padding(
start = 24.dp,
end = 24.dp
),
backgroundColor = PureWhite
)
Spacer(modifier = Modifier.height(150.dp))
},
content = { RoutinePageView(viewModel) }
)
}
Add this on the top:在顶部添加:
val bottomState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
confirmStateChange = { it != ModalBottomSheetValue.HalfExpanded }
)
val coroutineScope = rememberCoroutineScope()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.