Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @interface BBTradeItemNode ()
- @property (strong, nonatomic) ASDisplayNode *tradeTyprDisplayNode;
- @property (strong, nonatomic) ASTextNode *tradeTitleNode;
- @property (strong, nonatomic) ASTextNode *tradeAmountNode;
- @property (strong, nonatomic) ASTextNode *tradeCloseDateNode;
- @property (strong, nonatomic) ASNetworkImageNode *thumbnailImageNode;
- @property (strong, nonatomic) ASImageNode *hotIconImageNode;
- @property (strong, nonatomic) BBItem *tradeItem;
- @end
- @implementation BBTradeItemNode
- - (instancetype)initWithTrade:(BBItem*)trade {
- self = [super init];
- if (self) {
- _tradeItem = trade;
- self.backgroundColor = [UIColor whiteColor];
- self.clipsToBounds = YES;
- _watchButtonNode = [[ASButtonNode alloc]init];
- _watchButtonNode.style.preferredSize = CGSizeMake(30, 30);
- _tradeTyprDisplayNode = [[ASDisplayNode alloc] init];
- _tradeTyprDisplayNode.style.preferredSize = CGSizeMake(4, 80);
- _thumbnailImageNode = [[ASNetworkImageNode alloc] init];
- _thumbnailImageNode.placeholderEnabled = YES;
- _thumbnailImageNode.placeholderColor = [UIColor colorWithHex:BACKGROUNDCOLOR_GREY];
- _thumbnailImageNode.defaultImage = [UIImage imageNamed:@"Temp Image"];
- _thumbnailImageNode.URL = [NSURL imageURLforRawURLString:_tradeItem.thumbnailUrl size:Small];
- _thumbnailImageNode.style.preferredSize = CGSizeMake(80, 80);
- _tradeTitleNode = [[ASTextNode alloc] init];
- _tradeTitleNode.style.maxWidth = ASDimensionMake([DeviceHardware platformType] == DeviceHardwarePlatformType_iPad ? 182 : [UIScreen mainScreen].bounds.size.width - 138);
- _tradeTitleNode.attributedText = [NSAttributedString attributedStringForTitleText:_tradeItem.tradeTitle];
- _tradeAmountNode.maximumNumberOfLines = 2;
- _tradeCloseDateNode = [[ASTextNode alloc] init];
- _tradeCloseDateNode.attributedText = [NSAttributedString attributedStringForDateText:[NSString stringWithFormat:@"Ends: %@", _tradeItem.twentFourHourCloseDate]];
- _tradeAmountNode = [[ASTextNode alloc] init];
- _tradeAmountNode.attributedText = [NSAttributedString attributedStringForAmountText:[BBUtils getDisplayAmountStringWithValue:_tradeItem.bidAmount Currency:_tradeItem.tradeCurrency]];
- _tradeAmountNode.placeholderEnabled = YES;
- _tradeAmountNode.placeholderFadeDuration = 0.15;
- _tradeAmountNode.placeholderColor = [UIColor colorWithWhite:0.777 alpha:1.0];
- [self addSubnode:self.thumbnailImageNode];
- [self addSubnode:self.tradeTyprDisplayNode];
- [self addSubnode:self.tradeTitleNode];
- [self addSubnode:self.tradeCloseDateNode];
- [self addSubnode:self.tradeAmountNode];
- [self addSubnode:self.watchButtonNode];
- switch (_tradeItem.type){
- case AUCTION_ID:
- case BUY_NOW_AUCTION:
- _tradeTyprDisplayNode.view.backgroundColor = [UIColor colorWithHex:LISTING_TYPE_COLOR_AUCTION];
- break;
- case CLASSIFIED_ID:
- _tradeTyprDisplayNode.view.backgroundColor = [UIColor colorWithHex:LISTING_TYPE_COLOR_CLASSIFIED];
- break;
- default:
- _tradeTyprDisplayNode.view.backgroundColor = [UIColor colorWithHex:LISTING_TYPE_COLOR_BUY_NOW];
- break;
- }
- }
- if(_tradeItem.hotSelling){
- _hotIconImageNode = [[ASImageNode alloc] init];
- _hotIconImageNode.style.preferredSize = CGSizeMake(40, 40);
- _hotIconImageNode.image = [UIImage imageNamed:@"Hot Selling Item"];
- [self addSubnode:_hotIconImageNode];
- }
- return self;
- }
- #pragma mark - Node Layout
- - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
- ASStackLayoutSpec *horizontalTitleAndButtonSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
- spacing:0
- justifyContent:ASStackLayoutJustifyContentSpaceBetween
- alignItems:ASStackLayoutAlignItemsStart
- children:@[_tradeTitleNode, _watchButtonNode]];
- horizontalTitleAndButtonSpec.style.width = ASDimensionMake([DeviceHardware platformType] == DeviceHardwarePlatformType_iPad ? 219 : [UIScreen mainScreen].bounds.size.width - 100);
- horizontalTitleAndButtonSpec.style.flexGrow = 1.0;
- horizontalTitleAndButtonSpec.style.flexShrink = 1.0;
- ASStackLayoutSpec *horizontalCloseDateeAndAmountSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
- spacing:0
- justifyContent:ASStackLayoutJustifyContentSpaceBetween
- alignItems:ASStackLayoutAlignItemsStart
- children:@[_tradeCloseDateNode, _tradeAmountNode]];
- horizontalCloseDateeAndAmountSpec.style.width = ASDimensionMake([DeviceHardware platformType] == DeviceHardwarePlatformType_iPad ? 219 : [UIScreen mainScreen].bounds.size.width - 100);
- ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
- spacing:0
- justifyContent:ASStackLayoutJustifyContentSpaceBetween
- alignItems:ASStackLayoutAlignItemsStart
- children:@[horizontalTitleAndButtonSpec, horizontalCloseDateeAndAmountSpec]];
- verticalStack.style.height = ASDimensionMake(80);
- ASInsetLayoutSpec *insrtSpec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(8, 8, 8, 8) child:verticalStack];
- ASStackLayoutSpec *headerHorizontalStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
- spacing:0
- justifyContent:ASStackLayoutJustifyContentStart
- alignItems:ASStackLayoutAlignItemsStart
- children:@[_tradeTyprDisplayNode, _thumbnailImageNode, insrtSpec]];
- headerHorizontalStack.style.height = ASDimensionMake(80);
- ASOverlayLayoutSpec *hotSellingoverlaySpec;
- if(_hotIconImageNode){
- ASStackLayoutSpec *hotSellingSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
- spacing:0
- justifyContent:ASStackLayoutJustifyContentStart
- alignItems:ASStackLayoutAlignItemsStart
- children:@[_hotIconImageNode]];
- ASInsetLayoutSpec *overlayInsetSpec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(0, 4, 0, 0) child:hotSellingSpec];
- hotSellingoverlaySpec = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:headerHorizontalStack overlay:overlayInsetSpec];
- }
- return _hotIconImageNode ? hotSellingoverlaySpec : headerHorizontalStack;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement