mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-01 10:23:15 +00:00
[ASNodeController+Beta] Provide an option to allow nodes to own their controllers. (#61)
* [ASNodeController+Beta] Provide an option to allow nodes to own their controllers. We should certainly remove this before moving ASNodeController out of Beta. However, I think it will require at least ASCollectionNode to be able to retain its top level set of node controllers. Without this facility built in, it's very difficult for apps supporting both UIKit and ASDK to manually manage the controllers and keep them in sync with perfect timing. * [ASNodeController] Fix one of the #if's.
This commit is contained in:
parent
4d5e3ce81e
commit
71d5b3205d
@ -18,10 +18,18 @@
|
||||
#import <AsyncDisplayKit/ASDisplayNode.h>
|
||||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h> // for ASInterfaceState protocol
|
||||
|
||||
// Until an ASNodeController can be provided in place of an ASCellNode, some apps may prefer to have
|
||||
// nodes keep their controllers alive (and a weak reference from controller to node)
|
||||
#define INVERT_NODE_CONTROLLER_OWNERSHIP 0
|
||||
|
||||
/* ASNodeController is currently beta and open to change in the future */
|
||||
@interface ASNodeController<__covariant DisplayNodeType : ASDisplayNode *> : NSObject <ASInterfaceStateDelegate>
|
||||
|
||||
#if INVERT_NODE_CONTROLLER_OWNERSHIP
|
||||
@property (nonatomic, weak) DisplayNodeType node;
|
||||
#else
|
||||
@property (nonatomic, strong) DisplayNodeType node;
|
||||
#endif
|
||||
|
||||
- (void)loadNode;
|
||||
|
||||
|
@ -16,9 +16,30 @@
|
||||
//
|
||||
|
||||
#import "ASNodeController+Beta.h"
|
||||
|
||||
#import "ASDisplayNode+FrameworkPrivate.h"
|
||||
|
||||
#if INVERT_NODE_CONTROLLER_OWNERSHIP
|
||||
|
||||
@interface ASDisplayNode (ASNodeController)
|
||||
@property (nonatomic, strong) ASNodeController *asdkNodeController;
|
||||
@end
|
||||
|
||||
@implementation ASDisplayNode (ASNodeController)
|
||||
|
||||
- (ASNodeController *)asdkNodeController
|
||||
{
|
||||
return objc_getAssociatedObject(self, @selector(asdkNodeController));
|
||||
}
|
||||
|
||||
- (void)setAsdkNodeController:(ASNodeController *)asdkNodeController
|
||||
{
|
||||
objc_setAssociatedObject(self, @selector(asdkNodeController), asdkNodeController, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
@implementation ASNodeController
|
||||
|
||||
@synthesize node = _node;
|
||||
@ -49,6 +70,9 @@
|
||||
{
|
||||
_node = node;
|
||||
_node.interfaceStateDelegate = self;
|
||||
#if INVERT_NODE_CONTROLLER_OWNERSHIP
|
||||
_node.asdkNodeController = self;
|
||||
#endif
|
||||
}
|
||||
|
||||
// subclass overrides
|
||||
|
Loading…
x
Reference in New Issue
Block a user