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

Fix view annotation losing its feature association after update #1446

Merged

Conversation

evil159
Copy link
Contributor

@evil159 evil159 commented Jul 12, 2022

This PR addresses the issue when a view annotation loses its feature id association when updating other(non-associatedFeatureId) properties.

Pull request checklist:

  • Write tests for all new functionality. If tests were not written, please explain why.
  • 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 requested a review from endanke July 13, 2022 08:24
@evil159 evil159 marked this pull request as ready for review July 13, 2022 08:24
@evil159 evil159 requested a review from a team as a code owner July 13, 2022 08:24
@@ -193,7 +193,7 @@ public final class ViewAnnotationManager {
let isHidden = !(options.visible ?? true)
expectedHiddenByView[view] = isHidden
viewsById[id]?.isHidden = isHidden
if let id = currentFeatureId, id != options.associatedFeatureId {
if let id = currentFeatureId, let updatedId = options.associatedFeatureId, id != updatedId {
viewsByFeatureIds[id] = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not quite understand this change. It looks like the same lines to me. Can you explain to me, please?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, now I see – options.associatedFeatureId has to be non-nil, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By unwrapping the options.associatedFeatureId this makes sure that a view loses its feature id association only when the feature id got updated, previously it would loose the association on every update.

Some sample code to illustrate this:

let view = UIView()
let id = UUID().uuidString
let options = ViewAnnotationOptions(associatedFeatureId: id)

try manager.add(view, options: options)
try manager.update(view, options: ViewAnnotationOptions(width: 100, height: 100))

// previosly
manager.view(forFeatureId: id) // nil 💥

// fixed
manager.view(forFeatureId: id) // returns the view ✅

@@ -193,7 +193,7 @@ public final class ViewAnnotationManager {
let isHidden = !(options.visible ?? true)
expectedHiddenByView[view] = isHidden
viewsById[id]?.isHidden = isHidden
if let id = currentFeatureId, id != options.associatedFeatureId {
if let id = currentFeatureId, let updatedId = options.associatedFeatureId, id != updatedId {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
if let id = currentFeatureId, let updatedId = options.associatedFeatureId, id != updatedId {
if !(currentFeatureId == options.associatedFeatureId) {

Copy link
Contributor

Choose a reason for hiding this comment

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

It's also probably make sense to add an explicit comment above

@evil159 evil159 enabled auto-merge (squash) July 13, 2022 12:37
@evil159 evil159 force-pushed the rl/MAPSIOS-11-fix_view_annotation_options_feature_id_update branch from 3ea5e15 to a29ca8b Compare July 13, 2022 13:09
@evil159 evil159 merged commit 94dcda8 into main Jul 13, 2022
@evil159 evil159 deleted the rl/MAPSIOS-11-fix_view_annotation_options_feature_id_update branch July 13, 2022 13:18
OdNairy added a commit that referenced this pull request Jul 14, 2022
* Update changelog (#1418)

* Add style toggle to location example (#1413)

* [XCParty] Add tag name if HEAD has any (#1424)

* [XCParty] Export crash reports for XCResult (#1434)

* Expose a way to initialise TilesetDescriptorOptionsForTilesets (#1431)

* Add cast shadow option to 3d puck config (#1435)

* Mark camera functions as unsupported for globe projection, invocation results in a no-op (#1440)

* Rotation gesture threshold and simultaneousRotateAndPinchToZoomEnabled option (#1429)

* Add option to support measurements from the only last run (#1445)

* Update examples (#1443)

* Fix flaky test (#1450)

* Fix view annotation losing its feature association after update (#1446)

* Enable `modelCastsShadow` option for custom location puck config (#1447)

* enabled model casts shadows option for custom location puck configuration

* Provide default value for list of last-run metrics (#1453)

* Update CoreMaps to `10.7.0-rc.1` (#1456)

* Update CoreMaps to 10.7.0-rc.1

* Update changelog

* Update changelog header (#1459)

* Update 10.7.0 versions (#1460)

Co-authored-by: ZiZi <44972592+ZiZasaurus@users.noreply.github.com>
Co-authored-by: Roman Laitarenko <roman.laitarenko@mapbox.com>
Co-authored-by: Tobrun <tobrun.van.nuland@gmail.com>
OdNairy added a commit that referenced this pull request Jul 14, 2022
* Add style toggle to location example (#1413)

* [XCParty] Add tag name if HEAD has any (#1424)

* [XCParty] Export crash reports for XCResult (#1434)

* Expose a way to initialise TilesetDescriptorOptionsForTilesets (#1431)

* Add cast shadow option to 3d puck config (#1435)

* Mark camera functions as unsupported for globe projection, invocation results in a no-op (#1440)

* Rotation gesture threshold and simultaneousRotateAndPinchToZoomEnabled option (#1429)

* Add option to support measurements from the only last run (#1445)

* Update examples (#1443)

* Fix flaky test (#1450)

* Fix view annotation losing its feature association after update (#1446)

* Enable `modelCastsShadow` option for custom location puck config (#1447)

* enabled model casts shadows option for custom location puck configuration

* Provide default value for list of last-run metrics (#1453)

* Update CoreMaps to `10.7.0-rc.1` (#1456)

* Update CoreMaps to 10.7.0-rc.1

* Update changelog

* Update changelog header (#1459)

* Update 10.7.0 versions (#1460)

Co-authored-by: ZiZi <44972592+ZiZasaurus@users.noreply.github.com>
Co-authored-by: Roman Laitarenko <roman.laitarenko@mapbox.com>
Co-authored-by: Tobrun <tobrun.van.nuland@gmail.com>
OdNairy pushed a commit that referenced this pull request Apr 6, 2023
* Remove unnecessary check before updating a geo json source

* Update changelog
mapbox-github-ci-writer-public-1 bot pushed a commit that referenced this pull request Apr 13, 2023
* Remove unnecessary check before updating a geo json source

* Update changelog
OdNairy pushed a commit that referenced this pull request Aug 22, 2023
* Remove unnecessary check before updating a geo json source

* Update changelog
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.

None yet

3 participants