Skip to content
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

New methods for view annotations API #1136

Merged
merged 16 commits into from
Feb 23, 2022
Merged

Conversation

evil159
Copy link
Contributor

@evil159 evil159 commented Feb 17, 2022

Summary

This PR introduces ViewAnnotationUpdateObserver protocol for notifying when annotion views get their frames or visibility changed. As well as corresponding methods to add/remove view annotation update observers to ViewAnnotationManager.

In addition removeAll() method is added to ViewAnnotationManager that removes all annotations added before.

Fixes: https://github.com/mapbox/mapbox-maps-internal/issues/1280

Pull request checklist:

  • Write tests for all new functionality. If tests were not written, please explain why.
  • Add documentation comments for any added or updated public APIs.
  • Add any new public, top-level symbols to the Jazzy config's custom_categories (scripts/doc-generation/.jazzy.yaml)
  • Describe the changes in this PR, especially public API changes.
  • Add a changelog entry to to bottom of the relevant section (typically the ## main heading near the top).
  • Review and agree to the Contributor License Agreement (CLA).

@evil159 evil159 force-pushed the new-viewpoint-annotations-api branch 2 times, most recently from d487975 to cfb4322 Compare February 18, 2022 13:05
@evil159 evil159 force-pushed the new-viewpoint-annotations-api branch from cfb4322 to 14a1e69 Compare February 22, 2022 09:18
@evil159 evil159 force-pushed the new-viewpoint-annotations-api branch from ca85176 to 9593d32 Compare February 22, 2022 09:46
@evil159 evil159 marked this pull request as ready for review February 22, 2022 09:57
Copy link
Contributor

@kiryldz kiryldz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did review protocol only 😉
API differs slightly from Android but in terms of usability and platform details we should be aligned.

@@ -1,6 +1,7 @@
import UIKit
@_implementationOnly import MapboxCommon_Private
@_implementationOnly import MapboxCoreMaps_Private
import SwiftUI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need SwiftUI here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't. Probably an accidental auto-import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True this, gotta be more careful with Xcode auto-importing things.

/// Manager API to control View Annotations.
///
/// View annotations are `UIView` instances that are drawn on top of the `MapView` and bound to some `Geometry` (only `Point` is supported for now).
/// View annotations are `UIView` instances that are drawn on top of the ``MapView`` and bound to some ``Geometry`` (only ``Point`` is supported for now).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these links for Geometry and Point do the right thing? Turf docs aren't well integrated at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as such it seems. I did check that it generates links to those types, but there's nothing in the documentation pages for them. Doesn't look like a right thing, indeed. I'll revert these changes back.

@@ -123,19 +153,36 @@ public final class ViewAnnotationManager {
}
}

/// Update given `UIView` with `ViewAnnotationOptions`.
public func removeAll() {
let viewsByIdCopy = viewsById
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need a copy here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Swift value types should avoid the troubles with mutation during iteration we had in Objective-C

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old habits...

view.isHidden = false
expectedHiddenByView[view] = false
visibleAnnotationIds.insert(position.identifier)
}

assert(!viewsWithUpdatedFrame.contains(where: {$0.isHidden == true }))
notifyViewAnnotationObserversFrameDidChange(for: Array(viewsWithUpdatedFrame))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to wait until the end of the method just before notifyViewAnnotationObserversVisibilityDidChange to make this call?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking it might avoid letting the developer see the views in an inconsistent state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also may make sense to put this block to the defer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea with defer will work well. It will make more sense to first notify about visibility changes and only after that is established to notify about frame changes.

Copy link
Contributor

@macdrevx macdrevx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you preview the changes to the generated docs?

evil159 and others added 3 commits February 23, 2022 03:26
Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com>
Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com>
Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com>
evil159 and others added 4 commits February 23, 2022 03:53
Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com>
Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com>
Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com>
…wift

Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com>
@evil159 evil159 force-pushed the new-viewpoint-annotations-api branch from 305a6d6 to c15031b Compare February 23, 2022 02:06
@evil159 evil159 force-pushed the new-viewpoint-annotations-api branch from c15031b to 35e76d7 Compare February 23, 2022 02:10
@evil159
Copy link
Contributor Author

evil159 commented Feb 23, 2022

Did you preview the changes to the generated docs?

Yeah, looks good except for symbol references to Turf docs(fixed it).

Copy link
Contributor

@OdNairy OdNairy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, few nits.

Sources/MapboxMaps/Annotations/ViewAnnotationManager.swift Outdated Show resolved Hide resolved
view.isHidden = true
expectedHiddenByView[view] = true
}

notifyViewAnnotationObserversVisibilityDidChange(for: Array(viewsWithUpdatedVisibility))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it defer as well for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Co-authored-by: Roman Gardukevich <roman.gardukevich@mapbox.com>
@evil159 evil159 enabled auto-merge (squash) February 23, 2022 15:16
@evil159 evil159 force-pushed the new-viewpoint-annotations-api branch from 0540c6f to 561fa9a Compare February 23, 2022 15:32
@evil159 evil159 merged commit ca2849c into main Feb 23, 2022
@evil159 evil159 deleted the new-viewpoint-annotations-api branch February 23, 2022 15:49
OdNairy pushed a commit that referenced this pull request Aug 22, 2023
Add automation workflow to move new issues to backlog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants