forked from andrewwiik/Intelix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITXNCGroupBackgroundView.m
143 lines (117 loc) · 4.18 KB
/
ITXNCGroupBackgroundView.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#import <Intelix/ITXNCGroupBackgroundView.h>
static CGFloat headerHeight = 20;
@implementation ITXNCGroupBackgroundView
- (id)initWithFrame:(CGRect)frame {
// HBLogInfo(@"Method #120");
self = [super initWithFrame:frame];
if (self) {
_topView = [[ITXAnimatedSeperatedCornersView alloc] init];
_bottomView = [[ITXAnimatedSeperatedCornersView alloc] init];
_containerView = [[UIView alloc] init];
[_containerView addSubview:_topView];
[_containerView addSubview:_bottomView];
_backdropView = [NSClassFromString(@"MTMaterialView") materialViewWithRecipe:1 options:2];
_backdropView.maskView = _containerView;
_backdropView.groupName = @"NCNotificationListCombinedListViewController.blur";
// _backdropView.allowsInPlaceFiltering = YES;
// _backdropView.backgroundColor = [UIColor redColor];
[self addSubview:_backdropView];
_middleFrame = CGRectNull;
_forcedFrame = self.frame;
_configuration = [ITXNCGroupBackgroundConfiguration defaultConfiguration];
[self _resetRevealOverrides];
}
return self;
}
- (void)setMiddleFrame:(CGRect)frame {
// HBLogInfo(@"Method #121");
if (!CGRectEqualToRect(frame, _middleFrame)) {
_middleFrame = frame;
_previousFrame = CGRectZero;
[self layoutSubviews];
}
}
- (void)setForcedFrame:(CGRect)frame {
// HBLogInfo(@"Method #122");
if (!CGRectEqualToRect(frame, _forcedFrame)) {
_forcedFrame = frame;
[self layoutSubviews];
}
}
- (void)setFrame:(CGRect)frame {
// HBLogInfo(@"Method #123");
[super setFrame:frame];
[self layoutSubviews];
}
- (void)doConfigUpdate {
CGRect bounds = CGRectMake(0,0,self.bounds.size.width,self.bounds.size.height);
_backdropView.frame = bounds;
_containerView.frame = bounds;
ITXNCGroupBackgroundConfiguration *config = _configuration;
_topView.topCornerRadius = config.topRadius;
_topView.bottomCornerRadius = config.middleTopRadius;
_topView.bottomInset = config.middleTopInset;
_bottomView.topCornerRadius = config.middleBottomRadius;
_bottomView.bottomCornerRadius = config.bottomRadius;
_bottomView.topInset = config.middleBottomInset;
CGRect middleFrame = _middleFrame;
if (CGRectIsNull(middleFrame)) middleFrame = CGRectMake(0, bounds.size.height*0.5, bounds.size.width, 0);
_topView.frame = CGRectMake(0, 0 + (_isSectionBackground ? headerHeight : 0), bounds.size.width, middleFrame.origin.y - (_isSectionBackground ? headerHeight : 0));
CGFloat bottomY = middleFrame.origin.y + middleFrame.size.height;
_bottomView.frame = CGRectMake(0, bottomY, bounds.size.width, bounds.size.height - bottomY);
[_topView layoutSubviews];
[_bottomView layoutSubviews];
_previousFrame = self.frame;
}
- (void)layoutSubviews {
// HBLogInfo(@"Method #124");
[super layoutSubviews];
//_isSectionBackground = NO;
// Andy Remove this after testing
//_forcedFrame = self.frame;
// if (!CGRectIsNull(_forcedFrame))
//CGRect forcedFrame = _forcedFrame;
//self.frame = _forcedFrame;
if (_previousFrame.size.width != self.frame.size.width || _previousFrame.size.height != self.frame.size.height || _backdropView.bounds.size.height != self.frame.size.height) {
[self doConfigUpdate];
}
}
+ (NSString *)elementKind {
return @"ITXNCGroupBackgroundView";
}
- (void)setOverrideAlpha:(CGFloat)alpha {
// HBLogInfo(@"Method #125");
_overrideAlpha = alpha;
if (!self.isTopSection) self.alpha = _overrideAlpha;
}
- (void)setOverrideCenter:(CGPoint)center {
// HBLogInfo(@"Method #126");
_overrideCenter = center;
if (!self.isTopSection) self.center = _overrideCenter;
}
- (void)prepareForReuse {
// HBLogInfo(@"Method #127");
_isSectionBackground = NO;
_isTopSection = NO;
[super prepareForReuse];
[self _resetRevealOverrides];
}
- (void)_resetRevealOverrides {
// HBLogInfo(@"Method #128");
_overrideAlpha = CGFLOAT_MAX;
_overrideCenter = CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX);
_shouldOverrideForReveal = NO;
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)attributes {
// HBLogInfo(@"Method #129");
[super applyLayoutAttributes:attributes];
if (_shouldOverrideForReveal && !self.isTopSection) {
if (_overrideAlpha != CGFLOAT_MAX) {
[self setAlpha:_overrideAlpha];
}
if (_overrideCenter.x != CGFLOAT_MAX && _overrideCenter.y != CGFLOAT_MAX) {
[self setCenter:_overrideCenter];
}
}
}
@end