mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
99bc08cf61
Summary: Started from here - https://github.com/facebook/react-native/issues/1120. Most functionality for annotations were missing so I started implementing and somehow got caught up until the entire thing was done. ![screen shot 2015-05-12 at 10 07 43 pm](https://cloud.githubusercontent.com/assets/688326/7588677/8479a7a4-f8f9-11e4-99a4-1dc3c7691810.png) 2 new events: - callout presses (left / right) - annotation presses 6 new properties for annotations: - hasLeftCallout - hasRightCallout - onLeftCalloutPress - onRightCalloutPress - animateDrop - id 1 new property for MapView - onAnnotationPress --- Now the important thing is, that I implemented all of this the way "I would do it". I am not sure this is the 'reacty' way so please let me know my mistakes 😄 The problem is that there is no real way to identify annotations which makes it difficult to distinguish which one got clicked. The idea is to pass a `id` and whether it has callouts the entire way with the annotation. I had to Closes https://github.com/facebook/react-native/pull/1247 Github Author: David Mohl <me@dave.cx> Test Plan: Imported from GitHub, without a `Test Plan:` line.
70 lines
2.0 KiB
Objective-C
70 lines
2.0 KiB
Objective-C
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import "RCTConvert+MapKit.h"
|
|
#import "RCTConvert+CoreLocation.h"
|
|
#import "RCTPointAnnotation.h"
|
|
|
|
@implementation RCTConvert(MapKit)
|
|
|
|
+ (MKCoordinateSpan)MKCoordinateSpan:(id)json
|
|
{
|
|
json = [self NSDictionary:json];
|
|
return (MKCoordinateSpan){
|
|
[self CLLocationDegrees:json[@"latitudeDelta"]],
|
|
[self CLLocationDegrees:json[@"longitudeDelta"]]
|
|
};
|
|
}
|
|
|
|
+ (MKCoordinateRegion)MKCoordinateRegion:(id)json
|
|
{
|
|
return (MKCoordinateRegion){
|
|
[self CLLocationCoordinate2D:json],
|
|
[self MKCoordinateSpan:json]
|
|
};
|
|
}
|
|
|
|
+ (MKShape *)MKShape:(id)json
|
|
{
|
|
json = [self NSDictionary:json];
|
|
|
|
// TODO: more shape types
|
|
MKShape *shape = [[MKPointAnnotation alloc] init];
|
|
shape.coordinate = [self CLLocationCoordinate2D:json];
|
|
shape.title = [RCTConvert NSString:json[@"title"]];
|
|
shape.subtitle = [RCTConvert NSString:json[@"subtitle"]];
|
|
return shape;
|
|
}
|
|
|
|
RCT_ARRAY_CONVERTER(MKShape)
|
|
|
|
RCT_ENUM_CONVERTER(MKMapType, (@{
|
|
@"standard": @(MKMapTypeStandard),
|
|
@"satellite": @(MKMapTypeSatellite),
|
|
@"hybrid": @(MKMapTypeHybrid),
|
|
}), MKMapTypeStandard, integerValue)
|
|
|
|
+ (RCTPointAnnotation *)RCTPointAnnotation:(id)json
|
|
{
|
|
json = [self NSDictionary:json];
|
|
RCTPointAnnotation *shape = [[RCTPointAnnotation alloc] init];
|
|
shape.coordinate = [self CLLocationCoordinate2D:json];
|
|
shape.title = [RCTConvert NSString:json[@"title"]];
|
|
shape.subtitle = [RCTConvert NSString:json[@"subtitle"]];
|
|
shape.identifier = [RCTConvert NSString:json[@"id"]];
|
|
shape.hasLeftCallout = [RCTConvert BOOL:json[@"hasLeftCallout"]];
|
|
shape.hasRightCallout = [RCTConvert BOOL:json[@"hasRightCallout"]];
|
|
shape.animateDrop = [RCTConvert BOOL:json[@"animateDrop"]];
|
|
return shape;
|
|
}
|
|
|
|
RCT_ARRAY_CONVERTER(RCTPointAnnotation)
|
|
|
|
@end
|