This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] Refined custom callout view support
Renamed MGLCalloutView to MGLCompactCalloutView and MGLCalloutViewProtocol to MGLCalloutView to avoid an awkward workaround for a Swift name collision. Replaced individual title and subtitle properties with a single representedObject property that lets you use custom annotation properties in the custom callout view. Overrode a problematic SMCalloutView method. Added lots more documentation.
- Loading branch information
Showing
13 changed files
with
151 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
#import "MGLTypes.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@protocol MGLCalloutViewDelegate; | ||
@protocol MGLAnnotation; | ||
|
||
/** | ||
A protocol for a `UIView` subclass that displays information about a selected annotation near that annotation. | ||
*/ | ||
@protocol MGLCalloutView <NSObject> | ||
|
||
/** | ||
An object conforming to the `MGLAnnotation` protocol whose details this callout view displays. | ||
*/ | ||
@property (nonatomic, strong) id <MGLAnnotation> representedObject; | ||
|
||
/** | ||
A view that the user may tap to perform an action. This view is conventionally positioned on the left side of the callout view. | ||
*/ | ||
@property (nonatomic, strong) UIView *leftAccessoryView; | ||
|
||
/** | ||
A view that the user may tap to perform an action. This view is conventionally positioned on the right side of the callout view. | ||
*/ | ||
@property (nonatomic, strong) UIView *rightAccessoryView; | ||
|
||
/** | ||
An object conforming to the `MGLCalloutViewDelegate` method that receives messages related to the callout view’s interactive subviews. | ||
*/ | ||
@property (nonatomic, weak) id<MGLCalloutViewDelegate> delegate; | ||
|
||
/** | ||
Presents a callout view by adding it to `inView` and pointing at the given rect of `inView`’s bounds. Constrains the callout to the bounds of the given view. | ||
*/ | ||
- (void)presentCalloutFromRect:(CGRect)rect inView:(UIView *)view constrainedToView:(UIView *)constrainedView animated:(BOOL)animated; | ||
|
||
/** | ||
Dismisses the callout view. | ||
*/ | ||
- (void)dismissCalloutAnimated:(BOOL)animated; | ||
|
||
@end | ||
|
||
/** | ||
The MGLCalloutViewDelegate protocol defines a set of optional methods that you can use to receive messages from an object that conforms to the MGLCalloutView protocol. The callout view uses these methods to inform the delegate that the user has interacted with the the callout view. | ||
*/ | ||
@protocol MGLCalloutViewDelegate <NSObject> | ||
|
||
@optional | ||
/** | ||
Returns a Boolean value indicating whether the entire callout view “highlights” when tapped. The default value is `YES`, which means the callout view highlights when tapped. | ||
The return value of this method is ignored unless the delegate also responds to the `-calloutViewTapped` method. | ||
*/ | ||
- (BOOL)calloutViewShouldHighlight:(UIView<MGLCalloutView> *)calloutView; | ||
|
||
/** | ||
Tells the delegate that the callout view has been tapped. | ||
*/ | ||
- (void)calloutViewTapped:(UIView<MGLCalloutView> *)calloutView; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
#import <UIKit/UIKit.h> | ||
#import <mbgl/ios/MGLCalloutViewProtocol.h> | ||
#import <mbgl/ios/MGLCalloutView.h> | ||
|
||
/* | ||
/** | ||
* Basic custom callout view to demonstrate how to | ||
* add your own on your app. Will only show the | ||
* callout title for demonstration purpose. | ||
*/ | ||
|
||
@interface MBXCustomCalloutView : UIView <MGLCalloutViewProtocol> | ||
|
||
@property (nonatomic, copy) NSString *title, *subtitle; | ||
@property (nonatomic, strong) UIView *leftAccessoryView, *rightAccessoryView; | ||
@property (nonatomic, weak) id<MGLCalloutViewDelegate> delegate; | ||
|
||
@interface MBXCustomCalloutView : UIView <MGLCalloutView> | ||
@end |
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#import "SMCalloutView.h" | ||
#import "MGLCalloutView.h" | ||
|
||
/** | ||
A concrete implementation of `MGLCalloutView` based on [SMCalloutView](https://github.com/nfarina/calloutview). This callout view displays the represented annotation’s title, subtitle, and accessory views in a compact, two-line layout. | ||
*/ | ||
@interface MGLCompactCalloutView : SMCalloutView <MGLCalloutView> | ||
|
||
+ (instancetype)platformCalloutView; | ||
|
||
@end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#import "MGLCompactCalloutView.h" | ||
|
||
#import "MGLAnnotation.h" | ||
|
||
@implementation MGLCompactCalloutView | ||
{ | ||
id <MGLAnnotation> _representedObject; | ||
} | ||
|
||
@synthesize representedObject = _representedObject; | ||
|
||
+ (instancetype)platformCalloutView | ||
{ | ||
return [[self alloc] init]; | ||
} | ||
|
||
- (void)setRepresentedObject:(id <MGLAnnotation>)representedObject | ||
{ | ||
_representedObject = representedObject; | ||
|
||
if ([representedObject respondsToSelector:@selector(title)]) | ||
{ | ||
self.title = representedObject.title; | ||
} | ||
if ([representedObject respondsToSelector:@selector(subtitle)]) | ||
{ | ||
self.subtitle = representedObject.subtitle; | ||
} | ||
} | ||
|
||
@end |
This file contains 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
This is a delegate method of SMCalloutView. It should be named calloutViewClicked. The map view no longer responds to the user clicking the callout view. (tapping the accessory views still work, but not the callout itself.)