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

fix: Use recomposed map listener callbacks rather than only the initially … #478

Merged
merged 7 commits into from
Jan 31, 2024

Conversation

bubenheimer
Copy link
Contributor

@bubenheimer bubenheimer commented Dec 16, 2023

…composed version

Fixes #466

This solution is optimized for the common case of recomposition updating a non-null GoogleMap listener callback to another non-null callback, and has negligible overhead, supporting rapid recomposition.

The other, less common case, toggling between null and non-null callbacks, calls the appropriate GoogleMap SDK listener setter in the composition apply phase; any overhead from calling the setter is passed through.

Thank you for opening a Pull Request!


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)

@bubenheimer
Copy link
Contributor Author

@kikoso would you have time for a review? Happy to explain changes. Would like to get it merged soon to not let the issue fester longer. Have a few other PRs waiting on this one.

@kikoso
Copy link
Collaborator

kikoso commented Jan 8, 2024

Hi @bubenheimer !

Thanks for putting this PR together. Since there are a few that could depend on the output of this one, let's focus on getting this one merged first.

The internal behavior of Google Maps follows this approach (using a POI and OnPoiClickListener as a reference):

  • If a POI is clicked but if there is no OnPoiClickListener set, the OnMapClickListener will be invoked instead (given that it has been previously set). If none of those listeners has been set, the click is still “captured” internally by the map, and triggers any default behavior (for instance, hiding the toolbar if it's displayed).

  • For markers, if a marker is clicked but does not have an OnMarkerClickListener set, again the click is still “captured” by the map to trigger default behavior (camera moves to the marker, info window appears and toolbar displayed if enabled).

As a rule of thumb, the map invokes any user-provided listeners first, and then afterwards processes internally the event to perform any other actions.

From your approach: the fact that it is not a breaking change, and that the logic of the MapUpdater stays relatively unchanged is good.

The PR seems to honor that A) Recomposed callbacks are working, and B) They default to the Google Map listener if they are null.

The PR looks good. Let me check if there are no further issues and get back!.

@kikoso
Copy link
Collaborator

kikoso commented Jan 9, 2024

Hi @bubenheimer,

This looks good to be merged, will do it soon.

@bubenheimer
Copy link
Contributor Author

Bump

…ate updates to after parent composition, not during parent composition"

This reverts commit dff2b0a.
@bubenheimer
Copy link
Contributor Author

bubenheimer commented Jan 24, 2024

I've reverted the earlier commit that moved the initial parts of updating the listener callbacks into a SideEffect. The SideEffect approach delays the listener updates to a future recomposition cycle, which I have to come to consider too slow.

Without SideEffect there is the issue of spurious recompositions that I believe are fast and do essentially nothing. However, the listeners are updated more quickly. I have not seen issues in terms of affected code behaving incorrectly because of the spurious recompositions.

The spurious recompositions are not specific to this PR, they are prone to happen with the current GoogleMap() subcomposition approach in general: #480

@wangela wangela assigned dkhawk and unassigned wangela Jan 25, 2024
@wangela wangela requested a review from dkhawk January 25, 2024 23:49
@dkhawk dkhawk merged commit d14daba into googlemaps:main Jan 31, 2024
8 of 9 checks passed
googlemaps-bot pushed a commit that referenced this pull request Jan 31, 2024
## [4.3.3](v4.3.2...v4.3.3) (2024-01-31)

### Bug Fixes

* Use recomposed map listener callbacks rather than only the initially … ([#478](#478)) ([d14daba](d14daba)), closes [#466](#466) [#501](#501)
@googlemaps-bot
Copy link
Contributor

🎉 This PR is included in version 4.3.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@bubenheimer bubenheimer deleted the use_recomposed_listeners branch February 1, 2024 02:32
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.

Regression: recomposed map listeners ignored
5 participants