Skip to content

Conversation

rjrjr
Copy link
Collaborator

@rjrjr rjrjr commented Oct 1, 2021

compose

@rjrjr rjrjr force-pushed the ray/compose-textcontroller branch from 6c6af33 to 6fc28de Compare October 2, 2021 00:01
return remember { mutableStateOf("") }.also { state ->
// Restart the effect if a different controller is passed in.
LaunchedEffect(this) {
state.value = textValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't run until after the first composition for the given text controller, which means you'll always get a frame with blank text. You need to initialize the state in the composition, ie when you create the mutable state. I did it that way in the snippet for a reason. You should probably also pass the text controller as a key to remember so it's immediately updated if the controller changes as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refuse to admit how hard I looked for a version of remember that took a key without finding it four lines down. Remember kids, it's important to get a full night's sleep.

@rjrjr rjrjr force-pushed the ray/compose-textcontroller branch 2 times, most recently from b91f8aa to 5421ff6 Compare October 2, 2021 19:37
@rjrjr rjrjr marked this pull request as ready for review October 2, 2021 19:37
@rjrjr rjrjr requested review from a team as code owners October 2, 2021 19:37
@rjrjr
Copy link
Collaborator Author

rjrjr commented Oct 2, 2021

@laurakelly @maybeYouShouldBeTheLawyer @helios175 You're probably interested in this.

Co-authored-by: Ray Ryan <ray@squareup.com>
@rjrjr rjrjr force-pushed the ray/compose-textcontroller branch from 5421ff6 to 270d11f Compare October 2, 2021 20:02
@rjrjr
Copy link
Collaborator Author

rjrjr commented Oct 4, 2021

Flakiness tracked at #559, not related to this PR.

@rjrjr rjrjr merged commit 1dfeb59 into main Oct 4, 2021
@rjrjr rjrjr deleted the ray/compose-textcontroller branch October 4, 2021 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants