Why not make `@Preview` workable with Composable f...
# compose
g
Why not make
@Preview
workable with Composable functions with arguments? As I understand almost all arguments are data classes. Compiler can instantiate them using primary constructor. For example:
Copy code
data class Post(
    val title: String,
    val description: String
)
Default instance for this class can be
Post("Title", "Description")
. Same with Lists of data classes, but compiler can add index for each instance
Post("Title β„–0", "Description β„–0")
,
Post("Title β„–1", "Description β„–1")
, etc. So in most cases you don't need to create special preview composable functions or mess around with
@PreviewParameter
. What do you think?
πŸ‘Ž 4
πŸ‘ 3
c
I think it's a cool idea to make things quicker to prototype, but at the same time I think it's always useful to be using "real-ish" data for composables right from the start or else some faulty assumptions are bound to bite you later on. Perhaps the reason it seems hard to write the default values in the preview composable function or data class is because you need to think about what might actually go there?
βž• 1
I haven't tried it but if you're really lazy to think of real-ish data something like https://github.com/serpro69/kotlin-faker could be fun πŸ˜„
πŸ‘ 1
g
@caelum19 I noticed that I fill my data classes with absolutely random values, because I don't care what values I want to see on screen. But know I am realising that subconsciously I fill "description" field with larger string, because it's description, it should be large, and I want to test ui with large description. By the way, thank you for the library. I didn't even know it exists. I'm going to try it.
w
You got a good point πŸ‘Œ