Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added recomposition sample #448

Merged
merged 2 commits into from
Dec 9, 2023
Merged

Conversation

kikoso
Copy link
Collaborator

@kikoso kikoso commented Oct 27, 2023

This PR adds a recomposition sample, to showcase how to remove or add markers using a remember variable and recomposition.

video_2023-10-27_16-56-20.mp4

Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #442, #91, #403 🦕

Copy link
Member

@wangela wangela left a comment

Choose a reason for hiding this comment

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

Let's also add to the "Drawing on a map" section of the README about how to update the state of composables that have been added to the map. Can just link to this activity if the code snippet gets too long.

@kikoso kikoso force-pushed the docs/added_recomposition_sample branch from c9b1cee to eb19a86 Compare November 23, 2023 07:05
@kikoso
Copy link
Collaborator Author

kikoso commented Nov 27, 2023

Let's also add to the "Drawing on a map" section of the README about how to update the state of composables that have been added to the map. Can just link to this activity if the code snippet gets too long.

This has been added, @wangela

@wangela wangela merged commit 6b6e0e1 into main Dec 9, 2023
10 checks passed
@wangela wangela deleted the docs/added_recomposition_sample branch December 9, 2023 06:35
@bubenheimer
Copy link
Contributor

@wangela May I ask why these commits were merged without further discussion? I pointed out a problem, yet my comments were ignored. This action does not promote a healthy open-source culture for this project. I will need to assess the relevance of future contributions from my side.

I respect that there may be differences in opinion, but there needs to be discussion to resolve those. Apart from my prior pointers: the API provides a dedicated function rememberMarkerState() to maintain MarkerState. It is unclear why the project documentation and samples would promote a different approach that does not actually remember the state object itself, but continuously recreates it.

I tried to voice my concerns in a helpful, professional manner, but perhaps I was too subtle? I would not go through the effort of commenting unless I see a strong need for changes.

The present action suggests that I and other users of this project will need to find alternative means to restore and maintain sufficient API quality for our own projects in the face of ongoing regressions since @arriolac's departure. For example the present documentation regression, as well as #466 and #347. I appreciate that #347 was reverted after I voiced my concerns, but this PR points in a different direction. The existence of #466 should have rung alarm bells.

The end result of all this is a necessity for private forks. I do not see a viable alternative, unless there are changes to how this project is managed. Seeing #347 gave me a scare (its problems should have been caught in code reviews, and it even required changing a test to make it pass), so I started to review every PR personally in an effort to catch serious regressions early, but now I am finding that my input is ignored. Private forks are expensive to maintain for independent devs like myself, so I wish this could be resolved in a different manner.

bubenheimer added a commit to bubenheimer/android-maps-compose that referenced this pull request Dec 9, 2023
@kikoso
Copy link
Collaborator Author

kikoso commented Dec 10, 2023

Hi @bubenheimer ,

Thanks for your comment. Regarding this Pull Request, it has been open for a month. I think the expectation was to write any comment or concern here, but there was none. Any issue is open to any feedback, as you can see in #347. If you had any, you could comment at any time given time, and a discussion could have been started. Sorry if this came as ignoring any feedback, it was definitely not the intention.

This PR showcases how to change a marker based on a changing location. I believe what you want to point out is to use the following to update the location:

val singaporeState = rememberMarkerState(position = location)

which makes sense, and it is pointing out how to use the rememberMarkerState() instead. The original PR wanted to showcase a recomposition example, but this makes sense to showcase the usage of rememberMarkerState()`. But there was no comment on this PR that we could have leveraged to start any discussion.

@bubenheimer
Copy link
Contributor

@kikoso I'm not sure what you mean about "no comment" on this PR. I started a code review right here in this PR soon after your initial commit, with 4 comments total. You did not respond to the concerns that I brought up in the context of the review. It's all still up there. Please clarify.

@bubenheimer
Copy link
Contributor

As for whether to use rememberMarkerState() specifically: it's not essential, it just remembers 'MarkerState'.

What I'm saying is that it does not make sense to recreate MarkerState on recomposition, and remember a separate mutableStateOf() for the location. MarkerState is the relevant state object here and needs to be the one to be remembered. MarkerState encapsulates more than just location.

The merged commit demonstrates a bad pattern. I hope it can be unmerged.

@kikoso
Copy link
Collaborator Author

kikoso commented Dec 10, 2023

@kikoso I'm not sure what you mean about "no comment" on this PR. I started a code review right here in this PR soon after your initial commit, with 4 comments total. You did not respond to the concerns that I brought up in the context of the review. It's all still up there. Please clarify.

@bubenheimer , there are no comments in this PR. Did you forget to click the send review button? It is easy to miss.

Screen.Recording.2023-12-10.at.14.16.17.mov

Comment on lines +68 to +69
var location by remember { mutableStateOf(singapore) }
val singaporeState = MarkerState(position = location)
Copy link
Contributor

Choose a reason for hiding this comment

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

MarkerState.position is a var with a public setter and a mutableStateOf behind it, and it is observed for changes by Marker() machinery. So it is not necessary to keep a separate remembered mutableStateOf to track position changes, or to recreate MarkerState on every recomposition.
Consider this instead:

val singaporeState = remember { MarkerState(singapore) }

Then update via:

singaporeState.position = when (randomValue) {
    0 -> singapore
    1 -> singapore2
    2 -> singapore3
    else -> singapore

Copy link
Contributor

Choose a reason for hiding this comment

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

@wangela @kikoso if this pattern does not work then there has been a regression that needs to be fixed. Various recently filed issues and my own testing suggest that this is the case. The pattern used to work flawlessly and is the way the API is intended to be used; it's described at https://github.com/androidx/androidx/blob/androidx-main/compose/docs/compose-api-guidelines.md#hoisted-state-types and subsequent sections.

Recreating MarkerState on every recomposition is akin to the following, which the IDE will tell you is missing 'remember':

val state = mutableStateOf(1)

Copy link
Contributor

Choose a reason for hiding this comment

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

@wangela @kikoso FYI: the regression (if it is just a single one) was introduced in 2.14.1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @bubenheimer ! I can see your point. Here I was trying to showcase how to recompose the map based on the location attribute, but it does introduce more confusion than another thing. Your approach makes sense.

I am updating the docs and PR-ing the changes.

Comment on lines +212 to +213
var location by remember { mutableStateOf(singapore) }
val singaporeState = MarkerState(position = location)
Copy link
Contributor

@bubenheimer bubenheimer Dec 10, 2023

Choose a reason for hiding this comment

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

Same concern as in sample

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed too.

@bubenheimer
Copy link
Contributor

bubenheimer commented Dec 10, 2023

Thanks @kikoso, I must have missed clicking the button initially, and I think the button may have stopped working later after force push & merge/closure. I've added my prior comments as regular comments now, to show what I had in mind. I seem no longer able to start a review on a closed PR.

My sincere apologies for the noise & waste of time on your end.

Would it be possible to change the sample & docs still? I don't think there is any valid use case where one would not want to retain MarkerState across recompositions, short of bug workarounds perhaps.

That said, there certainly is a common need to sync MarkerState with information that is kept outside Compose. This would be a slightly larger example. An important example, though.

@kikoso kikoso mentioned this pull request Dec 14, 2023
4 tasks
@googlemaps-bot
Copy link
Contributor

🎉 This PR is included in version 4.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplication of marker during update of viewmodel
4 participants