mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Added sample project using networking and infinite scrolling and random cats
This commit is contained in:
20
examples/CatDealsCollectionView/Sample/AppDelegate.h
Normal file
20
examples/CatDealsCollectionView/Sample/AppDelegate.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#define SIMULATE_WEB_RESPONSE 0
|
||||
|
||||
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
@end
|
||||
51
examples/CatDealsCollectionView/Sample/AppDelegate.m
Normal file
51
examples/CatDealsCollectionView/Sample/AppDelegate.m
Normal file
@@ -0,0 +1,51 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "PresentingViewController.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] init];
|
||||
|
||||
[self pushNewViewControllerAnimated:NO];
|
||||
|
||||
[self.window makeKeyAndVisible];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)pushNewViewControllerAnimated:(BOOL)animated
|
||||
{
|
||||
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
|
||||
|
||||
#if SIMULATE_WEB_RESPONSE
|
||||
UIViewController *viewController = [[PresentingViewController alloc] init];
|
||||
#else
|
||||
UIViewController *viewController = [[ViewController alloc] init];
|
||||
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push Another Copy" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewViewController)];
|
||||
#endif
|
||||
|
||||
[navController pushViewController:viewController animated:animated];
|
||||
}
|
||||
|
||||
- (void)pushNewViewController
|
||||
{
|
||||
[self pushNewViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
21
examples/CatDealsCollectionView/Sample/BlurbNode.h
Normal file
21
examples/CatDealsCollectionView/Sample/BlurbNode.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
|
||||
/**
|
||||
* Simple node that displays a placekitten.com attribution.
|
||||
*/
|
||||
@interface BlurbNode : ASCellNode
|
||||
|
||||
+ (CGFloat)desiredHeightForWidth:(CGFloat)width;
|
||||
|
||||
@end
|
||||
112
examples/CatDealsCollectionView/Sample/BlurbNode.m
Normal file
112
examples/CatDealsCollectionView/Sample/BlurbNode.m
Normal file
@@ -0,0 +1,112 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "BlurbNode.h"
|
||||
|
||||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
||||
#import <AsyncDisplayKit/ASHighlightOverlayLayer.h>
|
||||
|
||||
#import <AsyncDisplayKit/ASInsetLayoutSpec.h>
|
||||
#import <AsyncDisplayKit/ASCenterLayoutSpec.h>
|
||||
|
||||
static CGFloat kFixedHeight = 75.0f;
|
||||
static CGFloat kTextPadding = 10.0f;
|
||||
|
||||
@interface BlurbNode () <ASTextNodeDelegate>
|
||||
{
|
||||
ASTextNode *_textNode;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BlurbNode
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark ASCellNode.
|
||||
|
||||
+ (CGFloat)desiredHeightForWidth:(CGFloat)width {
|
||||
return kFixedHeight;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
self.backgroundColor = [UIColor lightGrayColor];
|
||||
// create a text node
|
||||
_textNode = [[ASTextNode alloc] init];
|
||||
_textNode.maximumNumberOfLines = 2;
|
||||
|
||||
// configure the node to support tappable links
|
||||
_textNode.delegate = self;
|
||||
_textNode.userInteractionEnabled = YES;
|
||||
|
||||
// generate an attributed string using the custom link attribute specified above
|
||||
NSString *blurb = @"Kittens courtesy lorempixel.com \U0001F638 \nTitles courtesy of catipsum.com";
|
||||
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:blurb];
|
||||
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Light" size:16.0f] range:NSMakeRange(0, blurb.length)];
|
||||
[string addAttributes:@{
|
||||
NSLinkAttributeName: [NSURL URLWithString:@"http://lorempixel.com/"],
|
||||
NSForegroundColorAttributeName: [UIColor blueColor],
|
||||
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle | NSUnderlinePatternDot),
|
||||
}
|
||||
range:[blurb rangeOfString:@"lorempixel.com"]];
|
||||
[string addAttributes:@{
|
||||
NSLinkAttributeName: [NSURL URLWithString:@"http://www.catipsum.com/"],
|
||||
NSForegroundColorAttributeName: [UIColor blueColor],
|
||||
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle | NSUnderlinePatternDot),
|
||||
} range:[blurb rangeOfString:@"catipsum.com"]];
|
||||
_textNode.attributedString = 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];
|
||||
}
|
||||
|
||||
- (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];
|
||||
}
|
||||
|
||||
|
||||
#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
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"orientation" : "portrait",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Default-568h@2x.png",
|
||||
"minimum-system-version" : "7.0",
|
||||
"subtype" : "retina4",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"scale" : "1x",
|
||||
"orientation" : "portrait"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"scale" : "2x",
|
||||
"orientation" : "portrait"
|
||||
},
|
||||
{
|
||||
"orientation" : "portrait",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Default-568h@2x.png",
|
||||
"subtype" : "retina4",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"orientation" : "portrait",
|
||||
"idiom" : "iphone",
|
||||
"minimum-system-version" : "7.0",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
21
examples/CatDealsCollectionView/Sample/Images.xcassets/cat_face.imageset/Contents.json
vendored
Normal file
21
examples/CatDealsCollectionView/Sample/Images.xcassets/cat_face.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "cat_face.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
BIN
examples/CatDealsCollectionView/Sample/Images.xcassets/cat_face.imageset/cat_face.png
vendored
Normal file
BIN
examples/CatDealsCollectionView/Sample/Images.xcassets/cat_face.imageset/cat_face.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
59
examples/CatDealsCollectionView/Sample/Info.plist
Normal file
59
examples/CatDealsCollectionView/Sample/Info.plist
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
<key>NSExceptionDomains</key>
|
||||
<dict>
|
||||
<key>http://lorempixel.com</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIcons</key>
|
||||
<dict/>
|
||||
<key>CFBundleIcons~ipad</key>
|
||||
<dict/>
|
||||
<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>UILaunchStoryboardName</key>
|
||||
<string>Launchboard</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
21
examples/CatDealsCollectionView/Sample/ItemNode.h
Normal file
21
examples/CatDealsCollectionView/Sample/ItemNode.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
#import "ItemViewModel.h"
|
||||
|
||||
@interface ItemNode : ASCellNode
|
||||
|
||||
- initWithViewModel:(ItemViewModel *)viewModel;
|
||||
+ (CGSize)sizeForWidth:(CGFloat)width;
|
||||
+ (CGSize)preferredViewSize;
|
||||
|
||||
@end
|
||||
361
examples/CatDealsCollectionView/Sample/ItemNode.m
Normal file
361
examples/CatDealsCollectionView/Sample/ItemNode.m
Normal file
@@ -0,0 +1,361 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "ItemNode.h"
|
||||
#import "ItemStyles.h"
|
||||
#import "PlaceholderNetworkImageNode.h"
|
||||
|
||||
const CGFloat kFixedLabelsAreaHeight = 96.0;
|
||||
const CGFloat kDesignWidth = 320.0;
|
||||
const CGFloat kDesignHeight = 299.0;
|
||||
const CGFloat kBadgeHeight = 34.0;
|
||||
const CGFloat kSoldOutGBHeight = 50.0;
|
||||
|
||||
@interface ItemNode() <ASNetworkImageNodeDelegate>
|
||||
|
||||
@property (nonatomic, strong) ItemViewModel *viewModel;
|
||||
|
||||
@property (nonatomic, strong) PlaceholderNetworkImageNode *dealImageView;
|
||||
|
||||
@property (nonatomic, strong) ASTextNode *titleLabel;
|
||||
@property (nonatomic, strong) ASTextNode *firstInfoLabel;
|
||||
@property (nonatomic, strong) ASTextNode *distanceLabel;
|
||||
@property (nonatomic, strong) ASTextNode *secondInfoLabel;
|
||||
@property (nonatomic, strong) ASTextNode *originalPriceLabel;
|
||||
@property (nonatomic, strong) ASTextNode *finalPriceLabel;
|
||||
@property (nonatomic, strong) ASTextNode *soldOutLabelFlat;
|
||||
@property (nonatomic, strong) ASDisplayNode *soldOutLabelBackground;
|
||||
@property (nonatomic, strong) ASDisplayNode *soldOutOverlay;
|
||||
@property (nonatomic, strong) ASTextNode *badge;
|
||||
|
||||
@end
|
||||
|
||||
@implementation ItemNode
|
||||
|
||||
- (instancetype)initWithViewModel:(ItemViewModel *)viewModel
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_viewModel = viewModel;
|
||||
[self setup];
|
||||
[self updateLabels];
|
||||
[self updateBackgroundColor];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (BOOL)isRTL {
|
||||
return [UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;
|
||||
}
|
||||
|
||||
- (void)setup {
|
||||
self.dealImageView = [[PlaceholderNetworkImageNode alloc] init];
|
||||
self.dealImageView.delegate = self;
|
||||
self.dealImageView.placeholderEnabled = YES;
|
||||
self.dealImageView.placeholderImageOverride = [ItemStyles placeholderImage];
|
||||
self.dealImageView.defaultImage = [ItemStyles placeholderImage];
|
||||
self.dealImageView.contentMode = UIViewContentModeScaleToFill;
|
||||
self.dealImageView.placeholderFadeDuration = 0.0;
|
||||
self.dealImageView.layerBacked = YES;
|
||||
|
||||
self.titleLabel = [[ASTextNode alloc] init];
|
||||
self.titleLabel.maximumNumberOfLines = 2;
|
||||
self.titleLabel.alignSelf = ASStackLayoutAlignSelfStart;
|
||||
self.titleLabel.flexGrow = YES;
|
||||
self.titleLabel.layerBacked = YES;
|
||||
|
||||
self.firstInfoLabel = [[ASTextNode alloc] init];
|
||||
self.firstInfoLabel.maximumNumberOfLines = 1;
|
||||
self.firstInfoLabel.layerBacked = YES;
|
||||
|
||||
self.secondInfoLabel = [[ASTextNode alloc] init];
|
||||
self.secondInfoLabel.maximumNumberOfLines = 1;
|
||||
self.secondInfoLabel.layerBacked = YES;
|
||||
|
||||
self.distanceLabel = [[ASTextNode alloc] init];
|
||||
self.distanceLabel.maximumNumberOfLines = 1;
|
||||
self.distanceLabel.layerBacked = YES;
|
||||
|
||||
self.originalPriceLabel = [[ASTextNode alloc] init];
|
||||
self.originalPriceLabel.maximumNumberOfLines = 1;
|
||||
self.originalPriceLabel.layerBacked = YES;
|
||||
|
||||
self.finalPriceLabel = [[ASTextNode alloc] init];
|
||||
self.finalPriceLabel.maximumNumberOfLines = 1;
|
||||
self.finalPriceLabel.layerBacked = YES;
|
||||
|
||||
self.badge = [[ASTextNode alloc] init];
|
||||
self.badge.hidden = YES;
|
||||
self.badge.layerBacked = YES;
|
||||
|
||||
self.soldOutLabelFlat = [[ASTextNode alloc] init];
|
||||
self.soldOutLabelFlat.layerBacked = YES;
|
||||
|
||||
self.soldOutLabelBackground = [[ASDisplayNode alloc] init];
|
||||
self.soldOutLabelBackground.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(1), ASRelativeDimensionMakeWithPoints(kSoldOutGBHeight)), ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(1), ASRelativeDimensionMakeWithPoints(kSoldOutGBHeight)));
|
||||
self.soldOutLabelBackground.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.9];
|
||||
self.soldOutLabelBackground.flexGrow = YES;
|
||||
self.soldOutLabelBackground.layerBacked = YES;
|
||||
|
||||
self.soldOutOverlay = [[ASDisplayNode alloc] init];
|
||||
self.soldOutOverlay.flexGrow = YES;
|
||||
self.soldOutOverlay.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
|
||||
self.soldOutOverlay.layerBacked = YES;
|
||||
|
||||
[self addSubnode:self.dealImageView];
|
||||
[self addSubnode:self.titleLabel];
|
||||
[self addSubnode:self.firstInfoLabel];
|
||||
[self addSubnode:self.secondInfoLabel];
|
||||
[self addSubnode:self.originalPriceLabel];
|
||||
[self addSubnode:self.finalPriceLabel];
|
||||
[self addSubnode:self.distanceLabel];
|
||||
[self addSubnode:self.badge];
|
||||
|
||||
[self addSubnode:self.soldOutLabelBackground];
|
||||
[self addSubnode:self.soldOutLabelFlat];
|
||||
[self addSubnode:self.soldOutOverlay];
|
||||
self.soldOutOverlay.hidden = YES;
|
||||
self.soldOutLabelBackground.hidden = YES;
|
||||
self.soldOutLabelFlat.hidden = YES;
|
||||
|
||||
[self addSubnode:self.soldOutOverlay];
|
||||
|
||||
if ([ItemNode isRTL]) {
|
||||
self.titleLabel.alignSelf = ASStackLayoutAlignSelfEnd;
|
||||
self.firstInfoLabel.alignSelf = ASStackLayoutAlignSelfEnd;
|
||||
self.distanceLabel.alignSelf = ASStackLayoutAlignSelfEnd;
|
||||
self.secondInfoLabel.alignSelf = ASStackLayoutAlignSelfEnd;
|
||||
self.originalPriceLabel.alignSelf = ASStackLayoutAlignSelfStart;
|
||||
self.finalPriceLabel.alignSelf = ASStackLayoutAlignSelfStart;
|
||||
} else {
|
||||
self.firstInfoLabel.alignSelf = ASStackLayoutAlignSelfStart;
|
||||
self.distanceLabel.alignSelf = ASStackLayoutAlignSelfStart;
|
||||
self.secondInfoLabel.alignSelf = ASStackLayoutAlignSelfStart;
|
||||
self.originalPriceLabel.alignSelf = ASStackLayoutAlignSelfEnd;
|
||||
self.finalPriceLabel.alignSelf = ASStackLayoutAlignSelfEnd;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateLabels {
|
||||
// Set Title text
|
||||
if (self.viewModel.titleText) {
|
||||
self.titleLabel.attributedString = [[NSAttributedString alloc] initWithString:self.viewModel.titleText attributes:[ItemStyles titleStyle]];
|
||||
}
|
||||
if (self.viewModel.firstInfoText) {
|
||||
self.firstInfoLabel.attributedString = [[NSAttributedString alloc] initWithString:self.viewModel.firstInfoText attributes:[ItemStyles subtitleStyle]];
|
||||
}
|
||||
|
||||
if (self.viewModel.secondInfoText) {
|
||||
self.secondInfoLabel.attributedString = [[NSAttributedString alloc] initWithString:self.viewModel.secondInfoText attributes:[ItemStyles secondInfoStyle]];
|
||||
}
|
||||
if (self.viewModel.originalPriceText) {
|
||||
self.originalPriceLabel.attributedString = [[NSAttributedString alloc] initWithString:self.viewModel.originalPriceText attributes:[ItemStyles originalPriceStyle]];
|
||||
}
|
||||
if (self.viewModel.finalPriceText) {
|
||||
self.finalPriceLabel.attributedString = [[NSAttributedString alloc] initWithString:self.viewModel.finalPriceText attributes:[ItemStyles finalPriceStyle]];
|
||||
}
|
||||
if (self.viewModel.distanceLabelText) {
|
||||
NSString *format = [ItemNode isRTL] ? @"%@ •" : @"• %@";
|
||||
NSString *distanceText = [NSString stringWithFormat:format, self.viewModel.distanceLabelText];
|
||||
|
||||
self.distanceLabel.attributedString = [[NSAttributedString alloc] initWithString:distanceText attributes:[ItemStyles distanceStyle]];
|
||||
}
|
||||
|
||||
BOOL isSoldOut = self.viewModel.soldOutText != nil;
|
||||
|
||||
if (isSoldOut) {
|
||||
NSString *soldOutText = self.viewModel.soldOutText;
|
||||
self.soldOutLabelFlat.attributedString = [[NSAttributedString alloc] initWithString:soldOutText attributes:[ItemStyles soldOutStyle]];
|
||||
}
|
||||
self.soldOutOverlay.hidden = !isSoldOut;
|
||||
self.soldOutLabelFlat.hidden = !isSoldOut;
|
||||
self.soldOutLabelBackground.hidden = !isSoldOut;
|
||||
|
||||
BOOL hasBadge = self.viewModel.badgeText != nil;
|
||||
if (hasBadge) {
|
||||
self.badge.attributedString = [[NSAttributedString alloc] initWithString:self.viewModel.badgeText attributes:[ItemStyles badgeStyle]];
|
||||
self.badge.backgroundColor = [ItemStyles badgeColor];
|
||||
}
|
||||
self.badge.hidden = !hasBadge;
|
||||
}
|
||||
|
||||
- (void)updateBackgroundColor
|
||||
{
|
||||
if (self.highlighted) {
|
||||
self.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3];
|
||||
} else if (self.selected) {
|
||||
self.backgroundColor = [UIColor lightGrayColor];
|
||||
} else {
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)imageNode:(ASNetworkImageNode *)imageNode didLoadImage:(UIImage *)image {
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected
|
||||
{
|
||||
[super setSelected:selected];
|
||||
[self updateBackgroundColor];
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted
|
||||
{
|
||||
[super setHighlighted:highlighted];
|
||||
[self updateBackgroundColor];
|
||||
}
|
||||
|
||||
#pragma mark - superclass
|
||||
|
||||
- (void)displayWillStart {
|
||||
[super displayWillStart];
|
||||
[self fetchData];
|
||||
}
|
||||
|
||||
- (void)fetchData {
|
||||
[super fetchData];
|
||||
if (self.viewModel) {
|
||||
[self loadImage];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
|
||||
|
||||
ASLayoutSpec *textSpec = [self textSpec];
|
||||
ASLayoutSpec *imageSpec = [self imageSpecWithSize:constrainedSize];
|
||||
ASOverlayLayoutSpec *soldOutOverImage = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:imageSpec overlay:[self soldOutLabelSpec]];
|
||||
|
||||
NSArray *stackChildren = @[soldOutOverImage, textSpec];
|
||||
|
||||
ASStackLayoutSpec *mainStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:0.0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStretch children:stackChildren];
|
||||
|
||||
ASOverlayLayoutSpec *soldOutOverlay = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:mainStack overlay:self.soldOutOverlay];
|
||||
|
||||
return soldOutOverlay;
|
||||
}
|
||||
|
||||
- (ASLayoutSpec *)textSpec {
|
||||
CGFloat kInsetHorizontal = 16.0;
|
||||
CGFloat kInsetTop = 6.0;
|
||||
CGFloat kInsetBottom = 0.0;
|
||||
|
||||
UIEdgeInsets textInsets = UIEdgeInsetsMake(kInsetTop, kInsetHorizontal, kInsetBottom, kInsetHorizontal);
|
||||
|
||||
ASLayoutSpec *verticalSpacer = [[ASLayoutSpec alloc] init];
|
||||
verticalSpacer.flexGrow = YES;
|
||||
|
||||
ASLayoutSpec *horizontalSpacer1 = [[ASLayoutSpec alloc] init];
|
||||
horizontalSpacer1.flexGrow = YES;
|
||||
|
||||
ASLayoutSpec *horizontalSpacer2 = [[ASLayoutSpec alloc] init];
|
||||
horizontalSpacer2.flexGrow = YES;
|
||||
|
||||
NSArray *info1Children = @[self.firstInfoLabel, self.distanceLabel, horizontalSpacer1, self.originalPriceLabel];
|
||||
NSArray *info2Children = @[self.secondInfoLabel, horizontalSpacer2, self.finalPriceLabel];
|
||||
if ([ItemNode isRTL]) {
|
||||
info1Children = [[info1Children reverseObjectEnumerator] allObjects];
|
||||
info2Children = [[info2Children reverseObjectEnumerator] allObjects];
|
||||
}
|
||||
|
||||
ASStackLayoutSpec *info1Stack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:1.0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsBaselineLast children:info1Children];
|
||||
|
||||
ASStackLayoutSpec *info2Stack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:0.0 justifyContent:ASStackLayoutJustifyContentCenter alignItems:ASStackLayoutAlignItemsBaselineLast children:info2Children];
|
||||
|
||||
ASStackLayoutSpec *textStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:0.0 justifyContent:ASStackLayoutJustifyContentEnd alignItems:ASStackLayoutAlignItemsStretch children:@[self.titleLabel, verticalSpacer, info1Stack, info2Stack]];
|
||||
|
||||
ASInsetLayoutSpec *textWrapper = [ASInsetLayoutSpec insetLayoutSpecWithInsets:textInsets child:textStack];
|
||||
textWrapper.flexGrow = YES;
|
||||
|
||||
return textWrapper;
|
||||
}
|
||||
|
||||
- (ASLayoutSpec *)imageSpecWithSize:(ASSizeRange)constrainedSize {
|
||||
CGFloat imageRatio = [self imageRatioFromSize:constrainedSize.max];
|
||||
|
||||
ASRatioLayoutSpec *imagePlace = [ASRatioLayoutSpec ratioLayoutSpecWithRatio:imageRatio child:self.dealImageView];
|
||||
|
||||
self.badge.layoutPosition = CGPointMake(0, constrainedSize.max.height - kFixedLabelsAreaHeight - kBadgeHeight);
|
||||
self.badge.sizeRange = ASRelativeSizeRangeMake(ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(0), ASRelativeDimensionMakeWithPoints(kBadgeHeight)), ASRelativeSizeMake(ASRelativeDimensionMakeWithPercent(1), ASRelativeDimensionMakeWithPoints(kBadgeHeight)));
|
||||
ASStaticLayoutSpec *badgePosition = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[self.badge]];
|
||||
|
||||
ASOverlayLayoutSpec *badgeOverImage = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:imagePlace overlay:badgePosition];
|
||||
badgeOverImage.flexGrow = YES;
|
||||
|
||||
return badgeOverImage;
|
||||
}
|
||||
|
||||
- (ASLayoutSpec *)soldOutLabelSpec {
|
||||
ASCenterLayoutSpec *centerSoldOutLabel = [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY sizingOptions:ASCenterLayoutSpecSizingOptionMinimumXY child:self.soldOutLabelFlat];
|
||||
ASStaticLayoutSpec *soldOutBG = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[self.soldOutLabelBackground]];
|
||||
ASCenterLayoutSpec *centerSoldOut = [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY sizingOptions:ASCenterLayoutSpecSizingOptionDefault child:soldOutBG];
|
||||
ASBackgroundLayoutSpec *soldOutLabelOverBackground = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:centerSoldOutLabel background:centerSoldOut];
|
||||
return soldOutLabelOverBackground;
|
||||
}
|
||||
|
||||
|
||||
+ (CGSize)sizeForWidth:(CGFloat)width {
|
||||
CGFloat height = [self scaledHeightForPreferredSize:[self preferredViewSize] scaledWidth:width];
|
||||
return CGSizeMake(width, height);
|
||||
}
|
||||
|
||||
|
||||
+ (CGSize)preferredViewSize {
|
||||
return CGSizeMake(kDesignWidth, kDesignHeight);
|
||||
}
|
||||
|
||||
+ (CGFloat)scaledHeightForPreferredSize:(CGSize)preferredSize scaledWidth:(CGFloat)scaledWidth {
|
||||
CGFloat scale = scaledWidth / kDesignWidth;
|
||||
CGFloat scaledHeight = ceilf(scale * (kDesignHeight - kFixedLabelsAreaHeight)) + kFixedLabelsAreaHeight;
|
||||
|
||||
return scaledHeight;
|
||||
}
|
||||
|
||||
#pragma mark - view operations
|
||||
|
||||
- (CGFloat)imageRatioFromSize:(CGSize)size {
|
||||
CGFloat imageHeight = size.height - kFixedLabelsAreaHeight;
|
||||
CGFloat imageRatio = imageHeight / size.width;
|
||||
|
||||
return imageRatio;
|
||||
}
|
||||
|
||||
- (CGSize)imageSize {
|
||||
if (!CGSizeEqualToSize(self.dealImageView.frame.size, CGSizeZero)) {
|
||||
return self.dealImageView.frame.size;
|
||||
} else if (!CGSizeEqualToSize(self.calculatedSize, CGSizeZero)) {
|
||||
CGFloat imageRatio = [self imageRatioFromSize:self.calculatedSize];
|
||||
CGFloat imageWidth = self.calculatedSize.width;
|
||||
return CGSizeMake(imageWidth, imageRatio * imageWidth);
|
||||
} else {
|
||||
return CGSizeZero;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)loadImage {
|
||||
CGSize imageSize = [self imageSize];
|
||||
if (CGSizeEqualToSize(CGSizeZero, imageSize)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSURL *url = [self.viewModel imageURLWithSize:imageSize];
|
||||
|
||||
// if we're trying to set the deal image to what it already was, skip the work
|
||||
if ([[url absoluteString] isEqualToString:[self.dealImageView.URL absoluteString]]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the flag that says we've loaded our image
|
||||
[self.dealImageView setURL:url];
|
||||
}
|
||||
|
||||
@end
|
||||
23
examples/CatDealsCollectionView/Sample/ItemStyles.h
Normal file
23
examples/CatDealsCollectionView/Sample/ItemStyles.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// ItemStyles.h
|
||||
// Sample
|
||||
//
|
||||
// Created by Samuel Stow on 12/30/15.
|
||||
// Copyright © 2015 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ItemStyles : NSObject
|
||||
+ (NSDictionary *)titleStyle;
|
||||
+ (NSDictionary *)subtitleStyle;
|
||||
+ (NSDictionary *)distanceStyle;
|
||||
+ (NSDictionary *)secondInfoStyle;
|
||||
+ (NSDictionary *)originalPriceStyle;
|
||||
+ (NSDictionary *)finalPriceStyle;
|
||||
+ (NSDictionary *)soldOutStyle;
|
||||
+ (NSDictionary *)badgeStyle;
|
||||
+ (UIColor *)badgeColor;
|
||||
+ (UIImage *)placeholderImage;
|
||||
@end
|
||||
93
examples/CatDealsCollectionView/Sample/ItemStyles.m
Normal file
93
examples/CatDealsCollectionView/Sample/ItemStyles.m
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// ItemStyles.m
|
||||
// Sample
|
||||
//
|
||||
// Created by Samuel Stow on 12/30/15.
|
||||
// Copyright © 2015 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ItemStyles.h"
|
||||
|
||||
const CGFloat kTitleFontSize = 20.0;
|
||||
const CGFloat kInfoFontSize = 14.0;
|
||||
|
||||
UIColor *kTitleColor;
|
||||
UIColor *kInfoColor;
|
||||
UIColor *kFinalPriceColor;
|
||||
UIFont *kTitleFont;
|
||||
UIFont *kInfoFont;
|
||||
|
||||
@implementation ItemStyles
|
||||
|
||||
+ (void)initialize {
|
||||
if (self == [ItemStyles class]) {
|
||||
kTitleColor = [UIColor darkGrayColor];
|
||||
kInfoColor = [UIColor grayColor];
|
||||
kFinalPriceColor = [UIColor greenColor];
|
||||
kTitleFont = [UIFont boldSystemFontOfSize:kTitleFontSize];
|
||||
kInfoFont = [UIFont systemFontOfSize:kInfoFontSize];
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSDictionary *)titleStyle {
|
||||
// Title Label
|
||||
return @{ NSFontAttributeName:kTitleFont,
|
||||
NSForegroundColorAttributeName:kTitleColor };
|
||||
}
|
||||
|
||||
+ (NSDictionary *)subtitleStyle {
|
||||
// First Subtitle
|
||||
return @{ NSFontAttributeName:kInfoFont,
|
||||
NSForegroundColorAttributeName:kInfoColor };
|
||||
}
|
||||
|
||||
+ (NSDictionary *)distanceStyle {
|
||||
// Distance Label
|
||||
return @{ NSFontAttributeName:kInfoFont,
|
||||
NSForegroundColorAttributeName:kInfoColor};
|
||||
}
|
||||
|
||||
+ (NSDictionary *)secondInfoStyle {
|
||||
// Second Subtitle
|
||||
return @{ NSFontAttributeName:kInfoFont,
|
||||
NSForegroundColorAttributeName:kInfoColor};
|
||||
}
|
||||
|
||||
+ (NSDictionary *)originalPriceStyle {
|
||||
// Original price
|
||||
return @{ NSFontAttributeName:kInfoFont,
|
||||
NSForegroundColorAttributeName:kInfoColor,
|
||||
NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)};
|
||||
}
|
||||
|
||||
+ (NSDictionary *)finalPriceStyle {
|
||||
// Discounted / Claimable price label
|
||||
return @{ NSFontAttributeName:kTitleFont,
|
||||
NSForegroundColorAttributeName:kFinalPriceColor};
|
||||
}
|
||||
|
||||
+ (NSDictionary *)soldOutStyle {
|
||||
// Setup Sold Out Label
|
||||
return @{ NSFontAttributeName:kTitleFont,
|
||||
NSForegroundColorAttributeName:kTitleColor};
|
||||
}
|
||||
|
||||
+ (NSDictionary *)badgeStyle {
|
||||
// Setup Sold Out Label
|
||||
return @{ NSFontAttributeName:kTitleFont,
|
||||
NSForegroundColorAttributeName:[UIColor whiteColor]};
|
||||
}
|
||||
|
||||
+ (UIColor *)badgeColor {
|
||||
return [[UIColor purpleColor] colorWithAlphaComponent:0.4];
|
||||
}
|
||||
|
||||
+ (UIImage *)placeholderImage {
|
||||
static UIImage *__catFace = nil;
|
||||
if (!__catFace) {
|
||||
__catFace = [UIImage imageNamed:@"cat_face"];
|
||||
}
|
||||
return __catFace;
|
||||
}
|
||||
|
||||
@end
|
||||
27
examples/CatDealsCollectionView/Sample/ItemViewModel.h
Normal file
27
examples/CatDealsCollectionView/Sample/ItemViewModel.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// GPDealViewModel.h
|
||||
// Groupon
|
||||
//
|
||||
// Created by Samuel Stow on 12/29/15.
|
||||
// Copyright © 2015 Groupon Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ItemViewModel : NSObject
|
||||
|
||||
+ (instancetype)randomItem;
|
||||
|
||||
@property (nonatomic, copy) NSString *titleText;
|
||||
@property (nonatomic, copy) NSString *firstInfoText;
|
||||
@property (nonatomic, copy) NSString *secondInfoText;
|
||||
@property (nonatomic, copy) NSString *originalPriceText;
|
||||
@property (nonatomic, copy) NSString *finalPriceText;
|
||||
@property (nonatomic, copy) NSString *soldOutText;
|
||||
@property (nonatomic, copy) NSString *distanceLabelText;
|
||||
@property (nonatomic, copy) NSString *badgeText;
|
||||
|
||||
- (NSURL *)imageURLWithSize:(CGSize)size;
|
||||
|
||||
@end
|
||||
99
examples/CatDealsCollectionView/Sample/ItemViewModel.m
Normal file
99
examples/CatDealsCollectionView/Sample/ItemViewModel.m
Normal file
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// GPDealViewModel.m
|
||||
// Groupon
|
||||
//
|
||||
// Created by Samuel Stow on 12/29/15.
|
||||
// Copyright © 2015 Groupon Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ItemViewModel.h"
|
||||
|
||||
NSArray *titles;
|
||||
NSArray *firstInfos;
|
||||
NSArray *badges;
|
||||
|
||||
@interface ItemViewModel()
|
||||
|
||||
@property (nonatomic, assign) NSInteger catNumber;
|
||||
@property (nonatomic, assign) NSInteger labelNumber;
|
||||
|
||||
@end
|
||||
|
||||
@implementation ItemViewModel
|
||||
|
||||
+ (instancetype)randomItem {
|
||||
return [[ItemViewModel alloc] init];
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_titleText = [self randomObjectFromArray:titles];
|
||||
_firstInfoText = [self randomObjectFromArray:firstInfos];
|
||||
_secondInfoText = [NSString stringWithFormat:@"%zd+ bought", [self randomNumberInRange:5 to:6000]];
|
||||
_originalPriceText = [NSString stringWithFormat:@"$%zd", [self randomNumberInRange:40 to:90]];
|
||||
_finalPriceText = [NSString stringWithFormat:@"$%zd", [self randomNumberInRange:5 to:30]];
|
||||
BOOL isSoldOut = arc4random() % 5 == 0;
|
||||
_soldOutText = isSoldOut ? @"SOLD OUT" : nil;
|
||||
_distanceLabelText = [NSString stringWithFormat:@"%zd mi", [self randomNumberInRange:1 to:20]];
|
||||
BOOL isBadged = arc4random() % 2 == 0;
|
||||
if (isBadged) {
|
||||
_badgeText = [self randomObjectFromArray:badges];
|
||||
}
|
||||
_catNumber = [self randomNumberInRange:1 to:10];
|
||||
_labelNumber = [self randomNumberInRange:1 to:10000];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSURL *)imageURLWithSize:(CGSize)size {
|
||||
NSString *imageText = [NSString stringWithFormat:@"Fun cat pic %zd", self.labelNumber];
|
||||
NSString *urlString = [NSString stringWithFormat:@"http://lorempixel.com/%zd/%zd/cats/%zd/%@",
|
||||
(NSInteger)roundl(size.width),
|
||||
(NSInteger)roundl(size.height), self.catNumber, imageText];
|
||||
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
return [NSURL URLWithString:urlString];
|
||||
}
|
||||
|
||||
// titles courtesy of http://www.catipsum.com/
|
||||
+ (void)initialize {
|
||||
titles = @[@"Leave fur on owners clothes intrigued by the shower",
|
||||
@"Meowwww",
|
||||
@"Immediately regret falling into bathtub stare out the window",
|
||||
@"Jump launch to pounce upon little yarn mouse, bare fangs at toy run hide in litter box until treats are fed",
|
||||
@"Sleep nap",
|
||||
@"Lick butt",
|
||||
@"Chase laser lick arm hair present belly, scratch hand when stroked"];
|
||||
firstInfos = @[@"Kitty Shop",
|
||||
@"Cat's r us",
|
||||
@"Fantastic Felines",
|
||||
@"The Cat Shop",
|
||||
@"Cat in a hat",
|
||||
@"Cat-tastic"
|
||||
];
|
||||
|
||||
badges = @[@"ADORABLE",
|
||||
@"BOUNCES",
|
||||
@"HATES CUCUMBERS",
|
||||
@"SCRATCHY"
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
- (id)randomObjectFromArray:(NSArray *)strings
|
||||
{
|
||||
u_int32_t ipsumCount = (u_int32_t)[strings count];
|
||||
u_int32_t location = arc4random_uniform(ipsumCount);
|
||||
|
||||
return strings[location];
|
||||
}
|
||||
|
||||
- (uint32_t)randomNumberInRange:(uint32_t)start to:(uint32_t)end {
|
||||
|
||||
return start + arc4random_uniform(end - start);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
|
||||
</dependencies>
|
||||
<scenes/>
|
||||
</document>
|
||||
15
examples/CatDealsCollectionView/Sample/LoadingNode.h
Normal file
15
examples/CatDealsCollectionView/Sample/LoadingNode.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// LoadingNode.h
|
||||
// Sample
|
||||
//
|
||||
// Created by Samuel Stow on 1/9/16.
|
||||
// Copyright © 2016 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
|
||||
@interface LoadingNode : ASCellNode
|
||||
|
||||
+ (CGFloat)desiredHeightForWidth:(CGFloat)width;
|
||||
|
||||
@end
|
||||
68
examples/CatDealsCollectionView/Sample/LoadingNode.m
Normal file
68
examples/CatDealsCollectionView/Sample/LoadingNode.m
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// LoadingNode.m
|
||||
// Sample
|
||||
//
|
||||
// Created by Samuel Stow on 1/9/16.
|
||||
// Copyright © 2016 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import "LoadingNode.h"
|
||||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
||||
#import <AsyncDisplayKit/ASHighlightOverlayLayer.h>
|
||||
|
||||
#import <AsyncDisplayKit/ASInsetLayoutSpec.h>
|
||||
#import <AsyncDisplayKit/ASCenterLayoutSpec.h>
|
||||
|
||||
static CGFloat kFixedHeight = 200.0f;
|
||||
|
||||
@interface LoadingNode ()
|
||||
{
|
||||
ASDisplayNode *_loadingSpinner;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation LoadingNode
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark ASCellNode.
|
||||
|
||||
+ (CGFloat)desiredHeightForWidth:(CGFloat)width {
|
||||
return kFixedHeight;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
_loadingSpinner = [[ASDisplayNode alloc] initWithViewBlock:^UIView * _Nonnull{
|
||||
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
||||
[spinner startAnimating];
|
||||
return spinner;
|
||||
}];
|
||||
_loadingSpinner.preferredFrameSize = CGSizeMake(50, 50);
|
||||
|
||||
|
||||
// add it as a subnode, and we're done
|
||||
[self addSubnode:_loadingSpinner];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)layout {
|
||||
[super layout];
|
||||
}
|
||||
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASCenterLayoutSpec *centerSpec = [[ASCenterLayoutSpec alloc] init];
|
||||
centerSpec.centeringOptions = ASCenterLayoutSpecCenteringXY;
|
||||
centerSpec.sizingOptions = ASCenterLayoutSpecSizingOptionDefault;
|
||||
centerSpec.child = _loadingSpinner;
|
||||
|
||||
return centerSpec;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// PlacholderNetworkImageNode.h
|
||||
// Sample
|
||||
//
|
||||
// Created by Samuel Stow on 1/14/16.
|
||||
// Copyright © 2016 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
|
||||
@interface PlaceholderNetworkImageNode : ASNetworkImageNode
|
||||
|
||||
@property (nonatomic, strong) UIImage *placeholderImageOverride;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// PlacholderNetworkImageNode.m
|
||||
// Sample
|
||||
//
|
||||
// Created by Samuel Stow on 1/14/16.
|
||||
// Copyright © 2016 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PlaceholderNetworkImageNode.h"
|
||||
|
||||
@implementation PlaceholderNetworkImageNode
|
||||
|
||||
- (UIImage *)placeholderImage {
|
||||
return self.placeholderImageOverride;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// PresentingViewController.h
|
||||
// Sample
|
||||
//
|
||||
// Created by Tom King on 12/23/15.
|
||||
// Copyright © 2015 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface PresentingViewController : UIViewController
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// PresentingViewController.m
|
||||
// Sample
|
||||
//
|
||||
// Created by Tom King on 12/23/15.
|
||||
// Copyright © 2015 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PresentingViewController.h"
|
||||
#import "ViewController.h"
|
||||
|
||||
@interface PresentingViewController ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation PresentingViewController
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push Details" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewViewController)];
|
||||
}
|
||||
|
||||
- (void)pushNewViewController
|
||||
{
|
||||
ViewController *controller = [[ViewController alloc] init];
|
||||
[self.navigationController pushViewController:controller animated:true];
|
||||
}
|
||||
|
||||
@end
|
||||
16
examples/CatDealsCollectionView/Sample/ViewController.h
Normal file
16
examples/CatDealsCollectionView/Sample/ViewController.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ViewController : UIViewController
|
||||
|
||||
@end
|
||||
244
examples/CatDealsCollectionView/Sample/ViewController.m
Normal file
244
examples/CatDealsCollectionView/Sample/ViewController.m
Normal file
@@ -0,0 +1,244 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "ViewController.h"
|
||||
|
||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||
#import "ItemNode.h"
|
||||
#import "BlurbNode.h"
|
||||
#import "LoadingNode.h"
|
||||
|
||||
static const NSTimeInterval kWebResponseDelay = 1.0;
|
||||
static const BOOL kSimulateWebResponse = YES;
|
||||
static const NSInteger kBatchSize = 20;
|
||||
|
||||
static const CGFloat kHorizontalSectionPadding = 10.0f;
|
||||
static const CGFloat kVerticalSectionPadding = 20.0f;
|
||||
|
||||
@interface ViewController () <ASCollectionViewDataSource, ASCollectionViewDelegateFlowLayout>
|
||||
{
|
||||
ASCollectionView *_collectionView;
|
||||
NSMutableArray *_data;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation ViewController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark UIViewController.
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
|
||||
self.title = @"Cat Deals";
|
||||
|
||||
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||
|
||||
_collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
||||
_collectionView.asyncDataSource = self;
|
||||
_collectionView.asyncDelegate = self;
|
||||
_collectionView.backgroundColor = [UIColor grayColor];
|
||||
_collectionView.leadingScreensForBatching = 2;
|
||||
|
||||
ASRangeTuningParameters fetchDataTuning;
|
||||
fetchDataTuning.leadingBufferScreenfuls = 2;
|
||||
fetchDataTuning.trailingBufferScreenfuls = 1;
|
||||
[_collectionView setTuningParameters:fetchDataTuning forRangeType:ASLayoutRangeTypeFetchData];
|
||||
|
||||
ASRangeTuningParameters preRenderTuning;
|
||||
preRenderTuning.leadingBufferScreenfuls = 1;
|
||||
preRenderTuning.trailingBufferScreenfuls = 0.5;
|
||||
[_collectionView setTuningParameters:preRenderTuning forRangeType:ASLayoutRangeTypeDisplay];
|
||||
|
||||
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
||||
[_collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionFooter];
|
||||
|
||||
_data = [[NSMutableArray alloc] init];
|
||||
|
||||
self.navigationItem.leftItemsSupplementBackButton = YES;
|
||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadTapped)];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
[self.view addSubview:_collectionView];
|
||||
[self fetchMoreCatsWithCompletion:nil];
|
||||
}
|
||||
|
||||
- (void)fetchMoreCatsWithCompletion:(void (^)(BOOL))completion {
|
||||
if (kSimulateWebResponse) {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void(^mockWebService)() = ^{
|
||||
NSLog(@"ViewController \"got data from a web service\"");
|
||||
ViewController *strongSelf = weakSelf;
|
||||
if (strongSelf != nil)
|
||||
{
|
||||
NSLog(@"ViewController is not nil");
|
||||
[strongSelf appendMoreItems:kBatchSize completion:completion];
|
||||
NSLog(@"ViewController finished updating collectionView");
|
||||
}
|
||||
else {
|
||||
NSLog(@"ViewController is nil - won't update collectionView");
|
||||
}
|
||||
};
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kWebResponseDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), mockWebService);
|
||||
} else {
|
||||
[self appendMoreItems:kBatchSize completion:completion];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)appendMoreItems:(NSInteger)numberOfNewItems completion:(void (^)(BOOL))completion {
|
||||
NSArray *newData = [self getMoreData:numberOfNewItems];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[_collectionView performBatchUpdates:^{
|
||||
[_data addObjectsFromArray:newData];
|
||||
NSArray *addedIndexPaths = [self indexPathsForObjects:newData];
|
||||
[_collectionView insertItemsAtIndexPaths:addedIndexPaths];
|
||||
} completion:completion];
|
||||
});
|
||||
}
|
||||
|
||||
- (NSArray *)getMoreData:(NSInteger)count {
|
||||
NSMutableArray *data = [NSMutableArray array];
|
||||
for (int i = 0; i < count; i++) {
|
||||
[data addObject:[ItemViewModel randomItem]];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
- (NSArray *)indexPathsForObjects:(NSArray *)data {
|
||||
NSMutableArray *indexPaths = [NSMutableArray array];
|
||||
NSInteger section = 0;
|
||||
for (ItemViewModel *viewModel in data) {
|
||||
NSInteger item = [_data indexOfObject:viewModel];
|
||||
NSAssert(item < [_data count] && item != NSNotFound, @"Item should be in _data");
|
||||
[indexPaths addObject:[NSIndexPath indexPathForItem:item inSection:section]];
|
||||
}
|
||||
return indexPaths;
|
||||
}
|
||||
|
||||
- (void)viewWillLayoutSubviews
|
||||
{
|
||||
_collectionView.frame = self.view.bounds;
|
||||
}
|
||||
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
||||
[_collectionView.collectionViewLayout invalidateLayout];
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)reloadTapped
|
||||
{
|
||||
[_collectionView reloadData];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark ASCollectionView data source.
|
||||
|
||||
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
ItemViewModel *viewModel = _data[indexPath.item];
|
||||
return [[ItemNode alloc] initWithViewModel:viewModel];
|
||||
}
|
||||
|
||||
- (ASCellNode *)collectionView:(UICollectionView *)collectionView nodeForSupplementaryElementOfKind:(nonnull NSString *)kind atIndexPath:(nonnull NSIndexPath *)indexPath {
|
||||
if ([kind isEqualToString:UICollectionElementKindSectionHeader] && indexPath.section == 0) {
|
||||
return [[BlurbNode alloc] init];
|
||||
} else if ([kind isEqualToString:UICollectionElementKindSectionFooter] && indexPath.section == 0) {
|
||||
return [[LoadingNode alloc] init];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
|
||||
if (section == 0) {
|
||||
CGFloat width = CGRectGetWidth(self.view.frame) - 2 * kHorizontalSectionPadding;
|
||||
return CGSizeMake(width, [BlurbNode desiredHeightForWidth:width]);
|
||||
}
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
|
||||
if (section == 0) {
|
||||
CGFloat width = CGRectGetWidth(self.view.frame);
|
||||
return CGSizeMake(width, [LoadingNode desiredHeightForWidth:width]);
|
||||
}
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
- (ASSizeRange)collectionView:(ASCollectionView *)collectionView constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath {
|
||||
CGFloat collectionViewWidth = CGRectGetWidth(self.view.frame) - 2 * kHorizontalSectionPadding;
|
||||
CGFloat oneItemWidth = [ItemNode preferredViewSize].width;
|
||||
NSInteger numColumns = floor(collectionViewWidth / oneItemWidth);
|
||||
// Number of columns should be at least 1
|
||||
numColumns = MAX(1, numColumns);
|
||||
|
||||
CGFloat totalSpaceBetweenColumns = (numColumns - 1) * kHorizontalSectionPadding;
|
||||
CGFloat itemWidth = ((collectionViewWidth - totalSpaceBetweenColumns) / numColumns);
|
||||
CGSize itemSize = [ItemNode sizeForWidth:itemWidth];
|
||||
return ASSizeRangeMake(itemSize, itemSize);
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return [_data count];
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (void)collectionViewLockDataSource:(ASCollectionView *)collectionView
|
||||
{
|
||||
// lock the data source
|
||||
// The data source should not be change until it is unlocked.
|
||||
}
|
||||
|
||||
- (void)collectionViewUnlockDataSource:(ASCollectionView *)collectionView
|
||||
{
|
||||
// unlock the data source to enable data source updating.
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView willBeginBatchFetchWithContext:(ASBatchContext *)context
|
||||
{
|
||||
NSLog(@"fetch additional content");
|
||||
[self fetchMoreCatsWithCompletion:^(BOOL finished){
|
||||
[context completeBatchFetching:YES];
|
||||
}];
|
||||
}
|
||||
|
||||
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
|
||||
return UIEdgeInsetsMake(kVerticalSectionPadding, kHorizontalSectionPadding, kVerticalSectionPadding, kHorizontalSectionPadding);
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
NSLog(@"ViewController is deallocing");
|
||||
}
|
||||
|
||||
@end
|
||||
19
examples/CatDealsCollectionView/Sample/main.m
Normal file
19
examples/CatDealsCollectionView/Sample/main.m
Normal file
@@ -0,0 +1,19 @@
|
||||
/* This file provided by Facebook is for non-commercial testing and evaluation
|
||||
* purposes only. Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppDelegate.h"
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
@autoreleasepool {
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user