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

[iOS] Added onPress support for Polygons on Google Maps #1024

Merged
merged 1 commit into from
Mar 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/MapPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const propTypes = {
*/
onPress: PropTypes.func,

/**
* Boolean to allow a polygon to be tappable and use the
* onPress function
*/
tappable: PropTypes.bool,

/**
* The stroke width to use for the path.
*/
Expand Down
1 change: 1 addition & 0 deletions example/examples/EventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class EventListener extends React.Component {
<MapView.Polygon
fillColor={'rgba(255,0,0,0.3)'}
onPress={this.recordEvent('Polygon::onPress')}
tappable
coordinates={[{
latitude: LATITUDE + (LATITUDE_DELTA / 5),
longitude: LONGITUDE + (LONGITUDE_DELTA / 4),
Expand Down
6 changes: 6 additions & 0 deletions example/ios/AirMapsExplorer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
21E6570C1D77591A00B75EE5 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21E6570B1D77591A00B75EE5 /* MobileCoreServices.framework */; };
21E6570E1D77591F00B75EE5 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21E6570D1D77591F00B75EE5 /* MapKit.framework */; };
21E657101D77594C00B75EE5 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21E6570F1D77594C00B75EE5 /* AudioToolbox.framework */; };
5647FBD81E47A82C0054FF00 /* AIRGMSPolygon.m in Sources */ = {isa = PBXBuildFile; fileRef = 5647FBD71E47A82C0054FF00 /* AIRGMSPolygon.m */; };
8620CC871DBD814A00B79BFE /* AIRGMSMarker.m in Sources */ = {isa = PBXBuildFile; fileRef = 8620CC6E1DBD814A00B79BFE /* AIRGMSMarker.m */; };
8620CC881DBD814A00B79BFE /* AIRGoogleMap.m in Sources */ = {isa = PBXBuildFile; fileRef = 8620CC701DBD814A00B79BFE /* AIRGoogleMap.m */; };
8620CC891DBD814A00B79BFE /* AIRGoogleMapCallout.m in Sources */ = {isa = PBXBuildFile; fileRef = 8620CC721DBD814A00B79BFE /* AIRGoogleMapCallout.m */; };
Expand Down Expand Up @@ -116,6 +117,8 @@
21E6570B1D77591A00B75EE5 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
21E6570D1D77591F00B75EE5 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
21E6570F1D77594C00B75EE5 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
5647FBD61E47A82C0054FF00 /* AIRGMSPolygon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIRGMSPolygon.h; sourceTree = "<group>"; };
5647FBD71E47A82C0054FF00 /* AIRGMSPolygon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIRGMSPolygon.m; sourceTree = "<group>"; };
8620CC6D1DBD814A00B79BFE /* AIRGMSMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIRGMSMarker.h; sourceTree = "<group>"; };
8620CC6E1DBD814A00B79BFE /* AIRGMSMarker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIRGMSMarker.m; sourceTree = "<group>"; };
8620CC6F1DBD814A00B79BFE /* AIRGoogleMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIRGoogleMap.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -293,6 +296,8 @@
isa = PBXGroup;
children = (
8620CC6D1DBD814A00B79BFE /* AIRGMSMarker.h */,
5647FBD61E47A82C0054FF00 /* AIRGMSPolygon.h */,
5647FBD71E47A82C0054FF00 /* AIRGMSPolygon.m */,
8620CC6E1DBD814A00B79BFE /* AIRGMSMarker.m */,
8620CC6F1DBD814A00B79BFE /* AIRGoogleMap.h */,
8620CC701DBD814A00B79BFE /* AIRGoogleMap.m */,
Expand Down Expand Up @@ -510,6 +515,7 @@
buildActionMask = 2147483647;
files = (
8620CC891DBD814A00B79BFE /* AIRGoogleMapCallout.m in Sources */,
5647FBD81E47A82C0054FF00 /* AIRGMSPolygon.m in Sources */,
8620CC8D1DBD814A00B79BFE /* AIRGoogleMapMarkerManager.m in Sources */,
8620CC881DBD814A00B79BFE /* AIRGoogleMap.m in Sources */,
2166AB2D1D82EC56007538D7 /* AIRMapCircleManager.m in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions ios/AirGoogleMaps/AIRGMSPolygon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// AIRGMSPolygon.h
// AirMaps
//
// Created by Gerardo Pacheco 02/05/2017.
//

#import <GoogleMaps/GoogleMaps.h>
#import "UIView+React.h"

@class AIRGoogleMapPolygon;

@interface AIRGMSPolygon : GMSPolygon
@property (nonatomic, strong) NSString *identifier;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@end
12 changes: 12 additions & 0 deletions ios/AirGoogleMaps/AIRGMSPolygon.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// AIRGMSPolygon.m
// AirMaps
//
// Created by Gerardo Pacheco 02/05/2017.
//

#import "AIRGMSPolygon.h"

@implementation AIRGMSPolygon

@end
1 change: 1 addition & 0 deletions ios/AirGoogleMaps/AIRGoogleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@property (nonatomic, assign) BOOL showsUserLocation;

- (BOOL)didTapMarker:(GMSMarker *)marker;
- (void)didTapPolygon:(GMSPolygon *)polygon;
- (void)didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;
- (void)didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;
- (void)didChangeCameraPosition:(GMSCameraPosition *)position;
Expand Down
10 changes: 10 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ - (BOOL)didTapMarker:(GMSMarker *)marker {
return NO;
}

- (void)didTapPolygon:(GMSOverlay *)polygon {
AIRGMSPolygon *airPolygon = (AIRGMSPolygon *)polygon;

id event = @{@"action": @"polygon-press",
@"id": airPolygon.identifier ?: @"unknown",
};

if (airPolygon.onPress) airPolygon.onPress(event);
}

- (void)didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (!self.onPress) return;
self.onPress([self eventFromCoordinate:coordinate]);
Expand Down
5 changes: 5 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
return [googleMapView didTapMarker:marker];
}

- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSPolygon *)polygon {
AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView;
[googleMapView didTapPolygon:polygon];
}

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView;
[googleMapView didTapAtCoordinate:coordinate];
Expand Down
8 changes: 7 additions & 1 deletion ios/AirGoogleMaps/AIRGoogleMapPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
//

#import <GoogleMaps/GoogleMaps.h>
#import <React/RCTBridge.h>
#import "AIRGMSPolygon.h"
#import "AIRMapCoordinate.h"

@interface AIRGoogleMapPolygon : UIView

@property (nonatomic, strong) GMSPolygon *polygon;
@property (nonatomic, weak) RCTBridge *bridge;
@property (nonatomic, strong) NSString *identifier;
@property (nonatomic, strong) AIRGMSPolygon *polygon;
@property (nonatomic, strong) NSArray<AIRMapCoordinate *> *coordinates;
@property (nonatomic, strong) NSArray<NSArray<AIRMapCoordinate *> *> *holes;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;

@property (nonatomic, assign) UIColor *fillColor;
@property (nonatomic, assign) double strokeWidth;
@property (nonatomic, assign) UIColor *strokeColor;
@property (nonatomic, assign) BOOL geodesic;
@property (nonatomic, assign) int zIndex;
@property (nonatomic, assign) BOOL tappable;

@end
13 changes: 12 additions & 1 deletion ios/AirGoogleMaps/AIRGoogleMapPolygon.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
//

#import "AIRGoogleMapPolygon.h"
#import "AIRGMSPolygon.h"
#import <GoogleMaps/GoogleMaps.h>

@implementation AIRGoogleMapPolygon

- (instancetype)init
{
if (self = [super init]) {
_polygon = [[GMSPolygon alloc] init];
_polygon = [[AIRGMSPolygon alloc] init];
}

return self;
Expand Down Expand Up @@ -82,4 +83,14 @@ -(void)setZIndex:(int)zIndex
_polygon.zIndex = zIndex;
}

-(void)setTappable:(BOOL)tappable
{
_tappable = tappable;
_polygon.tappable = tappable;
}

- (void)setOnPress:(RCTBubblingEventBlock)onPress {
_polygon.onPress = onPress;
}

@end
3 changes: 3 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMapPolygonManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @implementation AIRGoogleMapPolygonManager
- (UIView *)view
{
AIRGoogleMapPolygon *polygon = [AIRGoogleMapPolygon new];
polygon.bridge = self.bridge;
return polygon;
}

Expand All @@ -35,5 +36,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(strokeColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(geodesic, BOOL)
RCT_EXPORT_VIEW_PROPERTY(zIndex, int)
RCT_EXPORT_VIEW_PROPERTY(tappable, BOOL)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)

@end