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

Jorge Rodríguez

03/24/2023, 5:02 PM
Hi all, I’ve been using the
BasicTextField
with
AnnotatedString
but when I place the cursor in the component the
styles
are empty and I just get a plain text. Is there any way to get the
AnnotatedString
with the
styles
when a change is made?
h

Halil Ozercan

03/24/2023, 5:23 PM
Unfortunately, no. BasicTextField's buffer removes all styling from AnnotatedString before
onValueChange
triggers for the first time.
j

Jorge Rodríguez

03/24/2023, 5:25 PM
@Halil Ozercan why the component has that behavior?
I think if the component is able to accept
AnnotatedString
the normal behavior is to get all the styles with the text when value changes. I don’t found the reason why the styles are removed.
h

Halil Ozercan

03/24/2023, 7:53 PM
This is a limitation of internal buffer used by BasicTextField. We are aware of the problem and planning to address it.
a

Adam Brown

03/24/2023, 11:19 PM
thats great to hear!
@Jorge Rodríguez there is this library (and my Multiplatform version of it) that attempts to implement rich text editing on top of
BasicTextField
however it is definitely a hack. We store an external copy of all of the styling, and then re-apply the styling after setting the value.
@Halil Ozercan in working on that rich text editor library, it occurs to me that we're missing some more fine-grained call backs in order to be able to have a more advanced text editor. I'd love to be able to know WHAT text changed when I get a
onTextChanged
type of callback. Currently we just get the whole value again
j

Jorge Rodríguez

03/24/2023, 11:29 PM
@Adam Brown I'm working also in a Rich Text Editor. I will take a look your library and also @Halil Ozercan nice to hear about that and also could be great to have more granularity in the textfield changes in case of rich text editors
h

Halil Ozercan

03/25/2023, 4:16 AM
We will hopefully have more to share in near future. There is definitely a need for more granular information on text changes. All I can say is stay tuned 🙂 Also, thanks all for your hard work to contribute to the community. We believe it's gonna get much easier to build awesome text editors in Compose 🤞
j

Jorge Rodríguez

03/25/2023, 6:40 AM
@Halil Ozercan thanks for the information.
@Adam Brown there is an issue with the library when you type characters fast or when applying styles and the adding a space to the text, I was fixing on my local project also integrating with some extra code that we have in KMM. I’m still understanding the code but seems to have some bugs related to TextRange as mentioned.
a

Adam Brown

04/26/2023, 9:29 PM
ya, I'm not sure they are totally fixable without some new APIs on
BasicTextField
j

Jorge Rodríguez

04/26/2023, 9:32 PM
I have fixed the issue. On the other hand I’m not sure if there is an alpha version or where can I see the progress of
BasicTextField2
@Halil Ozercan?
h

Halil Ozercan

04/27/2023, 9:57 AM
The latest alpha of foundation includes
BasicTextField2
but it's in a very rough state for now. You can give it a try to check the new API and get an idea about where it's evolving towards.
j

Jorge Rodríguez

04/27/2023, 4:36 PM
Thanks @Halil Ozercan, it would be great to have some extension to handle list formats or to put other composables inside the
BasicTextField2
the same way the
BasicText
do with placeholders.
a

Adam Brown

04/27/2023, 4:37 PM
@Halil Ozercan oh very cool, I'll check it out!
@Halil Ozercan I've been playing with
BasicTextField2
and its looking really good so far! One thing I think would be hard at the moment I think is undo/redo. I think the guts are there maybe with the internal
ChangeTracker
? If that is exposed it should be possible I think.
h

Halil Ozercan

05/03/2023, 7:46 AM
@Adam Brown I'm glad to hear that you are enjoying the new API. We are of course planning to support undo/redo at least internally just like in the current BasicTextField. It's also in consideration to expose an API to control it from outside. Also, why do you think it's hard to add undo/redo right now? Wouldn't
forEachTextValue
or
textAsFlow
help you keep track of observed values to reset back to? You can even add some kind of debounce to skip intermediate steps during fast typing. Use
edit
to reset TextFieldState to any value you want.
cc: @Zach Klippenstein (he/him) [MOD]
z

Zach Klippenstein (he/him) [MOD]

05/04/2023, 12:12 AM
I wouldn’t bother implementing undo/redo on top of BTF2 at this point - it’s not usable for a thousand other reasons at this time, so it would be wasted work
a

Adam Brown

05/04/2023, 12:50 AM
@Halil Ozercan My thinking was that I would want to debounce based on certain events. So I might keep just taking typing events, but the moment you change the selection or add a selection or whatever, demarcate right there and create a new undo point
and also probably skip selection events entirely from the undo redo history
j

Jorge Rodríguez

05/04/2023, 1:11 AM
During this week I will be playing with the new BTF2 and share my findings
a

Adam Brown

05/04/2023, 1:18 AM
I know this is super early in development, but do you have any very rough timeline of when BTF2 is planned to be released? it's it in 1.5.0?
z

Zach Klippenstein (he/him) [MOD]

05/04/2023, 2:58 PM
I can’t say for sure, it’s a large project and any number of things could delay it. But we are hoping to target roughly the end of the year.
a

Adam Brown

05/05/2023, 5:06 AM
@Halil Ozercan you asked why I would want external access to the undo/redo history, it's because I would want to be persisting it past the life time of the composable.
2 Views