mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
[ASMapNode] snapshot can be triggered before layout and cause exception (e.g. setAnnotations)
This commit is contained in:
parent
83a3a835b9
commit
c981aeb09d
@ -89,7 +89,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* @discussion Gives a chance for subclasses to perform actions after the subclass and superclass have finished laying
|
* @discussion Gives a chance for subclasses to perform actions after the subclass and superclass have finished laying
|
||||||
* out.
|
* out.
|
||||||
*/
|
*/
|
||||||
- (void)layoutDidFinish;
|
- (void)layoutDidFinish ASDISPLAYNODE_REQUIRES_SUPER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract Called on a background thread if !isNodeLoaded - called on the main thread if isNodeLoaded.
|
* @abstract Called on a background thread if !isNodeLoaded - called on the main thread if isNodeLoaded.
|
||||||
@ -97,7 +97,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
* @discussion When the .calculatedLayout property is set to a new ASLayout (directly from -calculateLayoutThatFits: or
|
* @discussion When the .calculatedLayout property is set to a new ASLayout (directly from -calculateLayoutThatFits: or
|
||||||
* calculated via use of -layoutSpecThatFits:), subclasses may inspect it here.
|
* calculated via use of -layoutSpecThatFits:), subclasses may inspect it here.
|
||||||
*/
|
*/
|
||||||
- (void)calculatedLayoutDidChange;
|
- (void)calculatedLayoutDidChange ASDISPLAYNODE_REQUIRES_SUPER;
|
||||||
|
|
||||||
/** @name Layout calculation */
|
/** @name Layout calculation */
|
||||||
|
|
||||||
|
|||||||
@ -14,11 +14,13 @@
|
|||||||
#import <AsyncDisplayKit/ASCenterLayoutSpec.h>
|
#import <AsyncDisplayKit/ASCenterLayoutSpec.h>
|
||||||
#import <AsyncDisplayKit/ASThread.h>
|
#import <AsyncDisplayKit/ASThread.h>
|
||||||
#import <AsyncDisplayKit/ASInternalHelpers.h>
|
#import <AsyncDisplayKit/ASInternalHelpers.h>
|
||||||
|
#import <AsyncDisplayKit/ASLayout.h>
|
||||||
|
|
||||||
@interface ASMapNode()
|
@interface ASMapNode()
|
||||||
{
|
{
|
||||||
ASDN::RecursiveMutex _propertyLock;
|
ASDN::RecursiveMutex _propertyLock;
|
||||||
MKMapSnapshotter *_snapshotter;
|
MKMapSnapshotter *_snapshotter;
|
||||||
|
BOOL _snapshotNeeded;
|
||||||
NSArray *_annotations;
|
NSArray *_annotations;
|
||||||
CLLocationCoordinate2D _centerCoordinateOfMap;
|
CLLocationCoordinate2D _centerCoordinateOfMap;
|
||||||
}
|
}
|
||||||
@ -159,6 +161,15 @@
|
|||||||
|
|
||||||
- (void)takeSnapshot
|
- (void)takeSnapshot
|
||||||
{
|
{
|
||||||
|
// do not trigger snapshot before layout
|
||||||
|
ASLayout *layout = self.calculatedLayout;
|
||||||
|
if (layout == nil || CGSizeEqualToSize(CGSizeZero, layout.size)) {
|
||||||
|
_snapshotNeeded = YES;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_snapshotNeeded = NO;
|
||||||
|
|
||||||
if (!_snapshotter) {
|
if (!_snapshotter) {
|
||||||
[self setUpSnapshotter];
|
[self setUpSnapshotter];
|
||||||
}
|
}
|
||||||
@ -307,6 +318,15 @@
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)calculatedLayoutDidChange
|
||||||
|
{
|
||||||
|
[super calculatedLayoutDidChange];
|
||||||
|
|
||||||
|
if (_snapshotNeeded) {
|
||||||
|
[self takeSnapshot];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -layout isn't usually needed over -layoutSpecThatFits, but this way we can avoid a needless node wrapper for MKMapView.
|
// -layout isn't usually needed over -layoutSpecThatFits, but this way we can avoid a needless node wrapper for MKMapView.
|
||||||
- (void)layout
|
- (void)layout
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user