is it possible to specify number of words, for lor...
# compose
p
is it possible to specify number of words, for lorem ipsum preview parameter?
Copy code
@Preview
@Composable
fun Preview(@PreviewParameter(LoremIpsum::class) text: String) {
    Text(text)
}
I guess
text.take(100)
? Or is there smth else I'm missing?
Why is it not possible to use
@PreviewParameter(LoremIpsum::class, limit = 100)
to select number of words? Bug?
x
That doesn't make sense IMO. If you want 100 words, you make the
LorenIpsum
class provide 100 words. This logic must be in the
values
property of the class that implements PrevierParameterProvider
s
True, but there’s no way to also provide constructor parameters when initiating the class passed inside @PreviewParameter. Is there? The LoremIpsum https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]/androidx/compose/ui/tooling/preview/datasource/LoremIpsum.kt class does have the necessary constructor parameters, but not sure how to actually use it.
1
today i learned 1
As far as the
@PreviewParameter(LoremIpsum::class, limit = 100)
question goes. The limit there is for the number of previews you’ll be rendering. LoremIpsum does not render 100 previews all with different texts. It gives back 1 String value. So the limit 100 does nothing since you are only getting 1 value off of it anyway.
What you can do instead is simply take the string and do
take(X)
as you said, just to fit your UI, should work just fine for now. Unless there’s a way to do this that I am not aware of.
x
Oh wow, I thought this
LorenIpsum
class was something that @Peter had defined in his project. LMAO that this class is actually provided by Compose UI. Thanks for that cs link @Stylianos Gakis!
p
Exactly this yeah. I was wondering, if there's any way to provide count, since
LoremIpsum
supports it via constructor.
s
Do you mind filing a bug for this that we can +1? I am curious to see if maybe this is not supported ATM and if it could be supported somehow. The annotation atm doesn’t look like it could ever support it, but there must be another way they can make this work.
1
x
I also feel like this
LorenIpsum
class could be way more useful by providing a way to configure it
p
Sure, I will make it tomorrow and share the link
👍 1
I guess someone already opened this request https://issuetracker.google.com/issues/266918816
s
I suppose so, even though the title of the issue isn’t really representative of the problem here is it? The fact that it’s not a var is not the problem. The problem is that using the PreviewParameter annotation doesn’t let us customize how we actually call the constructor of it.
p
I think it's kind of in the same lines as this topic here, but poorly reported. I will open another issue
👍 1
c
any good blog post to read more about @PreviewParameter?
s
Yes, this one: You use preview parameter when you want to preview your composable with multiple inputs, and you want a new preview in the IDE for each one of them. But you don't want to create multiple @Preview composables.
p
543 Views