fix(android): clean up polyline animator on view drop#72
Merged
Conversation
Notify GoogleMapProvider from LuggPolylineView.onDropViewInstance so the PolylineAnimator (and its infinite-repeat ValueAnimator) gets cancelled even when the view is dropped without going through removeViewAt. Also guards addPolylineViewToMap against an already-registered animator entry and drops a per-frame ArrayList copy in updateAnimatedPolyline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LuggPolylineView.onDropViewInstancepreviously only cleared the GMS polyline — it never toldGoogleMapProviderto dismantle the matchingPolylineAnimator. Cleanup of thepolylineAnimatorsmap andValueAnimator.cancel()lived only inremovePolylineView, which is reached viaLuggMapView.removeViewAt. If a view instance was dropped without that path firing first (e.g. provider/surface teardown ordering), the entire animator chain leaked: anINFINITE-repeatValueAnimatoris held by the systemAnimationHandler, keeping thePolylineAnimator, itscoordinates,cumulativeDistances,reusablePoints, and the already-removedPolylinealive across re-mounts.This PR:
polylineViewDidDropcallback toLuggPolylineViewDelegate.LuggPolylineView.onDropViewInstancenow notifies the delegate, andGoogleMapProviderroutes bothremovePolylineViewandpolylineViewDidDropthrough a sharedteardownPolylinehelper.addPolylineViewToMap, so a stale registration can't silently overwrite a still-runningValueAnimator.ArrayList(reusablePoints)wrapper inPolylineAnimator.updateAnimatedPolyline—Polyline.setPointscopies internally, so the wrapping list is unneeded GC churn.Type of Change
Test Plan
Stress-tested on Android emulator (Google Maps SDK 20.0.0):
Without this fix, the same scenarios would have leaked a `PolylineAnimator` per remount cycle since `onDropViewInstance` ran without the matching delegate notification. The shared teardown helper makes both paths idempotent.
Checklist