Stylianos Gakis
02/22/2023, 12:41 PMColumn(.verticalScroll().windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal))) {
TopAppBar(
contentPadding = WindowInsets.safeDrawing.only(<http://WindowInsetsSides.Top|WindowInsetsSides.Top> + WindowInsetsSides.Horizontal).asPaddingValues(),
)
Stuff()
Spacer(windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)))
}
But this way, the TopAppBar gets the horizontal padding applied to it which I do not want as the top app bar now doesn’t go edge to edge when in landscape mode and there’s navigation buttons, as that should be handled by the insets passed in its contentPadding. Is there some way to achieve my goal with this structure, or do I have to make it so that I do something like
Column(.verticalScroll()) {
TopAppBar(
contentPadding = WindowInsets.safeDrawing.only(<http://WindowInsetsSides.Top|WindowInsetsSides.Top> + WindowInsetsSides.Horizontal).asPaddingValues(),
)
Column(
.windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal))
.weight(1f) // <-- got some problems with this
) {
Stuff()
Spacer(windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)))
}
}
But I can’t go with #2 (unless I fix this somehow), as that way if I put the weight(1f) on the inner column, it doesn’t scroll at all when the content fills the entire height. And if I don’t put the weight(1f) the inner column doesn’t take up the entire space, so this column in column situation is more tricky than I’d like it to be.Tgo1014
02/22/2023, 2:01 PMScaffold
instead of Column
? It has a lambda specially for TopAppBar
content that's supposed to handle the system paddings properly for you.Stylianos Gakis
02/22/2023, 2:24 PMlayout()
modifier or something like that, but I’d rather avoid this, as it’d look quite complex I think.
• I can’t put a column inside a scrolling column and still have it force take up the entire screen height when there is no need to scroll, while also letting it take up more than the available space when there is enough content in order to warrant scrolling.
I know this may be too much, if anything it’s serving as a way for myself to rubber duck myself, I will try the forcing the TopAppBar to take more space than that the constraints passed to it by forcing it in a layout {}
modifier as a first step.Alex Vanyo
02/22/2023, 5:39 PMStylianos Gakis
02/22/2023, 5:52 PMAlex Vanyo
02/22/2023, 5:57 PMStuff()
? What happens if you put a Spacer
with weight(1f)
inside the inner Column
, instead of on the inner Column
itself?Stylianos Gakis
02/22/2023, 8:55 PMverticalScroll
modifier makes the content wrap its height, which as I understand it needs to do in order to then know when it actually needs to scroll when the content doesn’t fit in the visible content.Alex Vanyo
02/22/2023, 9:26 PMSpacer
s with weights outside the inner column, and maybe add a second inner column that also has the horizontal padding applied if needed.Column
Stylianos Gakis
02/22/2023, 9:44 PM@Composable
private fun TopAppBar(navigateBack: () -> Unit) {
val horizontalPaddings = WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal).asPaddingValues()
val layoutDirection = LocalLayoutDirection.current
TopAppBarWithBack(
...,
contentPadding = WindowInsets.safeDrawing
.only(<http://WindowInsetsSides.Top|WindowInsetsSides.Top> + WindowInsetsSides.Horizontal)
.asPaddingValues(),
modifier = Modifier.layout { measurable, constraints ->
val leftInsets = horizontalPaddings.calculateLeftPadding(layoutDirection).roundToPx()
val rightInsets = horizontalPaddings.calculateRightPadding(layoutDirection).roundToPx()
val requiredWidth = constraints.maxWidth + leftInsets + rightInsets
val expandedConstraints = constraints.copy(
minWidth = requiredWidth,
maxWidth = requiredWidth,
)
val placeable = measurable.measure(expandedConstraints)
// When going above the max size of parent, it gets centered, so we need to find the *real* 0 position of the parent here
val actualZeroXPositionOfParent = (requiredWidth - constraints.maxWidth) / 2
layout(placeable.width, placeable.height) {
placeable.place(actualZeroXPositionOfParent - leftInsets, 0)
}
},
)
}
This way my original column can stay as I originally wanted it to be, with fillMaxSize().verticalScroll().windowInsetsPadding(Horizontal), and then no inner column needed.
Now I don’t know if I’d live to regret this, what do you think of it as an idea?
(Also works fine with Ltr-Rtl it seems, which is a bonus 🤩)Alex Vanyo
02/22/2023, 10:20 PM