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

Commit

Permalink
Add support for setting non-fatal error block
Browse files Browse the repository at this point in the history
  • Loading branch information
rocir committed Feb 6, 2017
1 parent e4c9878 commit 888225c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions AsyncDisplayKit/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ typedef void (^ASDisplayNodeContextModifier)(CGContextRef context);
*/
typedef ASLayoutSpec * _Nonnull(^ASLayoutSpecBlock)(__kindof ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize);

/**
* AsyncDisplayKit non-faltal error block. This block can be used for handling non-fatal errors. Useful for reporting
* errors that happens in production.
*/
typedef void (^ASDisplayNodeNonFatalErrorBlock)(__kindof NSError * _Nonnull error);

/**
* Interface state is available on ASDisplayNode and ASViewController, and
* allows checking whether a node is in an interface situation where it is prudent to trigger certain
Expand Down Expand Up @@ -252,6 +258,15 @@ extern NSInteger const ASDefaultDrawingPriority;
*/
@property (readonly) ASInterfaceState interfaceState;

/**
* @abstract Class property that allows to set a block that can be called on non-fatal errors. This
* property can be useful for cases when Async Display Kit can recover from an anormal behavior, but
* still gives the opportunity to use a reporting mechanism to catch occurrences in production.
*
* @warning This method is not thread-safe.
*/
@property (nonatomic, class, copy) ASDisplayNodeNonFatalErrorBlock nonFatalErrorBlock;


/** @name Managing dimensions */

Expand Down
16 changes: 16 additions & 0 deletions AsyncDisplayKit/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
#define TIME_SCOPED(outVar)
#endif

static ASDisplayNodeNonFatalErrorBlock _nonFatalErrorBlock = nil;

// Forward declare CALayerDelegate protocol as the iOS 10 SDK moves CALayerDelegate from a formal delegate to a protocol.
// We have to forward declare the protocol as this place otherwise it will not compile compiling with an Base SDK < iOS 10
@protocol CALayerDelegate;
Expand Down Expand Up @@ -2259,6 +2261,20 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode
return (id)kCFNull;
}

#pragma mark - Error Handling

+ (void)setNonFatalErrorBlock:(ASDisplayNodeNonFatalErrorBlock)nonFatalErrorBlock
{
if (_nonFatalErrorBlock != nonFatalErrorBlock) {
_nonFatalErrorBlock = [nonFatalErrorBlock copy];
}
}

+ (ASDisplayNodeNonFatalErrorBlock)nonFatalErrorBlock
{
return _nonFatalErrorBlock;
}

#pragma mark - Converting to and from the Node's Coordinate System

- (CATransform3D)_transformToAncestor:(ASDisplayNode *)ancestor
Expand Down

0 comments on commit 888225c

Please sign in to comment.