Fix indentation

This commit is contained in:
Aaron Schubert
2015-11-12 12:18:09 +00:00
parent fe06f211ca
commit 46bf49cae7
2 changed files with 134 additions and 133 deletions

View File

@@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree. An additional grant * 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. * of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <AsyncDisplayKit/AsyncDisplayKit.h> #import <AsyncDisplayKit/AsyncDisplayKit.h>
#import <MapKit/MapKit.h> #import <MapKit/MapKit.h>
@interface ASMapNode : ASControlNode @interface ASMapNode : ASControlNode

View File

@@ -13,12 +13,12 @@
@interface ASMapNode() @interface ASMapNode()
{ {
ASDN::RecursiveMutex _propertyLock; ASDN::RecursiveMutex _propertyLock;
CGSize _nodeSize; CGSize _nodeSize;
MKMapSnapshotter *_snapshotter; MKMapSnapshotter *_snapshotter;
MKMapSnapshotOptions *_options; MKMapSnapshotOptions *_options;
CGSize _maxSize; CGSize _maxSize;
NSArray *_annotations; NSArray *_annotations;
} }
@end @end
@@ -34,202 +34,202 @@
if (!(self = [super init])) { if (!(self = [super init])) {
return nil; return nil;
} }
self.backgroundColor = ASDisplayNodeDefaultPlaceholderColor(); self.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
_hasLiveMap = YES; _hasLiveMap = YES;
_automaticallyReloadsMapImageOnOrientationChange = YES; _automaticallyReloadsMapImageOnOrientationChange = YES;
_options = [[MKMapSnapshotOptions alloc] init]; _options = [[MKMapSnapshotOptions alloc] init];
_options.region = MKCoordinateRegionMakeWithDistance(coordinate, 1000, 1000);; _options.region = MKCoordinateRegionMakeWithDistance(coordinate, 1000, 1000);;
_mapImage = [[ASImageNode alloc]init]; _mapImage = [[ASImageNode alloc]init];
_mapImage.clipsToBounds = YES; _mapImage.clipsToBounds = YES;
[self addSubnode:_mapImage]; [self addSubnode:_mapImage];
[self updateGesture]; [self updateGesture];
_maxSize = self.bounds.size; _maxSize = self.bounds.size;
return self; return self;
} }
- (void)addAnnotations:(NSArray *)annotations - (void)addAnnotations:(NSArray *)annotations
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
if (annotations.count == 0) { if (annotations.count == 0) {
return; return;
} }
_annotations = [annotations copy]; _annotations = [annotations copy];
if (annotations.count != _annotations.count && _mapImage.image) { if (annotations.count != _annotations.count && _mapImage.image) {
// Redraw // Redraw
[self setNeedsDisplay]; [self setNeedsDisplay];
} }
} }
- (void)setUpSnapshotter - (void)setUpSnapshotter
{ {
if (!_snapshotter) { if (!_snapshotter) {
_options.size = _nodeSize; _options.size = _nodeSize;
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options]; _snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
} }
} }
- (BOOL)hasLiveMap - (BOOL)hasLiveMap
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
return _hasLiveMap; return _hasLiveMap;
} }
- (void)setHasLiveMap:(BOOL)hasLiveMap - (void)setHasLiveMap:(BOOL)hasLiveMap
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
if (hasLiveMap == _hasLiveMap) if (hasLiveMap == _hasLiveMap)
return; return;
_hasLiveMap = hasLiveMap; _hasLiveMap = hasLiveMap;
[self updateGesture]; [self updateGesture];
} }
- (CGSize)mapSize - (CGSize)mapSize
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
return _mapSize; return _mapSize;
} }
- (void)setMapSize:(CGSize)mapSize - (void)setMapSize:(CGSize)mapSize
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
if (CGSizeEqualToSize(mapSize,_mapSize)) { if (CGSizeEqualToSize(mapSize,_mapSize)) {
return; return;
} }
_mapSize = mapSize; _mapSize = mapSize;
_nodeSize = _mapSize; _nodeSize = _mapSize;
_automaticallyReloadsMapImageOnOrientationChange = NO; _automaticallyReloadsMapImageOnOrientationChange = NO;
[self setNeedsLayout]; [self setNeedsLayout];
} }
- (BOOL)automaticallyReloadsMapImageOnOrientationChange - (BOOL)automaticallyReloadsMapImageOnOrientationChange
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
return _automaticallyReloadsMapImageOnOrientationChange; return _automaticallyReloadsMapImageOnOrientationChange;
} }
- (void)setAutomaticallyReloadsMapImageOnOrientationChange:(BOOL)automaticallyReloadsMapImageOnOrientationChange - (void)setAutomaticallyReloadsMapImageOnOrientationChange:(BOOL)automaticallyReloadsMapImageOnOrientationChange
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
if (_automaticallyReloadsMapImageOnOrientationChange == automaticallyReloadsMapImageOnOrientationChange) { if (_automaticallyReloadsMapImageOnOrientationChange == automaticallyReloadsMapImageOnOrientationChange) {
return; return;
} }
_automaticallyReloadsMapImageOnOrientationChange = automaticallyReloadsMapImageOnOrientationChange; _automaticallyReloadsMapImageOnOrientationChange = automaticallyReloadsMapImageOnOrientationChange;
} }
- (void)updateGesture - (void)updateGesture
{ {
_hasLiveMap ? [self addTarget:self action:@selector(showLiveMap) forControlEvents:ASControlNodeEventTouchUpInside] : [self removeTarget:self action:@selector(showLiveMap) forControlEvents:ASControlNodeEventTouchUpInside]; _hasLiveMap ? [self addTarget:self action:@selector(showLiveMap) forControlEvents:ASControlNodeEventTouchUpInside] : [self removeTarget:self action:@selector(showLiveMap) forControlEvents:ASControlNodeEventTouchUpInside];
} }
- (void)fetchData - (void)fetchData
{ {
[super fetchData]; [super fetchData];
[self setUpSnapshotter]; [self setUpSnapshotter];
[self takeSnapshot]; [self takeSnapshot];
} }
- (void)clearFetchedData - (void)clearFetchedData
{ {
[super clearFetchedData]; [super clearFetchedData];
if (_liveMap) { if (_liveMap) {
[_liveMap removeFromSupernode]; [_liveMap removeFromSupernode];
_liveMap = nil; _liveMap = nil;
} }
_mapImage.image = nil; _mapImage.image = nil;
} }
- (void)takeSnapshot - (void)takeSnapshot
{ {
if (!_snapshotter.isLoading) { if (!_snapshotter.isLoading) {
[_snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) { [_snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
if (!error) { if (!error) {
UIImage *image = snapshot.image; UIImage *image = snapshot.image;
CGRect finalImageRect = CGRectMake(0, 0, image.size.width, image.size.height); CGRect finalImageRect = CGRectMake(0, 0, image.size.width, image.size.height);
// Get a standard annotation view pin. Future implementations should use a custom annotation image property. // Get a standard annotation view pin. Future implementations should use a custom annotation image property.
MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:@""]; MKAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:@""];
UIImage *pinImage = pin.image; UIImage *pinImage = pin.image;
UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale); UIGraphicsBeginImageContextWithOptions(image.size, YES, image.scale);
[image drawAtPoint:CGPointMake(0, 0)]; [image drawAtPoint:CGPointMake(0, 0)];
for (id<MKAnnotation>annotation in _annotations) for (id<MKAnnotation>annotation in _annotations)
{ {
CGPoint point = [snapshot pointForCoordinate:annotation.coordinate]; CGPoint point = [snapshot pointForCoordinate:annotation.coordinate];
if (CGRectContainsPoint(finalImageRect, point)) if (CGRectContainsPoint(finalImageRect, point))
{ {
CGPoint pinCenterOffset = pin.centerOffset; CGPoint pinCenterOffset = pin.centerOffset;
point.x -= pin.bounds.size.width / 2.0; point.x -= pin.bounds.size.width / 2.0;
point.y -= pin.bounds.size.height / 2.0; point.y -= pin.bounds.size.height / 2.0;
point.x += pinCenterOffset.x; point.x += pinCenterOffset.x;
point.y += pinCenterOffset.y; point.y += pinCenterOffset.y;
[pinImage drawAtPoint:point]; [pinImage drawAtPoint:point];
} }
} }
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext(); UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); UIGraphicsEndImageContext();
_mapImage.image = finalImage; _mapImage.image = finalImage;
} }
}]; }];
} }
} }
- (void)resetSnapshotter - (void)resetSnapshotter
{ {
if (!_snapshotter.isLoading) { if (!_snapshotter.isLoading) {
_options.size = _nodeSize; _options.size = _nodeSize;
_snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options]; _snapshotter = [[MKMapSnapshotter alloc] initWithOptions:_options];
} }
} }
#pragma mark - Action #pragma mark - Action
- (void)showLiveMap - (void)showLiveMap
{ {
if (self.isNodeLoaded && !_liveMap) { if (self.isNodeLoaded && !_liveMap) {
_liveMap = [[ASDisplayNode alloc]initWithViewBlock:^UIView *{ _liveMap = [[ASDisplayNode alloc]initWithViewBlock:^UIView *{
MKMapView *mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height)]; MKMapView *mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height)];
mapView.delegate = _mapDelegate; mapView.delegate = _mapDelegate;
[mapView setRegion:_options.region]; [mapView setRegion:_options.region];
[mapView addAnnotations:_annotations]; [mapView addAnnotations:_annotations];
return mapView; return mapView;
}]; }];
[self addSubnode:_liveMap]; [self addSubnode:_liveMap];
_mapImage.image = nil; _mapImage.image = nil;
} }
} }
#pragma mark - Layout #pragma mark - Layout
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize - (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{ {
_nodeSize = CGSizeEqualToSize(CGSizeZero, _mapSize) ? CGSizeMake(constrainedSize.width, _options.size.height) : _mapSize; _nodeSize = CGSizeEqualToSize(CGSizeZero, _mapSize) ? CGSizeMake(constrainedSize.width, _options.size.height) : _mapSize;
if (_mapImage) { if (_mapImage) {
[_mapImage calculateSizeThatFits:_nodeSize]; [_mapImage calculateSizeThatFits:_nodeSize];
} }
return _nodeSize; return _nodeSize;
} }
// Layout isn't usually needed in the box model, but since we are making use of MKMapView which is hidden in an ASDisplayNode this is preferred. // Layout isn't usually needed in the box model, but since we are making use of MKMapView which is hidden in an ASDisplayNode this is preferred.
- (void)layout - (void)layout
{ {
[super layout]; [super layout];
if (_liveMap) { if (_liveMap) {
MKMapView *mapView = (MKMapView *)_liveMap.view; MKMapView *mapView = (MKMapView *)_liveMap.view;
mapView.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height); mapView.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height);
} }
else { else {
_mapImage.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height); _mapImage.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height);
if (!CGSizeEqualToSize(_maxSize, self.bounds.size)) { if (!CGSizeEqualToSize(_maxSize, self.bounds.size)) {
_mapImage.preferredFrameSize = self.bounds.size; _mapImage.preferredFrameSize = self.bounds.size;
_maxSize = self.bounds.size; _maxSize = self.bounds.size;
if (_automaticallyReloadsMapImageOnOrientationChange && _mapImage.image) { if (_automaticallyReloadsMapImageOnOrientationChange && _mapImage.image) {
[self resetSnapshotter]; [self resetSnapshotter];
[self takeSnapshot]; [self takeSnapshot];
} }
}
} }
}
} }
@end @end