Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Optional positioning and stickiness for callout view #7646

Merged
merged 1 commit into from
Jan 11, 2017

Conversation

frederoni
Copy link
Contributor

@frederoni frederoni commented Jan 9, 2017

This proposal makes the MGLCalloutView a bit more versatile by adding an anchoredToAnnotation and a dismissesAutomatically property. It also fixes issues like #7483 by falling back to the same behavior as in 3.4.0 beta 4 by default.

animation

/cc @friedbunny @1ec5 @boundsj

@frederoni frederoni added annotations Annotations on iOS and macOS or markers on Android iOS Mapbox Maps SDK for iOS release blocker Blocks the next final release labels Jan 9, 2017
@frederoni frederoni added this to the ios-v3.4.0 milestone Jan 9, 2017
@frederoni frederoni self-assigned this Jan 9, 2017
@frederoni frederoni requested a review from friedbunny January 9, 2017 16:35
@mention-bot
Copy link

@frederoni, thanks for your PR! By analyzing this pull request, we identified @1ec5, @incanus and @boundsj to be potential reviewers.

@frederoni frederoni force-pushed the fred-callout-view-improvements-7483 branch from 4004ca1 to c358bc6 Compare January 9, 2017 16:37
A Boolean value indicating whether the callout view should be positioned automatically.
The exact position can be adjusted by overriding -[UIView setCenter:]
*/
@property (nonatomic, assign) BOOL automaticPositioning;
Copy link
Contributor

Choose a reason for hiding this comment

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

A Boolean-typed property shouldn’t be named with a noun phrase. How about anchoredToAnnotation, with a getter isAnchoredToAnnotation?

A Boolean value indicating whether the callout view should be dismissed or not
when the map view changes viewport.
*/
@property (nonatomic, assign) BOOL staysOpen;
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 reverse the logic and call it dismissesAutomatically? I think that would make the behavior clearer, as evidenced by the description you wrote for this property.

A Boolean value indicating whether the callout view should be positioned automatically.
The exact position can be adjusted by overriding -[UIView setCenter:]
*/
@property (nonatomic, assign) BOOL automaticPositioning;
Copy link
Contributor

@1ec5 1ec5 Jan 9, 2017

Choose a reason for hiding this comment

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

Positioning automatically can mean many things. I think the fundamental difference between MGLCompactCalloutView and the custom callout view that ran into this bug is that MGLCompactCalloutView is relatively positioned, while that custom callout view is absolutely positioned – kind of like MGLRotationAlignmentMap versus MGLRotationAlignmentViewport. So another possibility would be to call this property relativelyPositioned.

Copy link
Contributor

Choose a reason for hiding this comment

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

The words “automatic” or “relative” are too ambiguous here, for me. Of @1ec5’s suggestions, I like anchoredToAnnotation, because it makes this property’s action on the callout’s position and the annotation clear.

A Boolean value indicating whether the callout view should be positioned automatically.
The exact position can be adjusted by overriding -[UIView setCenter:]
*/
@property (nonatomic, assign) BOOL automaticPositioning;
Copy link
Contributor

Choose a reason for hiding this comment

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

Mark these two properties as optional; adding a required member to a public protocol is a backwards-incompatible change. We’ll have to figure out what to do if the properties aren’t implemented.

A Boolean value indicating whether the callout view should be positioned automatically.
The exact position can be adjusted by overriding -[UIView setCenter:]
*/
@property (nonatomic, assign) BOOL automaticPositioning;
Copy link
Contributor

Choose a reason for hiding this comment

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

Mark these properties as readonly, because MGLMapView doesn’t care if the class implements -setAutomaticPositioning: – it’ll never call that setter anyways.

@frederoni frederoni force-pushed the fred-callout-view-improvements-7483 branch from f48c2a7 to 15df576 Compare January 10, 2017 12:53

/**
A Boolean value indicating whether the callout view should be dismissed automatically
when the map view changes viewport. Note that a single tap on the map view
Copy link
Contributor

Choose a reason for hiding this comment

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

s/when the map view changes viewport/when the map view’s viewport changes/

/**
A Boolean value indicating whether the callout view should be dismissed automatically
when the map view changes viewport. Note that a single tap on the map view
still dismisses the callout view.
Copy link
Contributor

Choose a reason for hiding this comment

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

…regardless of the value of this property.

/**
A Boolean value indicating whether the callout view should be anchored to
the corresponding annotation. The exact position can be adjusted by
overriding -[UIView setCenter:]
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if this property (and the other one) is omitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. As of 46dd0a6 , it defaults to dismissesAutomatically.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you point out the default behavior in the documentation for both properties (so developers know whether they need to implement them or not)?

/**
A Boolean value indicating whether the callout view should be anchored to
the corresponding annotation. The exact position can be adjusted by
overriding -[UIView setCenter:]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: avoid passive voice:

You can adjust the callout view’s precise location by overriding -[UIView setCenter:].

@synthesize anchoredToAnnotation = _anchoredToAnnotation;
@synthesize dismissesAutomatically = _dismissesAutomatically;

- (instancetype)init {
Copy link
Contributor

Choose a reason for hiding this comment

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

-init is not the designated initializer for UIView instances; that’d be either -initWithFrame: or -initWithCoder:. This class’s +platformCalloutView implementation happens to call -init, but this is a bit of an antipattern.

Instead of maintaining ivars for read-only variables, implement -anchoredToAnnotation and -dismissesAutomatically to return YES and NO, respectively.

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Good to go as soon as the documentation requested in #7646 (comment) is added.

@frederoni frederoni force-pushed the fred-callout-view-improvements-7483 branch from 7462995 to a59a382 Compare January 11, 2017 13:30
@friedbunny
Copy link
Contributor

Let’s also update the changelog entry for this feature/fix. Currently, it’s:

Fixed an issue causing the callout view to be dismissed when panning around. (#6676)

@1ec5
Copy link
Contributor

1ec5 commented Jan 11, 2017

The changelog entry is correct: in v3.3.7, panning incorrectly dismissed the callout view; in v3.4.0, the callout view will stay open. We can update the beta release notes to note this fix, however.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android iOS Mapbox Maps SDK for iOS release blocker Blocks the next final release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants