https://kotlinlang.org logo
b

Bassam A.

04/17/2022, 10:48 PM
Does anyone know why my preview, does not look like the emulator? (I’ve restarted it so many times).
g

Guilherme Cordeiro

04/18/2022, 12:31 PM
Is it possible that the view or viewgroup you are displaying receives some properties from a theme or style? Or that the initialization of it happens programmatically?
if it uses a theme or style, maybe you just have to change it on your layout inspector attributes (the top bar on the "design" tab)
Also, if it is a custom view compiled in another module, the layout inspector may run into trouble finding all the custom attributes during the preview
z

Zach Klippenstein (he/him) [MOD]

04/18/2022, 4:46 PM
It looks like the preview is passing fixed constraints down (e.g.
fillMaxSize
), but whatever is hosting your composable in your app is not. For this sort of component, you probably don’t need the full device frame decoration in the preview, so you can turn that off then the preview should just let your component be whatever size it wants. But if you do want the frame decoration, then in your preview apply the
wrapContentSize
modifier to your composable.
c

Chris Sinco [G]

04/18/2022, 5:57 PM
Also please provide the code for your Preview function, as that can help us debug
Also, if you're using Bumblebee there is a bad caching bug that can be fixed by closing and reopening the Compose file with the Preview that doesn't seem to update
b

Bassam A.

04/19/2022, 1:03 PM
Thanks @Zach Klippenstein (he/him) [MOD]
wrapContentSize
solved the issue.
@Chris Sinco [G] I understand your point, I tried several times before I submit it here.
👍 1
@Guilherme Cordeiro Thanks for the participation, I am adapting compose in this project, and the solution to add
wrapContentSize
modifier.
4 Views