From 299df0aa8cddb04a68373e902e38f7c9cafe10e4 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Mon, 15 May 2017 09:48:45 -0700 Subject: [PATCH] [Examples] Fix a couple of examples due to API changes recently #trivial (#267) * Fix ASDKGram example * Fix some more examples * Convert Swift example to 3.0 * Fix VerticalWithinHorizontalScrolling * Fix some headers * Fix some more API changes * Remove semicolons --- examples/ASDKgram/Sample/ImageURLModel.h | 12 ++-- examples/ASDKgram/Sample/ImageURLModel.m | 20 +++--- .../ASDKgram/Sample/PhotoFeedNodeController.m | 30 ++++----- .../Sample/ViewController.m | 14 ++-- .../Sample/ViewController.swift | 24 ++----- .../Sample/MosaicCollectionLayoutDelegate.m | 2 +- .../Sample/ViewController.m | 3 +- .../Sample/RandomCoreGraphicsNode.h | 12 ++-- .../Sample/RandomCoreGraphicsNode.m | 15 ++--- .../Swift/Sample.xcodeproj/project.pbxproj | 6 +- examples/Swift/Sample/AppDelegate.swift | 22 +++---- .../Swift/Sample/TailLoadingCellNode.swift | 32 +++++----- examples/Swift/Sample/ViewController.swift | 64 +++++++++---------- .../Sample/RandomCoreGraphicsNode.h | 14 ++-- .../Sample/RandomCoreGraphicsNode.m | 32 ++++++---- 15 files changed, 149 insertions(+), 153 deletions(-) diff --git a/examples/ASDKgram/Sample/ImageURLModel.h b/examples/ASDKgram/Sample/ImageURLModel.h index 9c167fed2f..88381fde8f 100644 --- a/examples/ASDKgram/Sample/ImageURLModel.h +++ b/examples/ASDKgram/Sample/ImageURLModel.h @@ -9,12 +9,12 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // @interface ImageURLModel : NSObject diff --git a/examples/ASDKgram/Sample/ImageURLModel.m b/examples/ASDKgram/Sample/ImageURLModel.m index 776ee31777..78c4b43714 100644 --- a/examples/ASDKgram/Sample/ImageURLModel.m +++ b/examples/ASDKgram/Sample/ImageURLModel.m @@ -9,12 +9,12 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // #import "ImageURLModel.h" @@ -25,12 +25,12 @@ { BOOL squareImageRequested = (size.width == size.height) ? YES : NO; - NSUInteger imageParameterID; if (squareImageRequested) { - imageParameterID = [self imageParameterForSquareCroppedSize:size]; + NSUInteger imageParameterID = [self imageParameterForSquareCroppedSize:size]; + return [NSString stringWithFormat:@"&image_size=%lu", (long)imageParameterID]; + } else { + return @""; } - - return [NSString stringWithFormat:@"&image_size=%lu", (long)imageParameterID]; } // 500px standard cropped image sizes diff --git a/examples/ASDKgram/Sample/PhotoFeedNodeController.m b/examples/ASDKgram/Sample/PhotoFeedNodeController.m index 1e22925e6d..7396094e73 100644 --- a/examples/ASDKgram/Sample/PhotoFeedNodeController.m +++ b/examples/ASDKgram/Sample/PhotoFeedNodeController.m @@ -9,12 +9,12 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // #import "PhotoFeedNodeController.h" @@ -27,12 +27,10 @@ #define AUTO_TAIL_LOADING_NUM_SCREENFULS 2.5 @interface PhotoFeedNodeController () +@property (nonatomic, strong) ASTableNode *tableNode; @end @implementation PhotoFeedNodeController -{ - ASTableNode *_tableNode; -} #pragma mark - Lifecycle @@ -42,15 +40,15 @@ { _tableNode = [[ASTableNode alloc] init]; self = [super initWithNode:_tableNode]; - + if (self) { self.navigationItem.title = @"ASDK"; [self.navigationController setNavigationBarHidden:YES]; - + _tableNode.dataSource = self; _tableNode.delegate = self; } - + return self; } @@ -59,14 +57,14 @@ - (void)loadView { [super loadView]; - - _tableNode.view.leadingScreensForBatching = AUTO_TAIL_LOADING_NUM_SCREENFULS; // overriding default of 2.0 + + self.tableNode.leadingScreensForBatching = AUTO_TAIL_LOADING_NUM_SCREENFULS; // overriding default of 2.0 } - (void)loadPageWithContext:(ASBatchContext *)context { [self.photoFeed requestPageWithCompletionBlock:^(NSArray *newPhotos){ - + [self insertNewRows:newPhotos]; [self requestCommentsForPhotos:newPhotos]; if (context) { @@ -107,7 +105,7 @@ PhotoCellNode *cellNode = [[PhotoCellNode alloc] initWithPhotoObject:photoModel]; return cellNode; }; - + return ASCellNodeBlock; } diff --git a/examples/CatDealsCollectionView/Sample/ViewController.m b/examples/CatDealsCollectionView/Sample/ViewController.m index 6d693f690c..02fb5de8d8 100644 --- a/examples/CatDealsCollectionView/Sample/ViewController.m +++ b/examples/CatDealsCollectionView/Sample/ViewController.m @@ -7,12 +7,12 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // #import "ViewController.h" @@ -84,7 +84,7 @@ static const CGFloat kHorizontalSectionPadding = 10.0f; [super viewDidLoad]; // set any collectionView properties here (once the node's backing view is loaded) - _collectionNode.view.leadingScreensForBatching = 2; + _collectionNode.leadingScreensForBatching = 2; [self fetchMoreCatsWithCompletion:nil]; } diff --git a/examples/CustomCollectionView-Swift/Sample/ViewController.swift b/examples/CustomCollectionView-Swift/Sample/ViewController.swift index b6954c9b99..a4ee85df93 100644 --- a/examples/CustomCollectionView-Swift/Sample/ViewController.swift +++ b/examples/CustomCollectionView-Swift/Sample/ViewController.swift @@ -4,8 +4,9 @@ // // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. // This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. +// LICENSE file in the /ASDK-Licenses directory of this source tree. An additional +// grant of patent rights can be found in the PATENTS file in the same directory. +// // Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, // Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,12 +14,6 @@ // // http://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// import UIKit import AsyncDisplayKit @@ -49,9 +44,10 @@ class ViewController: ASViewController, MosaicCollectionViewLa } } - _collectionNode.dataSource = self; - _collectionNode.delegate = self; _collectionNode.backgroundColor = UIColor.white + _collectionNode.dataSource = self + _collectionNode.delegate = self + _collectionNode.layoutInspector = _layoutInspector _collectionNode.registerSupplementaryNode(ofKind: UICollectionElementKindSectionHeader) } @@ -59,14 +55,8 @@ class ViewController: ASViewController, MosaicCollectionViewLa fatalError("init(coder:) has not been implemented") } - deinit { - _collectionNode.dataSource = nil; - _collectionNode.delegate = nil; - } - override func viewDidLoad() { super.viewDidLoad() - _collectionNode.view.layoutInspector = _layoutInspector _collectionNode.view.isScrollEnabled = true } @@ -84,7 +74,7 @@ class ViewController: ASViewController, MosaicCollectionViewLa let textInsets = UIEdgeInsets(top: 11, left: 0, bottom: 11, right: 0) let textCellNode = ASTextCellNode(attributes: textAttributes as! [AnyHashable : Any], insets: textInsets) textCellNode.text = String(format: "Section %zd", indexPath.section + 1) - return textCellNode; + return textCellNode } diff --git a/examples/CustomCollectionView/Sample/MosaicCollectionLayoutDelegate.m b/examples/CustomCollectionView/Sample/MosaicCollectionLayoutDelegate.m index 211ad7cf35..4bbd53e6a8 100644 --- a/examples/CustomCollectionView/Sample/MosaicCollectionLayoutDelegate.m +++ b/examples/CustomCollectionView/Sample/MosaicCollectionLayoutDelegate.m @@ -108,7 +108,7 @@ CGFloat contentHeight = [[[columnHeights lastObject] firstObject] floatValue]; CGSize contentSize = CGSizeMake(layoutWidth, contentHeight); - return [[ASCollectionLayoutState alloc] initWithElements:elements contentSize:contentSize elementToLayoutArrtibutesMap:attrsMap]; + return [[ASCollectionLayoutState alloc] initWithContext:context contentSize:contentSize elementToLayoutAttributesTable:attrsMap]; } - (CGFloat)_widthForSection:(NSUInteger)section withLayoutWidth:(CGFloat)layoutWidth diff --git a/examples/CustomCollectionView/Sample/ViewController.m b/examples/CustomCollectionView/Sample/ViewController.m index fea3793165..65445a557c 100644 --- a/examples/CustomCollectionView/Sample/ViewController.m +++ b/examples/CustomCollectionView/Sample/ViewController.m @@ -47,7 +47,7 @@ static NSUInteger kNumberOfImages = 14; _collectionNode = [[ASCollectionNode alloc] initWithLayoutDelegate:layoutDelegate layoutFacilitator:nil]; _collectionNode.dataSource = self; _collectionNode.delegate = self; - _collectionNode.backgroundColor = [UIColor whiteColor]; + _collectionNode.layoutInspector = self; if (!(self = [super initWithNode:_collectionNode])) return nil; @@ -72,7 +72,6 @@ static NSUInteger kNumberOfImages = 14; { [super viewDidLoad]; - _collectionNode.view.layoutInspector = self; [_collectionNode.view registerClass:[ImageCollectionViewCell class] forCellWithReuseIdentifier:kReuseIdentifier]; } diff --git a/examples/HorizontalWithinVerticalScrolling/Sample/RandomCoreGraphicsNode.h b/examples/HorizontalWithinVerticalScrolling/Sample/RandomCoreGraphicsNode.h index 8785d084ec..19e86e5712 100644 --- a/examples/HorizontalWithinVerticalScrolling/Sample/RandomCoreGraphicsNode.h +++ b/examples/HorizontalWithinVerticalScrolling/Sample/RandomCoreGraphicsNode.h @@ -9,12 +9,12 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // #import diff --git a/examples/HorizontalWithinVerticalScrolling/Sample/RandomCoreGraphicsNode.m b/examples/HorizontalWithinVerticalScrolling/Sample/RandomCoreGraphicsNode.m index 2aa66a97b3..fce6ea56e9 100644 --- a/examples/HorizontalWithinVerticalScrolling/Sample/RandomCoreGraphicsNode.m +++ b/examples/HorizontalWithinVerticalScrolling/Sample/RandomCoreGraphicsNode.m @@ -9,12 +9,12 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // #import "RandomCoreGraphicsNode.h" @@ -46,8 +46,7 @@ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)colors, locations); - CGGradientDrawingOptions drawingOptions; - CGContextDrawLinearGradient(ctx, gradient, CGPointZero, CGPointMake(bounds.size.width, bounds.size.height), drawingOptions); + CGContextDrawLinearGradient(ctx, gradient, CGPointZero, CGPointMake(bounds.size.width, bounds.size.height), 0); CGGradientRelease(gradient); CGColorSpaceRelease(colorSpace); diff --git a/examples/Swift/Sample.xcodeproj/project.pbxproj b/examples/Swift/Sample.xcodeproj/project.pbxproj index 7d5dd724ea..081a5a2d6a 100644 --- a/examples/Swift/Sample.xcodeproj/project.pbxproj +++ b/examples/Swift/Sample.xcodeproj/project.pbxproj @@ -138,7 +138,7 @@ TargetAttributes = { 050E7C6D19D22E19004363C2 = { CreatedOnToolsVersion = 6.0.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0830; }; }; }; @@ -322,7 +322,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.AsyncDisplayKit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -335,7 +335,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.AsyncDisplayKit.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/examples/Swift/Sample/AppDelegate.swift b/examples/Swift/Sample/AppDelegate.swift index 2aaa33f9c6..e560672966 100644 --- a/examples/Swift/Sample/AppDelegate.swift +++ b/examples/Swift/Sample/AppDelegate.swift @@ -4,15 +4,15 @@ // // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. // This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. +// LICENSE file in the /ASDK-Licenses directory of this source tree. An additional +// grant of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // import UIKit @@ -22,9 +22,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - let window = UIWindow(frame: UIScreen.mainScreen().bounds) - window.backgroundColor = UIColor.whiteColor() + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + let window = UIWindow(frame: UIScreen.main.bounds) + window.backgroundColor = UIColor.white window.rootViewController = UINavigationController(rootViewController: ViewController()); window.makeKeyAndVisible() self.window = window diff --git a/examples/Swift/Sample/TailLoadingCellNode.swift b/examples/Swift/Sample/TailLoadingCellNode.swift index b3a0bff6f2..5327dd4456 100644 --- a/examples/Swift/Sample/TailLoadingCellNode.swift +++ b/examples/Swift/Sample/TailLoadingCellNode.swift @@ -6,15 +6,15 @@ // // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. // This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. +// LICENSE file in the /ASDK-Licenses directory of this source tree. An additional +// grant of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // import AsyncDisplayKit @@ -31,20 +31,20 @@ final class TailLoadingCellNode: ASCellNode { text.attributedText = NSAttributedString( string: "Loading…", attributes: [ - NSFontAttributeName: UIFont.systemFontOfSize(12), - NSForegroundColorAttributeName: UIColor.lightGrayColor(), + NSFontAttributeName: UIFont.systemFont(ofSize: 12), + NSForegroundColorAttributeName: UIColor.lightGray, NSKernAttributeName: -0.3 ]) addSubnode(spinner) } - override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec { + override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec { return ASStackLayoutSpec( - direction: .Horizontal, + direction: .horizontal, spacing: 16, - justifyContent: .Center, - alignItems: .Center, + justifyContent: .center, + alignItems: .center, children: [ text, spinner ]) } } @@ -57,11 +57,11 @@ final class SpinnerNode: ASDisplayNode { override init() { super.init() setViewBlock { - UIActivityIndicatorView(activityIndicatorStyle: .Gray) + UIActivityIndicatorView(activityIndicatorStyle: .gray) } // Set spinner node to default size of the activitiy indicator view - self.style.preferredSize = CGSizeMake(20.0, 20.0) + self.style.preferredSize = CGSize(width: 20.0, height: 20.0) } override func didLoad() { diff --git a/examples/Swift/Sample/ViewController.swift b/examples/Swift/Sample/ViewController.swift index eeae970a75..4d1269e6ae 100644 --- a/examples/Swift/Sample/ViewController.swift +++ b/examples/Swift/Sample/ViewController.swift @@ -4,21 +4,21 @@ // // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. // This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. +// LICENSE file in the /ASDK-Licenses directory of this source tree. An additional +// grant of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // import UIKit import AsyncDisplayKit -final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate { +final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate { struct State { var itemCount: Int @@ -27,15 +27,15 @@ final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate } enum Action { - case BeginBatchFetch - case EndBatchFetch(resultCount: Int) + case beginBatchFetch + case endBatchFetch(resultCount: Int) } var tableNode: ASTableNode { return node as! ASTableNode } - private(set) var state: State = .empty + fileprivate(set) var state: State = .empty init() { super.init(node: ASTableNode()) @@ -49,7 +49,7 @@ final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate // MARK: ASTableNode data source and delegate. - func tableNode(tableNode: ASTableNode, nodeForRowAtIndexPath indexPath: NSIndexPath) -> ASCellNode { + func tableNode(_ tableNode: ASTableNode, nodeForRowAt indexPath: IndexPath) -> ASCellNode { // Should read the row count directly from table view but // https://github.com/facebook/AsyncDisplayKit/issues/1159 let rowCount = self.tableNode(tableNode, numberOfRowsInSection: 0) @@ -66,11 +66,11 @@ final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate return node } - func numberOfSectionsInTableNode(tableNode: ASTableNode) -> Int { + func numberOfSections(in tableNode: ASTableNode) -> Int { return 1 } - func tableNode(tableNode: ASTableNode, numberOfRowsInSection section: Int) -> Int { + func tableNode(_ tableNode: ASTableNode, numberOfRowsInSection section: Int) -> Int { var count = state.itemCount if state.fetchingMore { count += 1 @@ -78,17 +78,17 @@ final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate return count } - func tableNode(tableNode: ASTableNode, willBeginBatchFetchWithContext context: ASBatchContext) { + func tableNode(_ tableNode: ASTableNode, willBeginBatchFetchWith context: ASBatchContext) { /// This call will come in on a background thread. Switch to main /// to add our spinner, then fire off our fetch. - dispatch_async(dispatch_get_main_queue()) { + DispatchQueue.main.async { let oldState = self.state - self.state = ViewController.handleAction(.BeginBatchFetch, fromState: oldState) + self.state = ViewController.handleAction(.beginBatchFetch, fromState: oldState) self.renderDiff(oldState) } ViewController.fetchDataWithCompletion { resultCount in - let action = Action.EndBatchFetch(resultCount: resultCount) + let action = Action.endBatchFetch(resultCount: resultCount) let oldState = self.state self.state = ViewController.handleAction(action, fromState: oldState) self.renderDiff(oldState) @@ -96,7 +96,7 @@ final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate } } - private func renderDiff(oldState: State) { + fileprivate func renderDiff(_ oldState: State) { self.tableNode.performBatchUpdates({ @@ -104,9 +104,9 @@ final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate let rowCountChange = state.itemCount - oldState.itemCount if rowCountChange > 0 { let indexPaths = (oldState.itemCount.. Void) { - let time = dispatch_time(DISPATCH_TIME_NOW, Int64(NSTimeInterval(NSEC_PER_SEC) * 1.0)) - dispatch_after(time, dispatch_get_main_queue()) { + fileprivate static func fetchDataWithCompletion(_ completion: @escaping (Int) -> Void) { + let time = DispatchTime.now() + Double(Int64(TimeInterval(NSEC_PER_SEC) * 1.0)) / Double(NSEC_PER_SEC) + DispatchQueue.main.asyncAfter(deadline: time) { let resultCount = Int(arc4random_uniform(20)) completion(resultCount) } } - private static func handleAction(action: Action, fromState state: State) -> State { + fileprivate static func handleAction(_ action: Action, fromState state: State) -> State { var state = state switch action { - case .BeginBatchFetch: + case .beginBatchFetch: state.fetchingMore = true - case let .EndBatchFetch(resultCount): + case let .endBatchFetch(resultCount): state.itemCount += resultCount state.fetchingMore = false } diff --git a/examples/VerticalWithinHorizontalScrolling/Sample/RandomCoreGraphicsNode.h b/examples/VerticalWithinHorizontalScrolling/Sample/RandomCoreGraphicsNode.h index 6eaed935c8..e2b21128f2 100644 --- a/examples/VerticalWithinHorizontalScrolling/Sample/RandomCoreGraphicsNode.h +++ b/examples/VerticalWithinHorizontalScrolling/Sample/RandomCoreGraphicsNode.h @@ -9,12 +9,12 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // #import @@ -24,6 +24,6 @@ ASTextNode *_indexPathTextNode; } -@property (nonatomic) NSIndexPath *indexPath; +@property NSIndexPath *indexPath; @end diff --git a/examples/VerticalWithinHorizontalScrolling/Sample/RandomCoreGraphicsNode.m b/examples/VerticalWithinHorizontalScrolling/Sample/RandomCoreGraphicsNode.m index 16d40df7aa..3b9e09d009 100644 --- a/examples/VerticalWithinHorizontalScrolling/Sample/RandomCoreGraphicsNode.m +++ b/examples/VerticalWithinHorizontalScrolling/Sample/RandomCoreGraphicsNode.m @@ -9,12 +9,12 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Modifications to this file made after 4/13/2017 are: Copyright (c) 2017-present, +// Pinterest, Inc. Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 // #import "RandomCoreGraphicsNode.h" @@ -22,7 +22,7 @@ @implementation RandomCoreGraphicsNode -@synthesize indexPath=_indexPath; +@synthesize indexPath = _indexPath; + (UIColor *)randomColor { @@ -48,8 +48,7 @@ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)colors, locations); - CGGradientDrawingOptions drawingOptions; - CGContextDrawLinearGradient(ctx, gradient, CGPointZero, CGPointMake(bounds.size.width, bounds.size.height), drawingOptions); + CGContextDrawLinearGradient(ctx, gradient, CGPointZero, CGPointMake(bounds.size.width, bounds.size.height), 0); CGGradientRelease(gradient); CGColorSpaceRelease(colorSpace); @@ -69,8 +68,19 @@ - (void)setIndexPath:(NSIndexPath *)indexPath { - _indexPath = indexPath; - _indexPathTextNode.attributedText = [[NSAttributedString alloc] initWithString:[indexPath description] attributes:nil]; + @synchronized (self) { + _indexPath = indexPath; + _indexPathTextNode.attributedText = [[NSAttributedString alloc] initWithString:[indexPath description] attributes:nil]; + } +} + +- (NSIndexPath *)indexPath +{ + NSIndexPath *indexPath = nil; + @synchronized (self) { + indexPath = _indexPath; + } + return indexPath; } - (void)layout