-
Notifications
You must be signed in to change notification settings - Fork 147
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
chore: Change the confusing parameter position
to a clear name. #637
#638
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
7c63b15
to
34a1a7d
Compare
parameter
position to a clear name. #637parameter
position to a clear name. #637
I resolved the conflict. |
Hi @JSpiner . This is a reasonable proposal. Typically we would like to not drop a breaking change, but to propose a transition time for folks to change. I think we could offer an alternative constructor to the current one, deprecate the former and leave folks one version to upgrade to the new one. We could eventually pack this PR with another breaking change. |
*/ | ||
@StateFactoryMarker | ||
public operator fun invoke( | ||
position: LatLng = LatLng(0.0, 0.0) | ||
): MarkerState = MarkerState(position) | ||
initialPosition: LatLng = LatLng(0.0, 0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the rationale for changing the parameter name here. Makes sense for rememberMarkerState, but not here. If you end up recomposing MarkerState.invoke(position) you will get a new MarkerState object.
It may look tempting because of the "initial marker position" KDoc verbiage, but that's how State objects generally work, including MutableState. It's mutableStateOf(value="bla")
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. This part didn't need to be updated.
However, I completely reverted and rewrote this part based on @kikoso 's opinion.
Please review again. 🙇
Following @kikoso 's suggestion, I kept the existing
I think it would be a good idea to deprecate rememberMarkerState like below. I'd like to hear your opinions. @Composable
@Deprecated(
message = "Use 'rememberUpdatedMarkerState' instead - It may be confusing to think " +
"that the state is automatically updated as the position changes, " +
"so it will be changed.",
replaceWith = ReplaceWith(
expression = """
val markerState = rememberUpdatedMarkerState()
"""
)
)
public fun rememberMarkerState(
key: String? = null,
position: LatLng = LatLng(0.0, 0.0)
): MarkerState = rememberSaveable(key = key, saver = MarkerState.Saver) {
MarkerState(position)
} |
@JSpiner I agree with deprecating rememberMarkerState, it's a misleading API. The I disagree with the changed implementation of rememberUpdatedMarkerState, basing it on rememberSaveable instead of remember. This is invalid for the examples where it is used, and does not align with the rationale from the posts in #637 (comment) |
Thanks for comments.
Sorry, my mistake. I changed it to use the original implementation.
I apply it. thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A maintainer should review this as well.
@@ -281,6 +282,30 @@ class GoogleMapViewTests { | |||
.performClick() | |||
} | |||
|
|||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this test actually pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: the key is being read from the secrets in the local repo, so (unless you have them set on your fork) it will not run. Typically we run the tests on a PR copy to make sure they pass.
maps-compose/src/main/java/com/google/maps/android/compose/Marker.kt
Outdated
Show resolved
Hide resolved
parameter
position to a clear name. #637position
to a clear name. #637
Also, @JSpiner : did you have the chance to take a look at the CLA agreement? |
…o `initialPosition`. googlemaps#637
…meter` to `initialPosition`. googlemaps#637" This reverts commit 565007e.
…arer name. googlemaps#637" This reverts commit 2aa9d4a.
…based on updates to the input parameters.
…ker.kt Co-authored-by: Uli Bubenheimer <[email protected]>
@kikoso I agreed to the CLA agreement. When I looked at the commit logs, my secondary git account name was included and was processed as a non-agreement. I re-organized them by rebasing. Thanks. When merging @bubenheimer 's suggestion on github, he's name was included in the commit author 5761aaf. Would you also agree to the CLA? |
Done |
@kikoso |
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:
Fixes #637 🦕
It may be confusing that it is automatically updated by the
position
parameter. I renamed it toinitialPosition
to make it clear that it only works with the initial value.(The compose foundation libraries also add the init prefix to the initial values that go into rememberXXX.)
MarkerState has rememberMarkerState 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 an inital prefix to rememberXXX functions.
So my suggestion is to change the name from position to initialPosition to reduce confusion.