Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 82f7956

Browse files
author
Scott Goodson
committed
[ASMapNode] Some improvements to layout logic and snapshot triggering.
1 parent 570d3e2 commit 82f7956

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

AsyncDisplayKit/ASMapNode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
3636
@property (nonatomic, assign, getter=isLiveMap) BOOL liveMap;
3737

3838
/**
39-
@abstract Whether ASMapNode should automatically request a new map snapshot to correspond to the new node size. Defaults to YES.
39+
@abstract Whether ASMapNode should automatically request a new map snapshot to correspond to the new node size.
40+
@default Default value is YES.
4041
@discussion If mapSize is set then this will be set to NO, since the size will be the same in all orientations.
4142
*/
4243
@property (nonatomic, assign) BOOL needsMapReloadOnBoundsChange;

AsyncDisplayKit/ASMapNode.mm

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ - (MKMapSnapshotOptions *)options
117117
if (!_options) {
118118
_options = [[MKMapSnapshotOptions alloc] init];
119119
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
120-
_options.size = self.calculatedSize;
120+
CGSize calculatedSize = self.calculatedSize;
121+
if (!CGSizeEqualToSize(calculatedSize, CGSizeZero)) {
122+
_options.size = calculatedSize;
123+
}
121124
}
122125
return _options;
123126
}
@@ -250,6 +253,24 @@ - (void)setAnnotations:(NSArray *)annotations
250253
}
251254

252255
#pragma mark - Layout
256+
- (void)setSnapshotSizeIfNeeded:(CGSize)snapshotSize
257+
{
258+
if (!CGSizeEqualToSize(self.options.size, snapshotSize)) {
259+
_options.size = snapshotSize;
260+
[self resetSnapshotter];
261+
}
262+
}
263+
264+
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
265+
{
266+
CGSize size = self.preferredFrameSize;
267+
if (CGSizeEqualToSize(size, CGSizeZero)) {
268+
size = constrainedSize;
269+
}
270+
[self setSnapshotSizeIfNeeded:size];
271+
return constrainedSize;
272+
}
273+
253274
// Layout isn't usually needed in the box model, but since we are making use of MKMapView this is preferred.
254275
- (void)layout
255276
{
@@ -258,9 +279,10 @@ - (void)layout
258279
_mapView.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height);
259280
} else {
260281
// If our bounds.size is different from our current snapshot size, then let's request a new image from MKMapSnapshotter.
261-
if (!CGSizeEqualToSize(_options.size, self.bounds.size) && _needsMapReloadOnBoundsChange) {
262-
_options.size = self.bounds.size;
263-
[self resetSnapshotter];
282+
if (_needsMapReloadOnBoundsChange) {
283+
[self setSnapshotSizeIfNeeded:self.bounds.size];
284+
// FIXME: Adding a check for FetchData here seems to cause intermittent map load failures, but shouldn't.
285+
// if (ASInterfaceStateIncludesFetchData(self.interfaceState)) {
264286
[self takeSnapshot];
265287
}
266288
}

0 commit comments

Comments
 (0)