-
Notifications
You must be signed in to change notification settings - Fork 129
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
Marker drag event callback #10
Comments
@chibatching Thank you for opening this issue. 🙏
This is an automated message, feel free to ignore. |
This is what
Definitely open to reevaluate this although I think marker drag state should only be observed either using the State-based approach or the callback-based approach, not both. Please provide a bit more context if for some reason the latter works better for your use case. |
@arriolac My usecase is like below var markerPoint by remember { mutableStateOf(defaultLatLng) }
GoogleMap() {
Marker(
position = markerPoint,
draggable = true,
onMarkerDragEnd = { marker ->
markerPoint = maker.position
viewModel.updateUserSelectedPosition(marker.position)
},
)
} |
I think it doesn't need to be a callback style if the drag state has marker object or position info. |
Yeah, this is what I'm thinking as well. There should be a |
I updated my PR #11 to add |
Please see my comment on #11 (comment) for how this feature should be implemented. |
AFAICT the current implementation (in 2.2.0) does not take into account the difference between drag state and drag events. The For example, I have a use case where a user's marker drag events are not committed to the data model when the marker is dragged to an invalid position. This looks hard to implement reliably at the moment, if possible at all; I need to save the prior marker position at drag START, verify the final position at drag END and commit or roll back, and update dependent visualizations upon DRAG. I don't see a way to access the raw events via a listener, either. This use case causes zero problems with the standard GoogleMap event listener approach. What you want to expose here is a Flow or possibly a ReceiveChannel of drag events. The consumer will have to determine the buffering strategy, not the compose wrapper. |
There also seems to be a misconception about what state hoisting means. When I hoist state, I control the state at a higher level of the composition, and the state object is not present at deeper levels of the composition, which cannot directly change the state. Yet here I am expected to pass the "hoisted" state object down into the composition, and it will change under my nose when the user drags the marker. That is the exact opposite of state hoisting. It means a lot of trouble for my outside data model.
|
@bubenheimer thanks for the feedback on the current marker drag API. I'm a bit confused what you mean by information loss as all marker drag transition states should be reported in From your feedback, seems like it is desirable to have an event-based API to accomplish validation type actions as the current state-based approach for drag state is difficult to work with. If you can capture some suggestions you have on a separate issue we can reevaluate and improve upon the existing API. |
Thanks. In general there is no way to guarantee that an observer will see transitory states of a MutableState, the observer only gets to see snapshot state (not events), and it may not even see all of the snapshot states. This is a fundamental characteristic of snapshot state. For background, see the bottom of the
I will propose something in a separate issue. Edit: removed comment about "state object hoisting" in favor of broader discussion in new issue. |
Hope we will see this event soon, both drag start and drag end. I could do with drag start but drag end is critical. |
@zaheeroz You may be able to "reconstruct" drag start & end to some degree from the information that is available, but you need to take into account that you may miss some ends and/or starts, when a new start-drag-end cycle starts too quickly after the last one ends. |
Thanks @bubenheimer that's great. Could you provide a link that can help in this regard. I can start a drag by first clicking on the marker to register a 'drag start' then drag the marker. But the problem is even click fires on 'pressed' and not ' on release' so I cant get the location where the marker was dragged (end of drag). So any help in this regard will be greatly appreciated. |
@zaheeroz I don't have a link, sorry. |
I believe the initial request here was addressed in v2.0, so closing this issue. Conversation continues about improving marker drag state in #149. |
I want to get marker drag event callback and manipulate marker-related work.
So,
Marker
composable have to have dragging callback parameter likeonMarkerDrag
onMarkerDragStart
onMarkerDragEnd
similar withonClick
andonInfoWindow~
It is an alternative to
OnMarkerDragListener
of Android view version.The text was updated successfully, but these errors were encountered: