Skip to content

Commit

Permalink
Add way to suppress invalid CollectionUpdateExceptions (TextureGroup#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maicki authored and mikezucc committed Nov 7, 2018
1 parent 86d6c41 commit 8b70abd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Source/ASDisplayNode+Beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ typedef struct {

@interface ASDisplayNode (Beta)

/**
* ASTableView and ASCollectionView now throw exceptions on invalid updates
* like their UIKit counterparts. If YES, these classes will log messages
* on invalid updates rather than throwing exceptions.
*
* Note that even if AsyncDisplayKit's exception is suppressed, the app may still crash
* as it proceeds with an invalid update.
*
* This property defaults to NO. It will be removed in a future release.
*/
+ (BOOL)suppressesInvalidCollectionUpdateExceptions AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Collection update exceptions are thrown if assertions are enabled.");
+ (void)setSuppressesInvalidCollectionUpdateExceptions:(BOOL)suppresses;

/**
* @abstract Recursively ensures node and all subnodes are displayed.
* @see Full documentation in ASDisplayNode+FrameworkPrivate.h
Expand Down
11 changes: 11 additions & 0 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ @implementation ASDisplayNode

@synthesize threadSafeBounds = _threadSafeBounds;

static std::atomic_bool suppressesInvalidCollectionUpdateExceptions = ATOMIC_VAR_INIT(NO);
static std::atomic_bool storesUnflattenedLayouts = ATOMIC_VAR_INIT(NO);

BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector)
Expand Down Expand Up @@ -3792,6 +3793,16 @@ - (ASLayout *)unflattenedCalculatedLayout
return _unflattenedLayout;
}

+ (void)setSuppressesInvalidCollectionUpdateExceptions:(BOOL)suppresses
{
suppressesInvalidCollectionUpdateExceptions.store(suppresses);
}

+ (BOOL)suppressesInvalidCollectionUpdateExceptions
{
return suppressesInvalidCollectionUpdateExceptions.load();
}

- (NSString *)displayNodeRecursiveDescription
{
return [self _recursiveDescriptionHelperWithIndent:@""];
Expand Down
14 changes: 11 additions & 3 deletions Source/Private/_ASHierarchyChangeSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@
#import <AsyncDisplayKit/ASDataController.h>
#import <AsyncDisplayKit/ASBaseDefines.h>

// If assertions are enabled, throw. Otherwise log.
// If assertions are enabled and they haven't forced us to suppress the exception,
// then throw, otherwise log.
#if ASDISPLAYNODE_ASSERTIONS_ENABLED
#define ASFailUpdateValidation(...)\
NSLog(__VA_ARGS__);\
[NSException raise:ASCollectionInvalidUpdateException format:__VA_ARGS__];
_Pragma("clang diagnostic push")\
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")\
if ([ASDisplayNode suppressesInvalidCollectionUpdateExceptions]) {\
NSLog(__VA_ARGS__);\
} else {\
NSLog(__VA_ARGS__);\
[NSException raise:ASCollectionInvalidUpdateException format:__VA_ARGS__];\
}\
_Pragma("clang diagnostic pop")
#else
#define ASFailUpdateValidation(...) NSLog(__VA_ARGS__);
#endif
Expand Down

0 comments on commit 8b70abd

Please sign in to comment.