https://kotlinlang.org logo
#compose
Title
# compose
s

Siyamed

10/15/2019, 6:42 AM
Which one is more kotliner: A “Builder” object functions should (1️⃣return this ) or (2️⃣let me use with/apply etc and don’t return this)
2️⃣ 16
1️⃣ 2
e

efemoney

10/15/2019, 9:24 AM
Correct me if i’m wrong but you mean: 1️⃣
Copy code
Builder()
  .function()
  .anotherFunction()
  .build()
2️⃣
Copy code
Builder().apply {
  function()
  anotherFunction()
}
right?
l

louiscad

10/15/2019, 10:03 AM
No builder and default argument values is more Kotliny
7
👆 1
👍 1
☝️ 4
m

Matej Drobnič

10/15/2019, 11:01 AM
Even if you return this, you can stull use with/apply etc., so I do not see why you would not return this if you are using builder. There is no downside. But otherwise I agree with @louiscad
1
s

Siyamed

10/15/2019, 2:57 PM
Thanks. Efeturi that's correct.
Louis, Regarding the default argument, this is more like StringBuilder, it actually is AnnotatedStringBuilder in order to assist construction of a styled string
StringBuilder seems to be an alias to java one, so I wasn't sure what it would look like if was implemented in kotlin
Thank you all for the responses.
l

louiscad

10/15/2019, 4:27 PM
Don't you already have
buildSpannedString { … }
+ extensions for
SpannedStringBuilder
in AndroidX Core KTX? You would just add another one for annotations, right?
s

Siyamed

10/15/2019, 5:29 PM
AnnotatedString.Builder will be a Compose component and will be the equivalent of/similar SpannableStringBuilder. Planning to add buildAnnotatedString {...}.
l

louiscad

10/15/2019, 8:07 PM
Oh yeah, that's why this thread is in the #compose channel. Will it be Android only, or multiplatform ready?
s

Siyamed

10/15/2019, 9:18 PM
AnnotatedString is a regular data class
l

louiscad

10/15/2019, 9:25 PM
How would that work with localization? A big when expression? Retrieve from resources on Android? Something else?
Also, is there a reason this doesn't implement
Appendable
?
s

Siyamed

10/15/2019, 11:06 PM
Regarding i18n, that is a wider concept and not defined yet.
Regarding appendable, no charsequence support for now. Charsequence bites us on android.
Wait :) I understand that you think AnnotatedString is directly related to annotation class and tag on Android?
If so, that is not something we intended to :/
l

louiscad

10/15/2019, 11:54 PM
I though it was related to the annotation spans you can put in string resources or
SpannedString
, but it seems it's not after all.
Charsequence bites us on android
How?