Open JSpiner opened 1 month ago
Personally I'd be in favor of eliminating rememberMarkerState
entirely. I find it misleading and an anti-pattern:
That is an interesting proposition. Admittedly, I have had issues with the way it works as well. Might be worth investigating as a possibility.
On Wed, Oct 16, 2024, 15:14 Uli Bubenheimer @.***> wrote:
Personally I'd be in favor of eliminating rememberMarkerState entirely. I find it misleading and an anti-pattern:
— Reply to this email directly, view it on GitHub https://github.com/googlemaps/android-maps-compose/issues/637#issuecomment-2415820993, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2GLJ4EXEB2OMQF6IVYXLZ3X73ZAVCNFSM6AAAAABQATZMWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJVHAZDAOJZGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>
@dkhawk
Yes, it can be confusing. Not only me, but my coworkers are also confused.
@Composable
fun rememberUpdatedMarkerState(position: LatLng): MarkerState =
// This pattern is equivalent to what rememberUpdatedState() does:
// rememberUpdatedState() uses MutableState, we use MarkerState.
// This is more efficient than updating position in an effect,
// as we avoid an additional recomposition.
remember { MarkerState(position = position) }.also {
it.position = position
}
The example code included in this repository also creates and uses rememberUpdatedMarkerState
to solve this problem.
I also solved the problem in a similar way.
It seems okay to provide this function, but I think the first thing to do is to distinguish between initPosition and position so that there is no confusion.
https://github.com/googlemaps/android-maps-compose/pull/638 Can you review my PR and leave comments?
MarkerState
hasrememberMarkerState
for use in compose.But looking at the example above, it's easy to get confused. This is because there is a risk of misunderstanding that the value entered as a parameter to remember (
position
in this case) acts as a key that is automatically reflected when the value changes. I also had a hard time because the position wasn't updated. To avoid this misunderstanding, compose foundation libraries add aninital
prefix to rememberXXX functions.So my suggestion is to change the name from
position
toinitialPosition
to reduce confusion. It seems like a simple fix, I'll create a PR. Please review it. Thanks!