Joe Altidore
04/28/2023, 12:52 PMLayout(
modifier = modifier.background(Colors.Transparent),
content = {
drawerContents()
content()
}
)
But if i provide other colors, they are applied. How do i work around this. ThanksTravis
04/28/2023, 6:51 PM@Composable
fun MyLayout(
drawerContents: @Composable () -> Unit,
modifier: Modifier = Modifier,
backgroundColor: Color = Color.Transparent,
content: @Composable () -> Unit,
) {
val backgroundModifier =
if(backgroundColor != Color.Transparent) Modifier.background(backgroundColor)
else Modifier
Layout(
modifier = modifier.then(backgroundModifier),
content = {
drawerContents()
content()
}
)
}
Joe Altidore
04/28/2023, 6:53 PMTravis
04/28/2023, 6:58 PMJoe Altidore
04/28/2023, 7:01 PMTravis
04/28/2023, 8:10 PMcontent()
block of your layout contains the background color you're seeing.
Though that wouldn't explain why a Modifier.background on the Layout with, say, Color.Blue would show up blue, since your scaffold should cover that up too.Joe Altidore
04/28/2023, 9:19 PMTravis
04/28/2023, 9:20 PMJoe Altidore
04/28/2023, 9:25 PMTravis
04/28/2023, 9:27 PMJoe Altidore
04/28/2023, 9:43 PM@Composable
fun MyLayout(
modifier: Modifier,
state: AnimatedDrawerState = rememberAnimatedDrawerState(
drawerWidth = 280.dp,
),
drawer: @Composable () -> Unit,
bottomSheetScaffold: @Composable () -> Unit
) {
Layout(
modifier = modifier,
content = {
drawer()
bottomSheetScaffold()
}
) { measurables, constraints ->
val (drawerContentMeasurable, contentMeasurable) = measurables
val drawerContentConstraints = Constraints.fixed(
width = state.drawerWidth.coerceAtMost(constraints.maxWidth.toFloat()).toInt(),
height = constraints.maxHeight,
)
val drawerContentPlaceable = drawerContentMeasurable.measure(drawerContentConstraints)
val contentConstraints = Constraints.fixed(
width = constraints.maxWidth,
height = constraints.maxHeight,
)
val contentPlaceable = contentMeasurable.measure(contentConstraints)
layout(
width = constraints.maxWidth,
height = constraints.maxHeight,
) {
contentPlaceable.placeRelativeWithLayer(
IntOffset.Zero,
) {
transformOrigin = state.contentTransformOrigin
scaleX = state.contentScaleX
scaleY = state.contentScaleY
translationX = state.contentTranslationX
}
drawerContentPlaceable.placeRelativeWithLayer(
IntOffset.Zero,
) {
translationX = state.drawerTranslationX
shadowElevation = state.drawerElevation
}
}
}
}
This is my layout@OptIn(ExperimentalMaterialApi::class)
@Composable
fun MyIndex(
modifier: Modifier = Modifier,
peekHeight: Float
) {
val sheetPeekHeight by animateDpAsState(
targetValue = peekHeight.dp,
animationSpec = spring(stiffness = Spring.StiffnessLow)
)
val animation = remember { Animatable(0f) }
val drawerState = rememberAnimatedDrawerState(
drawerWidth = (LocalConfiguration.current.screenWidthDp - 68).dp ,
animation
)
val scope = rememberCoroutineScope()
val scaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberBottomSheetState(initialValue = BottomSheetValue.Collapsed),
)
MyLayout(
modifier = modifier,
state = drawerState,
drawer = {
//Drawer Content
}
) {
BottomSheetScaffold(
sheetContent = {
//Sheet content
},
sheetShape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp),
sheetPeekHeight = sheetPeekHeight,
scaffoldState = scaffoldState
) {
AndroidView(
factory = {context ->
MapView(context).apply {
onCreate(null)
onResume()
getMapAsync {
}
}
},
modifier = modifier.background(Color.Transparent),
)
NavHost(
navController = rememberNavController(),
startDestination = "start_route",
modifier = modifier.background(Color.Yellow)
){
//My Routes Here
}
}
}
}
Travis
05/01/2023, 10:15 PM