mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
[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
This commit is contained in:
committed by
GitHub
parent
9d84b9e635
commit
299df0aa8c
@@ -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
|
||||
|
||||
@@ -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 @"";
|
||||
}
|
||||
}
|
||||
|
||||
// 500px standard cropped image sizes
|
||||
|
||||
@@ -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 () <ASTableDelegate, ASTableDataSource>
|
||||
@property (nonatomic, strong) ASTableNode *tableNode;
|
||||
@end
|
||||
|
||||
@implementation PhotoFeedNodeController
|
||||
{
|
||||
ASTableNode *_tableNode;
|
||||
}
|
||||
|
||||
#pragma mark - Lifecycle
|
||||
|
||||
@@ -60,7 +58,7 @@
|
||||
{
|
||||
[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
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ASCollectionNode>, 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<ASCollectionNode>, 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<ASCollectionNode>, 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <AsyncDisplayKit/AsyncDisplayKit.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 "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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<ASDisplayNode>, 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..<state.itemCount).map { index in
|
||||
NSIndexPath(forRow: index, inSection: 0)
|
||||
IndexPath(row: index, section: 0)
|
||||
}
|
||||
tableNode.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .None)
|
||||
tableNode.insertRows(at: indexPaths, with: .none)
|
||||
} else if rowCountChange < 0 {
|
||||
assertionFailure("Deleting rows is not implemented. YAGNI.")
|
||||
}
|
||||
@@ -115,12 +115,12 @@ final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate
|
||||
if state.fetchingMore != oldState.fetchingMore {
|
||||
if state.fetchingMore {
|
||||
// Add spinner.
|
||||
let spinnerIndexPath = NSIndexPath(forRow: state.itemCount, inSection: 0)
|
||||
tableNode.insertRowsAtIndexPaths([ spinnerIndexPath ], withRowAnimation: .None)
|
||||
let spinnerIndexPath = IndexPath(row: state.itemCount, section: 0)
|
||||
tableNode.insertRows(at: [ spinnerIndexPath ], with: .none)
|
||||
} else {
|
||||
// Remove spinner.
|
||||
let spinnerIndexPath = NSIndexPath(forRow: oldState.itemCount, inSection: 0)
|
||||
tableNode.deleteRowsAtIndexPaths([ spinnerIndexPath ], withRowAnimation: .None)
|
||||
let spinnerIndexPath = IndexPath(row: oldState.itemCount, section: 0)
|
||||
tableNode.deleteRows(at: [ spinnerIndexPath ], with: .none)
|
||||
}
|
||||
}
|
||||
}, completion:nil)
|
||||
@@ -128,20 +128,20 @@ final class ViewController: ASViewController, ASTableDataSource, ASTableDelegate
|
||||
|
||||
/// (Pretend) fetches some new items and calls the
|
||||
/// completion handler on the main thread.
|
||||
private static func fetchDataWithCompletion(completion: (Int) -> 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
|
||||
}
|
||||
|
||||
@@ -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 <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
@@ -24,6 +24,6 @@
|
||||
ASTextNode *_indexPathTextNode;
|
||||
}
|
||||
|
||||
@property (nonatomic) NSIndexPath *indexPath;
|
||||
@property NSIndexPath *indexPath;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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"
|
||||
@@ -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,9 +68,20 @@
|
||||
|
||||
- (void)setIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
@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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user