Is there any way to mark `CharSequence` as being s...
# compose
e
Is there any way to mark
CharSequence
as being stable? I'm using it as a way to pass around either
String
or
AnnotatedString
.
r
I don’t think that would work since a
StringBuilder
is a
CharSequence
for instance but changes are not observable
e
True, but in my use cases I'm always limiting it to a
String
or
AnnotatedString
z
You could wrap it in a stable holder class
e
I tried that but it made the API not as great + I would've had to spread it out over a bunch of libraries. I ended up going with overloads of all my generic composable that deal with text, which isn't great either, but at least the API is nicer
z
Ah yes if this is for a public api, tricking the compiler into treating CharSequence as would be especially bad because you couldn’t prevent consumers from passing in non-stable objects.
e
I'd say it's more of an "internal" API. We also check the CharSequence to make sure that it's a String or AnnotatedString and throw otherwise.
182 Views