Add 'submodules/AsyncDisplayKit/' from commit '02bedc12816e251ad71777f9d2578329b6d2bef6'

git-subtree-dir: submodules/AsyncDisplayKit
git-subtree-mainline: d06f423e0e
git-subtree-split: 02bedc1281
This commit is contained in:
Peter
2019-06-11 18:42:43 +01:00
2160 changed files with 232035 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
//
// AppDelegate.h
// 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 <UIKit/UIKit.h>
#define UseAutomaticLayout 1
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

View File

@@ -0,0 +1,25 @@
//
// AppDelegate.m
// 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 "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
[self.window makeKeyAndVisible];
return YES;
}
@end

View File

@@ -0,0 +1,17 @@
//
// BlurbNode.h
// 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/AsyncDisplayKit.h>
/**
* Simple node that displays a placekitten.com attribution.
*/
@interface BlurbNode : ASCellNode
@end

View File

@@ -0,0 +1,113 @@
//
// BlurbNode.m
// 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 "BlurbNode.h"
#import "AppDelegate.h"
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
#import <AsyncDisplayKit/ASHighlightOverlayLayer.h>
#import <AsyncDisplayKit/ASInsetLayoutSpec.h>
#import <AsyncDisplayKit/ASCenterLayoutSpec.h>
static CGFloat kTextPadding = 10.0f;
static NSString *kLinkAttributeName = @"PlaceKittenNodeLinkAttributeName";
@interface BlurbNode () <ASTextNodeDelegate>
{
ASTextNode *_textNode;
}
@end
@implementation BlurbNode
#pragma mark -
#pragma mark ASCellNode.
- (instancetype)init
{
if (!(self = [super init]))
return nil;
// create a text node
_textNode = [[ASTextNode alloc] init];
// configure the node to support tappable links
_textNode.delegate = self;
_textNode.userInteractionEnabled = YES;
_textNode.linkAttributeNames = @[ kLinkAttributeName ];
// generate an attributed string using the custom link attribute specified above
NSString *blurb = @"Nic Cage courtesy of himself.";
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:blurb];
_textNode.attributedText = string;
// add it as a subnode, and we're done
[self addSubnode:_textNode];
return self;
}
- (void)didLoad
{
// enable highlighting now that self.layer has loaded -- see ASHighlightOverlayLayer.h
self.layer.as_allowsHighlightDrawing = YES;
[super didLoad];
}
#if UseAutomaticLayout
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
ASCenterLayoutSpec *centerSpec = [[ASCenterLayoutSpec alloc] init];
centerSpec.centeringOptions = ASCenterLayoutSpecCenteringX;
centerSpec.sizingOptions = ASCenterLayoutSpecSizingOptionMinimumY;
centerSpec.child = _textNode;
UIEdgeInsets padding =UIEdgeInsetsMake(kTextPadding, kTextPadding, kTextPadding, kTextPadding);
return [ASInsetLayoutSpec insetLayoutSpecWithInsets:padding child:centerSpec];
}
#else
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
// called on a background thread. custom nodes must call -measure: on their subnodes in -calculateSizeThatFits:
CGSize measuredSize = [_textNode measure:CGSizeMake(constrainedSize.width - 2 * kTextPadding,
constrainedSize.height - 2 * kTextPadding)];
return CGSizeMake(constrainedSize.width, measuredSize.height + 2 * kTextPadding);
}
- (void)layout
{
// called on the main thread. we'll use the stashed size from above, instead of blocking on text sizing
CGSize textNodeSize = _textNode.calculatedSize;
_textNode.frame = CGRectMake(roundf((self.calculatedSize.width - textNodeSize.width) / 2.0f),
kTextPadding,
textNodeSize.width,
textNodeSize.height);
}
#endif
#pragma mark -
#pragma mark ASTextNodeDelegate methods.
- (BOOL)textNode:(ASTextNode *)richTextNode shouldHighlightLinkAttribute:(NSString *)attribute value:(id)value atPoint:(CGPoint)point
{
// opt into link highlighting -- tap and hold the link to try it! must enable highlighting on a layer, see -didLoad
return YES;
}
- (void)textNode:(ASTextNode *)richTextNode tappedLinkAttribute:(NSString *)attribute value:(NSURL *)URL atPoint:(CGPoint)point textRange:(NSRange)textRange
{
// the node tapped a link, open it
[[UIApplication sharedApplication] openURL:URL];
}
@end

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.facebook.AsyncDisplayKit.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,22 @@
//
// NicCageNode.h
// 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/AsyncDisplayKit.h>
/**
* Social media-style node that displays a kitten picture and a random length
* of lorem ipsum text. Uses a placekitten.com kitten of the specified size.
*/
@interface NicCageNode : ASCellNode
- (instancetype)initWithKittenOfSize:(CGSize)size;
- (void)toggleImageEnlargement;
@end

View File

@@ -0,0 +1,260 @@
//
// NicCageNode.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 "NicCageNode.h"
#import "AppDelegate.h"
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
#import <AsyncDisplayKit/ASDisplayNode+Beta.h>
#import <AsyncDisplayKit/ASStackLayoutSpec.h>
#import <AsyncDisplayKit/ASInsetLayoutSpec.h>
#import <AsyncDisplayKit/ASVideoNode.h>
static const CGFloat kImageSize = 80.0f;
static const CGFloat kOuterPadding = 16.0f;
static const CGFloat kInnerPadding = 10.0f;
#define kVideoURL @"https://www.w3schools.com/html/mov_bbb.mp4"
#define kVideoStreamURL @"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"
@interface NicCageNode ()
{
CGSize _kittenSize;
// ASNetworkImageNode *_imageNode;
ASVideoNode *_videoNode;
ASTextNode *_textNode;
ASDisplayNode *_divider;
BOOL _isImageEnlarged;
BOOL _swappedTextAndImage;
}
@end
@implementation NicCageNode
// lorem ipsum text courtesy https://kittyipsum.com/ <3
+ (NSArray *)placeholders
{
static NSArray *placeholders = nil;
static dispatch_once_t once;
dispatch_once(&once, ^{
placeholders = @[
@"Kitty ipsum dolor sit amet, purr sleep on your face lay down in your way biting, sniff tincidunt a etiam fluffy fur judging you stuck in a tree kittens.",
@"Lick tincidunt a biting eat the grass, egestas enim ut lick leap puking climb the curtains lick.",
@"Lick quis nunc toss the mousie vel, tortor pellentesque sunbathe orci turpis non tail flick suscipit sleep in the sink.",
@"Orci turpis litter box et stuck in a tree, egestas ac tempus et aliquam elit.",
@"Hairball iaculis dolor dolor neque, nibh adipiscing vehicula egestas dolor aliquam.",
@"Sunbathe fluffy fur tortor faucibus pharetra jump, enim jump on the table I don't like that food catnip toss the mousie scratched.",
@"Quis nunc nam sleep in the sink quis nunc purr faucibus, chase the red dot consectetur bat sagittis.",
@"Lick tail flick jump on the table stretching purr amet, rhoncus scratched jump on the table run.",
@"Suspendisse aliquam vulputate feed me sleep on your keyboard, rip the couch faucibus sleep on your keyboard tristique give me fish dolor.",
@"Rip the couch hiss attack your ankles biting pellentesque puking, enim suspendisse enim mauris a.",
@"Sollicitudin iaculis vestibulum toss the mousie biting attack your ankles, puking nunc jump adipiscing in viverra.",
@"Nam zzz amet neque, bat tincidunt a iaculis sniff hiss bibendum leap nibh.",
@"Chase the red dot enim puking chuf, tristique et egestas sniff sollicitudin pharetra enim ut mauris a.",
@"Sagittis scratched et lick, hairball leap attack adipiscing catnip tail flick iaculis lick.",
@"Neque neque sleep in the sink neque sleep on your face, climb the curtains chuf tail flick sniff tortor non.",
@"Ac etiam kittens claw toss the mousie jump, pellentesque rhoncus litter box give me fish adipiscing mauris a.",
@"Pharetra egestas sunbathe faucibus ac fluffy fur, hiss feed me give me fish accumsan.",
@"Tortor leap tristique accumsan rutrum sleep in the sink, amet sollicitudin adipiscing dolor chase the red dot.",
@"Knock over the lamp pharetra vehicula sleep on your face rhoncus, jump elit cras nec quis quis nunc nam.",
@"Sollicitudin feed me et ac in viverra catnip, nunc eat I don't like that food iaculis give me fish.",
];
});
return placeholders;
}
- (instancetype)initWithKittenOfSize:(CGSize)size
{
if (!(self = [super init]))
return nil;
_kittenSize = size;
u_int32_t videoInitMethod = arc4random_uniform(3);
u_int32_t autoPlay = arc4random_uniform(2);
NSArray* methodArray = @[@"AVAsset", @"File URL", @"HLS URL"];
NSArray* autoPlayArray = @[@"paused", @"auto play"];
switch (videoInitMethod) {
case 0:
// Construct an AVAsset from a URL
_videoNode = [[ASVideoNode alloc] init];
_videoNode.asset = [AVAsset assetWithURL:[NSURL URLWithString:kVideoURL]];
break;
case 1:
// Construct the video node directly from the .mp4 URL
_videoNode = [[ASVideoNode alloc] init];
_videoNode.asset = [AVAsset assetWithURL:[NSURL URLWithString:kVideoURL]];
break;
case 2:
// Construct the video node from an HTTP Live Streaming URL
// URL from https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html
_videoNode = [[ASVideoNode alloc] init];
_videoNode.asset = [AVAsset assetWithURL:[NSURL URLWithString:kVideoStreamURL]];
break;
}
if (autoPlay == 1)
_videoNode.shouldAutoplay = YES;
_videoNode.shouldAutorepeat = YES;
_videoNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
[self addSubnode:_videoNode];
_textNode = [[ASTextNode alloc] init];
_textNode.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@ %@", methodArray[videoInitMethod], autoPlayArray[autoPlay], [self kittyIpsum]]
attributes:[self textStyle]];
[self addSubnode:_textNode];
// hairline cell separator
_divider = [[ASDisplayNode alloc] init];
_divider.backgroundColor = [UIColor lightGrayColor];
[self addSubnode:_divider];
return self;
}
- (NSString *)kittyIpsum
{
NSArray *placeholders = [NicCageNode placeholders];
u_int32_t ipsumCount = (u_int32_t)[placeholders count];
u_int32_t location = arc4random_uniform(ipsumCount);
u_int32_t length = arc4random_uniform(ipsumCount - location);
NSMutableString *string = [placeholders[location] mutableCopy];
for (u_int32_t i = location + 1; i < location + length; i++) {
[string appendString:(i % 2 == 0) ? @"\n" : @" "];
[string appendString:placeholders[i]];
}
return string;
}
- (NSDictionary *)textStyle
{
UIFont *font = [UIFont fontWithName:@"HelveticaNeue" size:12.0f];
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.paragraphSpacing = 0.5 * font.lineHeight;
style.hyphenationFactor = 1.0;
return @{ NSFontAttributeName: font,
NSParagraphStyleAttributeName: style };
}
#if UseAutomaticLayout
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
CGSize videoNodeSize = _isImageEnlarged ? CGSizeMake(2.0 * kImageSize, 2.0 * kImageSize)
: CGSizeMake(kImageSize, kImageSize);
[_videoNode.style setPreferredSize:videoNodeSize];
_textNode.style.flexShrink = 1.0;
ASStackLayoutSpec *stackSpec = [[ASStackLayoutSpec alloc] init];
stackSpec.direction = ASStackLayoutDirectionHorizontal;
stackSpec.spacing = kInnerPadding;
[stackSpec setChildren:!_swappedTextAndImage ? @[_videoNode, _textNode] : @[_textNode, _videoNode]];
ASInsetLayoutSpec *insetSpec = [[ASInsetLayoutSpec alloc] init];
insetSpec.insets = UIEdgeInsetsMake(kOuterPadding, kOuterPadding, kOuterPadding, kOuterPadding);
insetSpec.child = stackSpec;
return insetSpec;
}
// With box model, you don't need to override this method, unless you want to add custom logic.
- (void)layout
{
[super layout];
// Manually layout the divider.
CGFloat pixelHeight = 1.0f / [[UIScreen mainScreen] scale];
_divider.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, pixelHeight);
}
#else
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
CGSize imageSize = CGSizeMake(kImageSize, kImageSize);
CGSize textSize = [_textNode measure:CGSizeMake(constrainedSize.width - kImageSize - 2 * kOuterPadding - kInnerPadding,
constrainedSize.height)];
// ensure there's room for the text
CGFloat requiredHeight = MAX(textSize.height, imageSize.height);
return CGSizeMake(constrainedSize.width, requiredHeight + 2 * kOuterPadding);
}
- (void)layout
{
CGFloat pixelHeight = 1.0f / [[UIScreen mainScreen] scale];
_divider.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, pixelHeight);
_imageNode.frame = CGRectMake(kOuterPadding, kOuterPadding, kImageSize, kImageSize);
CGSize textSize = _textNode.calculatedSize;
_textNode.frame = CGRectMake(kOuterPadding + kImageSize + kInnerPadding, kOuterPadding, textSize.width, textSize.height);
}
#endif
- (void)toggleImageEnlargement
{
_isImageEnlarged = !_isImageEnlarged;
[self setNeedsLayout];
}
- (void)toggleNodesSwap
{
_swappedTextAndImage = !_swappedTextAndImage;
[UIView animateWithDuration:0.15 animations:^{
self.alpha = 0;
} completion:^(BOOL finished) {
[self setNeedsLayout];
[self.view layoutIfNeeded];
[UIView animateWithDuration:0.15 animations:^{
self.alpha = 1;
}];
}];
}
- (void)updateBackgroundColor
{
if (self.highlighted) {
self.backgroundColor = [UIColor lightGrayColor];
} else if (self.selected) {
self.backgroundColor = [UIColor blueColor];
} else {
self.backgroundColor = [UIColor whiteColor];
}
}
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
[self updateBackgroundColor];
}
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
[self updateBackgroundColor];
}
@end

View File

@@ -0,0 +1,14 @@
//
// ViewController.h
// 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 <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end

View File

@@ -0,0 +1,197 @@
//
// ViewController.m
// 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 "ViewController.h"
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import <AsyncDisplayKit/ASAssert.h>
#import "BlurbNode.h"
#import "NicCageNode.h"
#import <AsyncDisplayKit/ASDisplayNode+Beta.h>
static const NSInteger kCageSize = 20; // intial number of Cage cells in ASTableView
static const NSInteger kCageBatchSize = 10; // number of Cage cells to add to ASTableView
static const NSInteger kMaxCageSize = 100; // max number of Cage cells allowed in ASTableView
@interface ViewController () <ASTableViewDataSource, ASTableViewDelegate>
{
ASTableView *_tableView;
// array of boxed CGSizes corresponding to placekitten.com kittens
NSMutableArray *_kittenDataSource;
BOOL _dataSourceLocked;
NSIndexPath *_blurbNodeIndexPath;
}
@property (nonatomic, strong) NSMutableArray *kittenDataSource;
@property (atomic, assign) BOOL dataSourceLocked;
@end
@implementation ViewController
#pragma mark -
#pragma mark UIViewController.
- (instancetype)init
{
if (!(self = [super init]))
return nil;
_tableView = [[ASTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // KittenNode has its own separator
_tableView.asyncDataSource = self;
_tableView.asyncDelegate = self;
// populate our "data source" with some random kittens
_kittenDataSource = [self createLitterWithSize:kCageSize];
_blurbNodeIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
self.title = @"Nic Cage";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:self
action:@selector(toggleEditingMode)];
return self;
}
- (NSMutableArray *)createLitterWithSize:(NSInteger)litterSize
{
NSMutableArray *cages = [NSMutableArray arrayWithCapacity:litterSize];
for (NSInteger i = 0; i < litterSize; i++) {
u_int32_t deltaX = arc4random_uniform(10) - 5;
u_int32_t deltaY = arc4random_uniform(10) - 5;
CGSize size = CGSizeMake(350 + 2 * deltaX, 350 + 4 * deltaY);
[cages addObject:[NSValue valueWithCGSize:size]];
}
return cages;
}
- (void)setKittenDataSource:(NSMutableArray *)kittenDataSource {
ASDisplayNodeAssert(!self.dataSourceLocked, @"Could not update data source when it is locked !");
_kittenDataSource = kittenDataSource;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview:_tableView];
}
- (void)viewWillLayoutSubviews
{
_tableView.frame = self.view.bounds;
}
- (void)toggleEditingMode
{
[_tableView setEditing:!_tableView.editing animated:YES];
}
#pragma mark -
#pragma mark ASTableView.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_tableView deselectRowAtIndexPath:indexPath animated:YES];
// Assume only kitten nodes are selectable (see -tableView:shouldHighlightRowAtIndexPath:).
NicCageNode *node = (NicCageNode *)[_tableView nodeForRowAtIndexPath:indexPath];
[node toggleImageEnlargement];
}
- (ASCellNode *)tableView:(ASTableView *)tableView nodeForRowAtIndexPath:(NSIndexPath *)indexPath
{
// special-case the first row
if ([_blurbNodeIndexPath compare:indexPath] == NSOrderedSame) {
BlurbNode *node = [[BlurbNode alloc] init];
return node;
}
NSValue *size = _kittenDataSource[indexPath.row - 1];
NicCageNode *node = [[NicCageNode alloc] initWithKittenOfSize:size.CGSizeValue];
return node;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// blurb node + kLitterSize kitties
return 1 + _kittenDataSource.count;
}
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
// Enable selection for kitten nodes
return [_blurbNodeIndexPath compare:indexPath] != NSOrderedSame;
}
- (void)tableViewLockDataSource:(ASTableView *)tableView
{
self.dataSourceLocked = YES;
}
- (void)tableViewUnlockDataSource:(ASTableView *)tableView
{
self.dataSourceLocked = NO;
}
- (BOOL)shouldBatchFetchForTableView:(UITableView *)tableView
{
return _kittenDataSource.count < kMaxCageSize;
}
- (void)tableView:(UITableView *)tableView willBeginBatchFetchWithContext:(ASBatchContext *)context
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sleep(1);
dispatch_async(dispatch_get_main_queue(), ^{
// populate a new array of random-sized kittens
NSArray *moarKittens = [self createLitterWithSize:kCageBatchSize];
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
// find number of kittens in the data source and create their indexPaths
NSInteger existingRows = _kittenDataSource.count + 1;
for (NSInteger i = 0; i < moarKittens.count; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:existingRows + i inSection:0]];
}
// add new kittens to the data source & notify table of new indexpaths
[_kittenDataSource addObjectsFromArray:moarKittens];
[tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[context completeBatchFetching:YES];
});
});
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Enable editing for Kitten nodes
return [_blurbNodeIndexPath compare:indexPath] != NSOrderedSame;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Assume only kitten nodes are editable (see -tableView:canEditRowAtIndexPath:).
[_kittenDataSource removeObjectAtIndex:indexPath.row - 1];
[_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
@end

View File

@@ -0,0 +1,18 @@
//
// main.m
// 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 <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}