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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
//
// TAPProfileViewController.m
// TapTalk
//
// Created by Welly Kencana on 30/10/18.
// Copyright © 2018 Moselo. All rights reserved.
//
#import "TAPProfileViewController.h"
#import "TAPProfileView.h"
#import "TAPProfileCollectionViewCell.h"
#import "TAPImageCollectionViewCell.h"
@interface TAPProfileViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (strong, nonatomic) TAPProfileView *profileView;
@end
@implementation TAPProfileViewController
#pragma mark - Lifecycle
- (void)loadView {
[super loadView];
_profileView = [[TAPProfileView alloc] initWithFrame:[TAPBaseView frameWithoutNavigationBar]];
[self.view addSubview:self.profileView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.profileView.collectionView.delegate = self;
self.profileView.collectionView.dataSource = self;
[self.profileView.navigationBackButton addTarget:self action:@selector(backButtonDidTapped) forControlEvents:UIControlEventTouchUpInside];
[self.profileView.backButton addTarget:self action:@selector(backButtonDidTapped) forControlEvents:UIControlEventTouchUpInside];
// [self.profileView.profileImageView setImageWithURLString:TAP_DUMMY_IMAGE_URL]; //WK Temp - Dummy image url
[self.profileView.profileImageView setImageWithURLString:self.room.imageURL.thumbnail]; //WK Temp - Dummy image url
self.profileView.nameLabel.text = self.room.name;
self.profileView.navigationNameLabel.text = self.room.name;
}
#pragma mark - Data Source
#pragma mark CollectionView
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
CGSize cellSize = CGSizeMake(CGRectGetWidth([UIScreen mainScreen].bounds), 56.0f);
return cellSize;
}
else if (indexPath.section == 1) {
CGSize cellSize = CGSizeMake((CGRectGetWidth([UIScreen mainScreen].bounds) - 3.0f) / 3.0f, (CGRectGetWidth([UIScreen mainScreen].bounds) - 3.0f) / 3.0f);
return cellSize;
}
CGSize size = CGSizeZero;
return size;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section {
if (section == 1) {
UIEdgeInsets cellInsets = UIEdgeInsetsMake(0.0f, 0.5f, 0.0f, 0.5f);
return cellInsets;
}
return UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
if (section == 1) {
return 1.0f;
}
return 0.0f;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
minimumLineSpacingForSectionAtIndex:(NSInteger)section {
if (section == 1) {
return 1.0f;
}
return 0.0f;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section {
if (section == 0) {
return 4;
}
else if (section == 1) {
return 40; //WK Temp
}
return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
NSString *cellID = @"TAPProfileCollectionViewCell";
[collectionView registerClass:[TAPProfileCollectionViewCell class] forCellWithReuseIdentifier:cellID];
TAPProfileCollectionViewCell *cell = (TAPProfileCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
if (indexPath.item == 0) {
[cell setProfileCollectionViewCellType:profileCollectionViewCellTypeNotification];
[cell showSeparatorView:YES];
}
else if (indexPath.item == 1) {
[cell setProfileCollectionViewCellType:profileCollectionViewCellTypeConversationColor];
[cell showSeparatorView:YES];
}
else if (indexPath.item == 2) {
[cell setProfileCollectionViewCellType:profileCollectionViewCellTypeBlock];
[cell showSeparatorView:YES];
}
else if (indexPath.item == 3) {
[cell setProfileCollectionViewCellType:profileCollectionViewCellTypeClearChat];
[cell showSeparatorView:NO];
}
return cell;
}
else if (indexPath.section == 1) {
NSString *cellID = @"TAPImageCollectionViewCell";
[collectionView registerClass:[TAPImageCollectionViewCell class] forCellWithReuseIdentifier:cellID];
TAPImageCollectionViewCell *cell = (TAPImageCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
if (cell == nil) {
NSLog(@"===>");
}
[cell setImageCollectionViewCellWithURL:TAP_DUMMY_IMAGE_URL]; //WK Temp - Dummy image URL
return cell;
}
static NSString *cellID = @"UICollectionViewCell";
[collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cellID];
UICollectionViewCell *cell = (UICollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
return cell;
}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *attributesInRect = [NSArray array];
return attributesInRect;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
if (section == 1) {
CGSize headerSize = CGSizeMake(CGRectGetWidth([UIScreen mainScreen].bounds), 30.0f);
return headerSize;
}
return CGSizeZero;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
return CGSizeZero;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
if (kind == UICollectionElementKindSectionHeader) {
if (indexPath.section == 1) {
NSString *headerID = @"ShareMediaHeaderView";
[collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:kind withReuseIdentifier:headerID];
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID forIndexPath:indexPath];
UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:indexPath];
[headerView preferredLayoutAttributesFittingAttributes:attributes];
headerView.backgroundColor = [TAPUtil getColor:TAP_COLOR_WHITE_F3];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16.0f, 0.0f, CGRectGetWidth([UIScreen mainScreen].bounds) - 16.0f - 16.0f, CGRectGetHeight(headerView.frame))];
titleLabel.text = @"SHARED MEDIA";
titleLabel.textColor = [TAPUtil getColor:TAP_COLOR_MOSELO_PURPLE];
titleLabel.font = [UIFont fontWithName:TAP_FONT_LATO_BOLD size:11.0f];
[headerView addSubview:titleLabel];
return headerView;
}
NSString *headerID = @"headerView";
[collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:kind withReuseIdentifier:headerID];
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID forIndexPath:indexPath];
UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:indexPath];
[headerView preferredLayoutAttributesFittingAttributes:attributes];
if (headerView == nil) {
headerView = [[UICollectionReusableView alloc] initWithFrame:CGRectZero];
}
return headerView;
}
else if (kind == UICollectionElementKindSectionFooter) {
NSString *footerID = @"footerView";
[collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:kind withReuseIdentifier:footerID];
UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:footerID forIndexPath:indexPath];
UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:indexPath];
[footerView preferredLayoutAttributesFittingAttributes:attributes];
if (footerView == nil) {
footerView = [[UICollectionReusableView alloc] initWithFrame:CGRectZero];
}
return footerView;
}
return nil;
}
#pragma mark - Delegate
#pragma mark CollectionView
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
}
#pragma mark ScrollView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat topPadding = 0.0f;
if (IS_IPHONE_X_FAMILY) {
topPadding = [TAPUtil currentDeviceStatusBarHeight];
}
CGFloat meetingPoint = 44.0f + [TAPUtil currentDeviceStatusBarHeight];
if (IS_IPHONE_X_FAMILY) {
meetingPoint = 44.0f; //WK Note - Because the image Y position is max Y of status bar for iphone X.
}
CGFloat scrollProgress = 1 + ((scrollView.contentOffset.y + meetingPoint) / (CGRectGetHeight(self.profileView.profileImageView.frame) - meetingPoint));
if (scrollProgress < 0.0f) {
scrollProgress = 0.0f;
}
else if (scrollProgress > 1.0f) {
scrollProgress = 1.0f;
}
//CHANGE FRAME nameLabel
CGRect nameLabelFrame = self.profileView.nameLabel.frame;
CGFloat nameLabelYPosition = self.profileView.nameLabelYPosition - (CGRectGetHeight(self.profileView.profileImageView.frame) - meetingPoint) * scrollProgress;
nameLabelFrame.origin.y = nameLabelYPosition;
self.profileView.nameLabel.frame = nameLabelFrame;
//CHANGE FRAME navigationBarView
CGRect navigationBarViewFrame = self.profileView.navigationBarView.frame;
CGFloat navigationBarViewYPosition = -self.profileView.navigationBarHeight + topPadding + ((self.profileView.navigationBarHeight - topPadding) * scrollProgress);
navigationBarViewFrame.origin.y = navigationBarViewYPosition;
self.profileView.navigationBarView.frame = navigationBarViewFrame;
//CHANGE FRAME navigationNameLabel
CGRect navigationNameLabelFrame = self.profileView.navigationNameLabel.frame;
CGFloat navigationNameLabelYPosition = self.profileView.navigationNameLabelYPosition - CGRectGetHeight(self.profileView.profileImageView.frame) * scrollProgress;
navigationNameLabelFrame.origin.y = navigationNameLabelYPosition;
self.profileView.navigationNameLabel.frame = navigationNameLabelFrame;
self.profileView.navigationBackButton.alpha = scrollProgress;
self.profileView.backButton.alpha = 1 - scrollProgress;
self.profileView.collectionView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:scrollProgress];
}
#pragma mark - Custom Method
- (void)backButtonDidTapped {
[self.navigationController popViewControllerAnimated:YES];
}
@end