https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

03/14/2023, 3:02 AM
Trying to meet my design specs of having a carousel of cards. Each card should be 90 percent of the width, and due to decisions made before me, I can't use a Modifier to complete this ask. Or else, I would just do fillMaxWidth(.9F) or something. Is there any other easy way to do get a dp value of 90 percent of the width? I'm assuming BoxWithConstraints, but I'd like not to use that if theres another way I just don't know about?
f

Francesc

03/14/2023, 3:43 AM
I'm not clear on what the restriction is, could you elaborate? Can you wrap your composable in a a
Box
and then set the child's width to 90%?
c

Colton Idle

03/14/2023, 3:51 AM
I'm basically unfortunately forced to using a component that requires me to pass in a set size for a width. 😭
Everywhere else in the codebase uses a root boxWithConstraints layout, but I'm working on a new part, and I didn't move to bWC just yet, but would love to not use it if I don't have to.
b

Ben Trengrove [G]

03/14/2023, 3:57 AM
Is the carousel lazy?
"Everywhere else in the codebase uses a root boxWithConstraints layout" this is slightly concerning
You should use BoxWithConstraints when you actually need to change what composables you are composing based off constraint information, if you are just using it to get the width and height and do some layout then you should just be using a custom layout
c

Colton Idle

03/14/2023, 4:18 AM
Yeah. I am also concerned. I think the gist of it is that the people that were here building it first don't really know how to build a lazyRow with cards that peak. This entire "carousel" sort of pattern that is super pattern is kinda tough I guess. there's so many ways to implement it. I'm sure I've also done some weird things to acieve a 90% width for a card in the past. And I'm honestly not even sure what the rec way would be to do this in a brand new app.
¯\_(ツ)_/¯
b

Ben Trengrove [G]

03/14/2023, 4:27 AM
The way to do it is just
Modifier.fillParentMaxWidth(0.9f)
So your item composable doesn't take a modifier parameter or something and you can't change it?
f

Francesc

03/14/2023, 4:31 AM
You can use
onGloballyPositioned
if you don't mind a one frame delay
5 Views