From 0c8712aa81fa7b2b9b0a956d47cb44850abbd1da Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Sat, 9 Jul 2016 20:41:03 -0700 Subject: [PATCH] Continuing work on layout examples --- AsyncDisplayKit/ASTextNode.mm | 1 + AsyncDisplayKit/ASViewController.mm | 6 ++++ .../Sample.xcodeproj/project.pbxproj | 33 +++++-------------- .../Sample/Base.lproj/LaunchScreen.storyboard | 27 --------------- .../Sample/LayoutExamplesViewController.m | 21 ++++++++---- .../Sample/OverviewComponentsViewController.h | 4 +-- .../Sample/OverviewComponentsViewController.m | 26 +++++++-------- 7 files changed, 46 insertions(+), 72 deletions(-) delete mode 100644 examples/AsyncDisplayKitOverview/Sample/Base.lproj/LaunchScreen.storyboard diff --git a/AsyncDisplayKit/ASTextNode.mm b/AsyncDisplayKit/ASTextNode.mm index e77b1b2b..5cf4c167 100644 --- a/AsyncDisplayKit/ASTextNode.mm +++ b/AsyncDisplayKit/ASTextNode.mm @@ -346,6 +346,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ]; // just update the size of the NSTextContainer that is owned by the renderer's internal context object. [self _renderer].constrainedSize = _constrainedSize; + // TODO: Consider if this should be gated to occur only if _constrainedSize actually changes. [self setNeedsDisplay]; CGSize size = [self _renderer].size; diff --git a/AsyncDisplayKit/ASViewController.mm b/AsyncDisplayKit/ASViewController.mm index a9923ef9..227c1d2a 100644 --- a/AsyncDisplayKit/ASViewController.mm +++ b/AsyncDisplayKit/ASViewController.mm @@ -43,6 +43,12 @@ return [self initWithNode:[[ASDisplayNode alloc] init]]; } +- (instancetype)init +{ + ASDisplayNodeAssert(NO, @"ASViewController requires using -initWithNode:"); + return [self initWithNode:[[ASDisplayNode alloc] init]]; +} + - (instancetype)initWithNode:(ASDisplayNode *)node { if (!(self = [super initWithNibName:nil bundle:nil])) { diff --git a/examples/AsyncDisplayKitOverview/Sample.xcodeproj/project.pbxproj b/examples/AsyncDisplayKitOverview/Sample.xcodeproj/project.pbxproj index 357c36b8..4e9d14f0 100644 --- a/examples/AsyncDisplayKitOverview/Sample.xcodeproj/project.pbxproj +++ b/examples/AsyncDisplayKitOverview/Sample.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ 697216351CCD8FB300122312 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 697216341CCD8FB300122312 /* main.m */; }; 697216381CCD8FB300122312 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 697216371CCD8FB300122312 /* AppDelegate.m */; }; 697216401CCD8FB300122312 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6972163F1CCD8FB300122312 /* Assets.xcassets */; }; - 697216431CCD8FB300122312 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 697216411CCD8FB300122312 /* LaunchScreen.storyboard */; }; 6972164E1CCD938A00122312 /* OverviewComponentsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6972164B1CCD938A00122312 /* OverviewComponentsViewController.m */; }; 6972164F1CCD938A00122312 /* OverviewDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6972164D1CCD938A00122312 /* OverviewDetailViewController.m */; }; 697216571CCD939000122312 /* OverviewASCollectionNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 697216521CCD939000122312 /* OverviewASCollectionNode.m */; }; @@ -26,7 +25,6 @@ 697216361CCD8FB300122312 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 697216371CCD8FB300122312 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 6972163F1CCD8FB300122312 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 697216421CCD8FB300122312 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 697216441CCD8FB300122312 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 6972164A1CCD938A00122312 /* OverviewComponentsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OverviewComponentsViewController.h; sourceTree = ""; }; 6972164B1CCD938A00122312 /* OverviewComponentsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OverviewComponentsViewController.m; sourceTree = ""; }; @@ -96,7 +94,6 @@ 80817AC31D309A4800E181DF /* LayoutExamplesViewController.h */, 80817AC41D309A4800E181DF /* LayoutExamplesViewController.m */, 6972163F1CCD8FB300122312 /* Assets.xcassets */, - 697216411CCD8FB300122312 /* LaunchScreen.storyboard */, 697216441CCD8FB300122312 /* Info.plist */, 697216331CCD8FB300122312 /* Supporting Files */, ); @@ -140,12 +137,12 @@ isa = PBXNativeTarget; buildConfigurationList = 697216471CCD8FB300122312 /* Build configuration list for PBXNativeTarget "Sample" */; buildPhases = ( - 78A0D09A94A74B3737920EA7 /* 📦 Check Pods Manifest.lock */, + 78A0D09A94A74B3737920EA7 /* [CP] Check Pods Manifest.lock */, 6972162C1CCD8FB300122312 /* Sources */, 6972162D1CCD8FB300122312 /* Frameworks */, 6972162E1CCD8FB300122312 /* Resources */, - 267658CA53A0F4A2D24A8438 /* 📦 Embed Pods Frameworks */, - 84F93825AFB1CA7FBB116BA4 /* 📦 Copy Pods Resources */, + 267658CA53A0F4A2D24A8438 /* [CP] Embed Pods Frameworks */, + 84F93825AFB1CA7FBB116BA4 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -193,7 +190,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 697216431CCD8FB300122312 /* LaunchScreen.storyboard in Resources */, 697216401CCD8FB300122312 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -201,14 +197,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 267658CA53A0F4A2D24A8438 /* 📦 Embed Pods Frameworks */ = { + 267658CA53A0F4A2D24A8438 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "📦 Embed Pods Frameworks"; + name = "[CP] Embed Pods Frameworks"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -216,14 +212,14 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Sample/Pods-Sample-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - 78A0D09A94A74B3737920EA7 /* 📦 Check Pods Manifest.lock */ = { + 78A0D09A94A74B3737920EA7 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "📦 Check Pods Manifest.lock"; + name = "[CP] Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -231,14 +227,14 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - 84F93825AFB1CA7FBB116BA4 /* 📦 Copy Pods Resources */ = { + 84F93825AFB1CA7FBB116BA4 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "📦 Copy Pods Resources"; + name = "[CP] Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -266,17 +262,6 @@ }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXVariantGroup section */ - 697216411CCD8FB300122312 /* LaunchScreen.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 697216421CCD8FB300122312 /* Base */, - ); - name = LaunchScreen.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - /* Begin XCBuildConfiguration section */ 697216451CCD8FB300122312 /* Debug */ = { isa = XCBuildConfiguration; diff --git a/examples/AsyncDisplayKitOverview/Sample/Base.lproj/LaunchScreen.storyboard b/examples/AsyncDisplayKitOverview/Sample/Base.lproj/LaunchScreen.storyboard deleted file mode 100644 index ebf48f60..00000000 --- a/examples/AsyncDisplayKitOverview/Sample/Base.lproj/LaunchScreen.storyboard +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/AsyncDisplayKitOverview/Sample/LayoutExamplesViewController.m b/examples/AsyncDisplayKitOverview/Sample/LayoutExamplesViewController.m index bd0b7bce..3e7d6ee8 100644 --- a/examples/AsyncDisplayKitOverview/Sample/LayoutExamplesViewController.m +++ b/examples/AsyncDisplayKitOverview/Sample/LayoutExamplesViewController.m @@ -60,7 +60,7 @@ cellNode.backgroundColor = [UIColor lightGrayColor]; ASTextNode *textNodeOne = [[ASTextNode alloc] init]; - textNodeOne.attributedText = [[NSAttributedString alloc] initWithString:@"firstname lastname"]; + textNodeOne.attributedText = [[NSAttributedString alloc] initWithString:@"first"]; ASTextNode *textNodeTwo = [[ASTextNode alloc] init]; @@ -75,14 +75,13 @@ ASLayoutSpecBlock layoutSpecBlock = nil; // Picture with text overlay - if (indexPath.row == 0) { + if (indexPath.row == 1) { [cellNode addSubnode:textNodeOne]; [cellNode addSubnode:textNodeTwo]; [cellNode addSubnode:textNodeThree]; [cellNode addSubnode:imageNode]; imageNode.preferredFrameSize = CGSizeMake(50, 50); - imageNode.cornerRadius = 25; layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) { ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec verticalStackLayoutSpec]; @@ -99,9 +98,19 @@ return insetSpec; }; - } else if (indexPath.row == 1) { - - + } else if (indexPath.row == 0) { + [cellNode addSubnode:textNodeOne]; + [cellNode addSubnode:imageNode]; + + layoutSpecBlock = ^ASLayoutSpec *(ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) { + + imageNode.preferredFrameSize = CGSizeMake(50, 50); + ASInsetLayoutSpec *textInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(6, 6, 6, 6) + child:textNodeOne]; + + ASOverlayLayoutSpec *textOverlay = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:imageNode overlay:textNodeOne]; + return textOverlay; + }; } cellNode.layoutSpecBlock = layoutSpecBlock; diff --git a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.h b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.h index 880cf78a..0450b76a 100644 --- a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.h +++ b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.h @@ -18,7 +18,7 @@ // #import - +#import @protocol ASLayoutSpecListEntry @@ -27,7 +27,7 @@ @end -@interface OverviewComponentsViewController : UIViewController +@interface OverviewComponentsViewController : ASViewController @end diff --git a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m index 60aad5c0..2a12e25c 100644 --- a/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m +++ b/examples/AsyncDisplayKitOverview/Sample/OverviewComponentsViewController.m @@ -103,14 +103,25 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr #pragma mark - UIViewController +- (instancetype)init +{ + ASTableNode *tableNode = [ASTableNode new]; + + if (self = [super initWithNode:tableNode]) { + self.tableNode = tableNode; + tableNode.delegate = (id)self; + tableNode.dataSource = (id)self; + } + return self; +} + - (void)viewDidLoad { [super viewDidLoad]; self.title = @"AsyncDisplayKit"; - + [self setupData]; - [self setupTableNode]; } - (void)viewWillAppear:(BOOL)animated @@ -127,7 +138,6 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr { OverviewDisplayNodeWithSizeBlock *parentNode = nil; ASDisplayNode *childNode = nil; - // Setup Nodes Container // --------------------------------------------------------------------------------------------------------- @@ -463,16 +473,6 @@ typedef ASLayoutSpec *(^OverviewDisplayNodeSizeThatFitsBlock)(ASSizeRange constr self.data = mutableData; } -- (void)setupTableNode -{ - _tableNode = [ASTableNode new]; - _tableNode.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _tableNode.frame = self.view.bounds; - _tableNode.delegate = (id)self; - _tableNode.dataSource = (id)self; - [self.view addSubnode:_tableNode]; -} - #pragma mark - Parent / Child Helper - (OverviewDisplayNodeWithSizeBlock *)parentNodeWithChild:(ASDisplayNode *)child