Status Update
Comments
st...@gmail.com <st...@gmail.com> #2
I feel like the overarching problem here is that the @PreviewParameter annotation does not allow us to decide how the constructor of the class is called, but is done so using reflection.
Maybe the completely unsafe solution to this is an overload to the @PreviewParameter which after taking in the limit: Int
parameter, it can also take in a vararg constructor parameters: Any
which it will simply take and pass to the constructor, obviously crashing if anything is passed wrongly, but at least it'd work. So for our case here, the call site would be like:
@PreviewParameter(LoremIpsum::class, limit = 1, 20)
, where 20
would be part of the varargs, which would be passed in the constructor of LoremIpsum.
mn...@google.com <mn...@google.com>
di...@google.com <di...@google.com>
am...@google.com <am...@google.com>
am...@google.com <am...@google.com> #3
LoremIpsum
is now an open class, so you can override it similar to CollectionPreviewParameterProvider
class LoremIpsum20Words : LoremIpsum(20)
@Preview
@Composable
fun Preview(@PreviewParameter(LoremIpsum20Words::class) text: String) {
Text(text)
}
pr...@google.com <pr...@google.com> #4
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.ui:ui-tooling:1.6.0-alpha08
androidx.compose.ui:ui-tooling-android:1.6.0-alpha08
androidx.compose.ui:ui-tooling-desktop:1.6.0-alpha08
androidx.compose.ui:ui-tooling-preview:1.6.0-alpha08
androidx.compose.ui:ui-tooling-preview-android:1.6.0-alpha08
androidx.compose.ui:ui-tooling-preview-desktop:1.6.0-alpha08
Description
Issue
LoremIpsum
doesn't seem to offer an option, to specify number of words. Sometimes you want to preview how specific composable behaves, when line breaks a single time.LoremIpsum
only offers "a truck load" amount of words.So basically, I would like to be able to preview text with only 20 words, instead of 500 (that's current default word count set in
LoremIpsum
).Example
I want to preview how following text breaks, but I don't want it to expand indefinitely.
Yes, I could limit it by height, but sometimes composables are more complicated than that.
Current workarounds
A. Only take first n characters
B. Manually instantiate LoremIpsum
Potential solutions
Maybe short version of
LoremIpsum
could solve this use case in a simple way? E.g.LoremIpsumShort
?Info