mapbox-maps-android icon indicating copy to clipboard operation
mapbox-maps-android copied to clipboard

Use on draw listener in view annotation manager for more granular control

Open kiryldz opened this issue 3 years ago • 0 comments

Summary of changes

In view annotation manager we were relying on ViewTreeObserver.OnGlobalLayoutListener listener to control 2 state changes for the view annotation:

  • dimension change caused by WRAP_CONTENT
  • visibility changes based on user calling View.setVisibility in order to update core with new visible status

However it turned out that changing view visibility from VISIBLE to INVISIBLE does not actually trigger OnGlobalLayoutListener as the view still remains in the view tree. That actually was breaking view annotation logic when user was simply setting view annotation visibility to INVISIBLE, dragging the map and making it VISIBLE again.

The solution found here is to actually check view visibility inside ViewTreeObserver.OnDrawListener that is called on each frame for the view. In order to save a bit of CPU cycles only visibility check was migrated to OnDrawListener while checking for WRAP_CONTENT dimensions did remain in OnGlobalLayoutListener.

User impact (optional)

Pull request checklist:

  • [x] Briefly describe the changes in this PR.
  • [ ] Include before/after visuals or gifs if this PR includes visual changes.
  • [x] Write tests for all new functionality. If tests were not written, please explain why.
  • [ ] Optimize code for java consumption (@JvmOverloads, @file:JvmName, etc).
  • [ ] Add example if relevant.
  • [ ] Document any changes to public APIs.
  • [ ] Run make update-api to update generated api files, if there's public API changes, otherwise the verify-api-* CI steps might fail.
  • [x] Update CHANGELOG.md or use the label 'skip changelog', otherwise check changelog CI step will fail.
  • [ ] If this PR is a v10.[version] release branch fix / enhancement, merge it to main firstly and then port to v10.[version] release branch.

Fixes: < Link to related issues that will be fixed by this pull request, if they exist >

PRs must be submitted under the terms of our Contributor License Agreement CLA.

kiryldz avatar Aug 19 '22 11:08 kiryldz