Chris Fillmore
09/01/2022, 3:19 PMChris Fillmore
09/01/2022, 3:19 PM[header with gray background and black text]
[icon][descriptive text][optional control]
[icon][descriptive text][optional control]
...
etc
Chris Fillmore
09/01/2022, 3:20 PMprivate val bottomSheetPadding = PaddingValues(horizontal = 24.dp, vertical = 16.dp)
private val bottomSheetItemPadding = PaddingValues(horizontal = 24.dp, vertical = 12.dp)
@Composable
fun BottomSheetScreen(
headerContent: @Composable (PaddingValues) -> Unit,
mainContent: @Composable BottomSheetContentScope.(PaddingValues) -> Unit,
) {
val scrollState = rememberScrollState()
Column(
modifier = Modifier.verticalScroll(scrollState),
) {
Surface(
color = PaleGrey,
contentColor = Color.Black,
) {
headerContent(bottomSheetPadding)
}
Surface(
color = Color.White,
) {
BottomSheetContentScopeImpl.mainContent(bottomSheetPadding)
}
}
}
interface BottomSheetContentScope {
fun item(content: (PaddingValues) -> Unit)
}
object BottomSheetContentScopeImpl : BottomSheetContentScope {
override fun item(content: (PaddingValues) -> Unit) {
content(bottomSheetItemPadding)
}
}
Chris Fillmore
09/01/2022, 3:21 PMFilip Wiesner
09/01/2022, 3:22 PMBottomSheetContentScope
? 🤔 Why not just a normal composable slot? content: @Composable () -> Unit
Chris Fillmore
09/01/2022, 3:23 PMPaddingValues
, so that each row can have consistent paddingChris Fillmore
09/01/2022, 3:24 PMChris Fillmore
09/01/2022, 3:27 PM@Composable
fun BottomSheetRow(content: @Composable (PaddingValues) -> Unit) {
content(bottomSheetItemPadding)
}
Filip Wiesner
09/01/2022, 3:27 PM@Composable
fun BottomSheetScreen(
headerContent: @Composable () -> Unit,
mainContent: @Composable () -> Unit,
) {...}
@Composable
fun BottomSheetScreenContentColumn(itemPadding: PaddingValues) {...}
Filip Wiesner
09/01/2022, 3:28 PMFilip Wiesner
09/01/2022, 3:32 PMChris Fillmore
09/01/2022, 3:32 PMChris Fillmore
09/01/2022, 3:33 PMChris Fillmore
09/01/2022, 3:33 PMFilip Wiesner
09/01/2022, 3:39 PMControlBottomSheet(
headerContent = {
Header(Modifier.padding(paddingValues))
}
) {
ControlColumn(
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
ControlItem(
icon = painter(<http://R.drawable.xyz|R.drawable.xyz>),
text = stringResource(R.string.text),
)
ControlItem(
icon = painter(R.drawable.abc),
text = stringResource(R.string.text2),
) {
Switch(
enabled = switchEnabledState,
onEnabledChange = { onEnablecChange(it) }
)
}
}
}
Chris Fillmore
09/01/2022, 4:28 PMspacedBy
won’t work hereChris Fillmore
09/01/2022, 4:30 PMFilip Wiesner
09/01/2022, 4:36 PMList<ControlViewItem>
), you could just iterate over the data and pass in the same Modifier. That'll result in uniform padding.
Example:
for (control in controls) {
ControlItem(control, Modifier.padding(paddingValue)
}
Filip Wiesner
09/01/2022, 4:39 PMControlViewItem
in one place and call specific items in other place.