Let ASNodeController conform to NSLocking (#1179)

This commit is contained in:
Michael Schneider 2018-10-21 11:49:02 -07:00 committed by appleguy
parent 776e475558
commit cb154f1471
3 changed files with 25 additions and 3 deletions

View File

@ -61,6 +61,7 @@
- Fix mismatch in UIAccessibilityAction selector method [Michael Schneider](https://github.com/maicki) [#1169](https://github.com/TextureGroup/Texture/pull/1169)
- [ASDisplayNode] Expose default Texture-set accessibility values as properties. [Jia Wern Lim](https://github.com/jiawernlim) [#1170](https://github.com/TextureGroup/Texture/pull/1170)
- ASTableNode init method match checks from ASCollectionNode [Michael Schneider](https://github.com/maicki) [#1171]
- Add NSLocking conformance to ASNodeController [Michael Schneider](https://github.com/maicki)[#1179] (https://github.com/TextureGroup/Texture/pull/1179)
## 2.7
- Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)

View File

@ -11,7 +11,8 @@
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h> // for ASInterfaceState protocol
/* ASNodeController is currently beta and open to change in the future */
@interface ASNodeController<__covariant DisplayNodeType : ASDisplayNode *> : NSObject <ASInterfaceStateDelegate>
@interface ASNodeController<__covariant DisplayNodeType : ASDisplayNode *>
: NSObject <ASInterfaceStateDelegate, NSLocking>
@property (nonatomic, strong /* may be weak! */) DisplayNodeType node;

View File

@ -7,10 +7,11 @@
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <AsyncDisplayKit/ASInternalHelpers.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h>
#import <AsyncDisplayKit/ASNodeController+Beta.h>
#import <AsyncDisplayKit/ASThread.h>
#import <AsyncDisplayKit/ASWeakProxy.h>
#define _node (_shouldInvertStrongReference ? _weakNode : _strongNode)
@ -18,15 +19,18 @@
{
ASDisplayNode *_strongNode;
__weak ASDisplayNode *_weakNode;
ASDN::RecursiveMutex __instanceLock__;
}
- (void)loadNode
{
ASLockScopeSelf();
self.node = [[ASDisplayNode alloc] init];
}
- (ASDisplayNode *)node
{
ASLockScopeSelf();
if (_node == nil) {
[self loadNode];
}
@ -35,6 +39,7 @@
- (void)setupReferencesWithNode:(ASDisplayNode *)node
{
ASLockScopeSelf();
if (_shouldInvertStrongReference) {
// The node should own the controller; weak reference from controller to node.
_weakNode = node;
@ -51,11 +56,13 @@
- (void)setNode:(ASDisplayNode *)node
{
ASLockScopeSelf();
[self setupReferencesWithNode:node];
}
- (void)setShouldInvertStrongReference:(BOOL)shouldInvertStrongReference
{
ASLockScopeSelf();
if (_shouldInvertStrongReference != shouldInvertStrongReference) {
// Because the BOOL controls which ivar we access, get the node before toggling.
ASDisplayNode *node = _node;
@ -82,11 +89,24 @@
- (void)hierarchyDisplayDidFinish {}
#pragma mark NSLocking
- (void)lock
{
__instanceLock__.lock();
}
- (void)unlock
{
__instanceLock__.unlock();
}
@end
@implementation ASDisplayNode (ASNodeController)
- (ASNodeController *)nodeController {
- (ASNodeController *)nodeController
{
return _weakNodeController ?: _strongNodeController;
}