Is there a way in compose to define an Image fun w...
# compose
d
Is there a way in compose to define an Image fun where you only provide the height and width of the image and not of the view 🧵
So I want to say an image is 16x16 and padding is 20x20. I could put padding modifier first but I am doing server driven UI where modifiers are provided by the backend in a particular order. I am sure that is not recommended but I would still like to understand how this could be possible. Whenever you setup a height and width all padding that you do after that is within that fixed height width. But I do not want the whole view to have a fixed height width but the image. Hopefully thats clear.
f
So if you have to specify size first and then padding, why don't you add the padding to the size?
Copy code
Modifier.size(sizeDp + paddingDp).padding(paddingDp)
Maybe I just don't understand the question 😅
👍 1
🧠 1
d
I think you understand the question. Yeah I think I could do that. Any other ways? I was hoping to not have to deal with the side effects of how height and width make it fixed and just set the image sizes but that might not be posssible
I tested it out btw and it works. But it gets more complicated. Such as if you add a border you also need to add that to the size and potentially other modifiers that need to adjust size.
f
I think that border does not add size but otherwise yes. I guess you are looking for something like
margin
but that's not how the Modifier system works. The order does matter and it matter intentionally. Let me see if I can find a thread on modifiers where Adam Powell talks about this.
side effects of how height and width make it fixed
How is that a side effect? I think that it is THE effect.
👍 1