Swiftgram/Source/ASNodeController+Beta.mm
Max Wang 69ab24bc00 Make interface state delegate non optional (#1112)
* fix SIMULATE_WEB_RESPONSE not imported #449

* Fix to make rangeMode update in right time

* remove uncessary assert

* Fix collection cell editing bug for iOS 9 & 10

* Revert "Fix collection cell editing bug for iOS 9 & 10"

This reverts commit 06e18a10596622ff8a68835c95a23986d7bf61ea.

* Make interface state delegate protocol non-optional.

* add change log

* add missing removal

* add required method to ASNodeController

* fix indentation

* Update CHANGELOG.md
2018-09-12 09:48:39 -07:00

94 lines
2.3 KiB
Plaintext

//
// ASNodeController+Beta.mm
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// 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>
#define _node (_shouldInvertStrongReference ? _weakNode : _strongNode)
@implementation ASNodeController
{
ASDisplayNode *_strongNode;
__weak ASDisplayNode *_weakNode;
}
- (void)loadNode
{
self.node = [[ASDisplayNode alloc] init];
}
- (ASDisplayNode *)node
{
if (_node == nil) {
[self loadNode];
}
return _node;
}
- (void)setupReferencesWithNode:(ASDisplayNode *)node
{
if (_shouldInvertStrongReference) {
// The node should own the controller; weak reference from controller to node.
_weakNode = node;
_strongNode = nil;
} else {
// The controller should own the node; weak reference from node to controller.
_strongNode = node;
_weakNode = nil;
}
[node __setNodeController:self];
[node addInterfaceStateDelegate:self];
}
- (void)setNode:(ASDisplayNode *)node
{
[self setupReferencesWithNode:node];
}
- (void)setShouldInvertStrongReference:(BOOL)shouldInvertStrongReference
{
if (_shouldInvertStrongReference != shouldInvertStrongReference) {
// Because the BOOL controls which ivar we access, get the node before toggling.
ASDisplayNode *node = _node;
_shouldInvertStrongReference = shouldInvertStrongReference;
[self setupReferencesWithNode:node];
}
}
// subclass overrides
- (void)nodeDidLoad {}
- (void)nodeDidLayout {}
- (void)didEnterVisibleState {}
- (void)didExitVisibleState {}
- (void)didEnterDisplayState {}
- (void)didExitDisplayState {}
- (void)didEnterPreloadState {}
- (void)didExitPreloadState {}
- (void)interfaceStateDidChange:(ASInterfaceState)newState
fromState:(ASInterfaceState)oldState {}
- (void)hierarchyDisplayDidFinish {}
@end
@implementation ASDisplayNode (ASNodeController)
- (ASNodeController *)nodeController {
return _weakNodeController ?: _strongNodeController;
}
@end