I've got text like this `Text("first line\nsecond...
# compose
c
I've got text like this
Text("first line\nsecond line")
but it just shows the \n directly in the Text widget According to SO, I should do
Text("first line\r\nsecond line")
but that didn't work either. Any thoughts? Edit: nvm did this and it works now
Copy code
myText.replace("""\n""", "\n")
z
That seems like a bug, can you file?
c
Sure!
Created. Only reproducible when my source is firebase firestore, which I'm assuming is the issue. But filed anyway: https://issuetracker.google.com/issues/200437476
z
Oh, I didn’t realize this was a firebase issue. Can you look at the string bytes and verify those
\n
characters are actually new lines?
c
Look at them once they are over the wire on the android side?
Sorry, chars/bytes/encoding etc have always gone over my head so I'm not necessarily sure where to start. All I know is that \n is what shows in firestore and iOS didn't have to do anything special.
z
Yes, look at the string bytes on Android. Just to make sure something isn’t actually putting a
\
and a
n
in the string.
c
Will try it out later today. Thanks for the pointer
In the debugger, printing the string gives me
Test\n\nOne. \n\nTwo\nThree
The byte array is
Copy code
[84, 101, 115, 116, 92, 110, 92, 110, 79, 110, 101, 46, 32, 92, 110, 92, 110, 84, 119, 111, 92, 110, 84, 104, 114, 101, 101]
z
Great, so if you look up those numbers in an ASCII table, you’ll see what’s wrong. 84 - T 101 - e 115 - s 116 - t 92 - \ 110 - n etc. So your string actually includes the characters
\
and
n
. You should see a 10 instead of the (92,110) pair – 10 is the newline character. I’m not sure how they’re getting in there, you could check the data at various points in your data flow.
c
Thanks. I will close my issue. Looks like I just misjudged firestore. Appreciate the help (as always)!
So interesting that a newline "character" can be two characters. lol
z
It’s not, newline is a single character.
Most programming languages will interpret the sequence ’\n` in a string literal as a newline, and replace it with an actual newline character. Sometimes when rendering a string for debug purposes, the translation will be done in the other direction as well, which can be a bit confusing.
c
I need a crash course in strings/chars/encoding lol
But that's for another day I suppose
z
I’d be surprised if this was a firestore problem, since that would break almost every app using it, and you said it works on ios. Sounds like something on the android client is doing something weird
c
iOS team confirmed just now that they actually are doing the same replace
Lmao. That's not what they said the first time
https://stackoverflow.com/a/48755845 looks like Doug confirmed that it's a firebase thing of not "supporting" \n
z
wow