-
Notifications
You must be signed in to change notification settings - Fork 161
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
Move MapEvents on
handling from BaseMapView to MapboxMap
#339
Conversation
private var eventHandlers = WeakSet<MapEventHandler>() | ||
|
||
deinit { | ||
eventHandlers.allObjects.forEach { | ||
$0.cancel() | ||
} | ||
} | ||
|
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.
Do we need a test for this?
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 is..sort of. See below.
class WeakHandlerContainer { | ||
weak var handler: MapEventHandler? | ||
|
||
deinit { | ||
handler?.cancel() | ||
} | ||
} |
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.
PRs must be submitted under the terms of our Contributor License Agreement CLA.
Pull request checklist:
Add example if relevant.Updatedmapbox-maps-ios
changelog:<changelog>Moved
on()from
BaseMapViewto
MapboxMap.</changelog>
.Summary of changes
This PR changes the behavior of
on(_:handler:)
to handle map events and moves the function toMapboxMap
.on(...)
has been replaced byonNext(...) -> Cancelable
onEvery(...) -> Cancelable
Assuming there is no retain cycle that stops the
MapView
orSnapshotter
from being deallocated, then unsubscribing will be handled on your behalf when theMapView
is deallocated: The underlying listener will unsubscribe from the map, and the closure will be released.If you do have a retain cycle or you need to stop listening, for example if you want to listen to 3 events then stop, then call
cancel
on the returnedCancelable
object.Here's an example of how the call-site changes:
becomes
cc @mapbox/maps-android