-
Notifications
You must be signed in to change notification settings - Fork 0
/
FRPCell.m
62 lines (49 loc) · 1.58 KB
/
FRPCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// FRPCell.m
// FunctionalReactivePixels
//
// Created by Barak Cohen on 1/4/14.
// Copyright (c) 2014 Barak Cohen. All rights reserved.
//
#import "FRPCell.h"
#import "FRPPhotoModel.h"
#import <UIKit/UIKit.h>
@interface FRPCell()
@property(nonatomic,weak)UIImageView *imageView;
@property(nonatomic,strong)RACDisposable *subscription;
@end
@implementation FRPCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (!self) return nil;
self.backgroundColor = [UIColor darkGrayColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.contentView addSubview:imageView];
self.imageView = imageView;
return self;
}
-(void)setPhotoModel:(FRPPhotoModel *)photoModel {
self.subscription = [[[RACObserve(photoModel, thumbnailData)
filter:^BOOL(id value) {
return value != nil;
}]
map:^id(id value) {
return [UIImage imageWithData:value];
}]
setKeyPath:@keypath(self.imageView, image) onObject:self.imageView];
}
-(void)prepareForReuse{
[super prepareForReuse];
[self.subscription dispose], self.subscription = nil;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end