Skip to content

Commit 8ce3c7f

Browse files
committed
Skeleton style that adds different cell styles
1 parent e411fb1 commit 8ce3c7f

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

Somo.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Pod::Spec.new do |s|
33

44
s.name = "Somo"
5-
s.version = "0.6.5"
5+
s.version = "0.7.0"
66
s.summary = "Somo is a Skeleton-style animation library that's simple enough."
77

88
s.homepage = "https://github.com/xorshine/Somo"

SomoDemo/SomoDemo/Somo/SomoDataSourceProvider.h

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
#import <Foundation/Foundation.h>
1212
#import <UIKit/UIKit.h>
13+
@protocol SomoSkeletonLayoutProtocol;
14+
15+
typedef UITableViewCell<SomoSkeletonLayoutProtocol> *(^SomoTableViewCellBlock)(UITableView *tableview, NSIndexPath *indexPath);
16+
typedef UICollectionViewCell<SomoSkeletonLayoutProtocol> *(^SomoCollectionViewCellBlock)(UICollectionView *tableview, NSIndexPath *indexPath);
1317

1418
@interface SomoDataSourceProvider : NSObject<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
1519

@@ -18,7 +22,16 @@
1822
*/
1923
@property (assign, nonatomic) NSInteger numberOfRowsInSection;
2024

25+
/**
26+
If you have only one cell style, use the following method
27+
*/
2128
- (instancetype)initWithCellReuseIdentifier:(NSString *)reuseIdentifier;
2229
+ (instancetype)dataSourceProviderWithCellReuseIdentifier:(NSString *)reuseIdentifier;
2330

31+
/**
32+
If you have different cell styles, use the following method
33+
*/
34+
- (instancetype)initWithTableViewCellBlock:(SomoTableViewCellBlock)block;
35+
- (instancetype)initWithCollectionViewCellBlock:(SomoCollectionViewCellBlock)block;
36+
2437
@end

SomoDemo/SomoDemo/Somo/SomoDataSourceProvider.m

+28-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
@implementation SomoDataSourceProvider
1515
{
1616
NSString * _reuseIdentifier;
17+
SomoTableViewCellBlock _tableViewCellBlock;
18+
SomoCollectionViewCellBlock _collectionViewCellBlock;
1719
}
1820

1921
- (instancetype)initWithCellReuseIdentifier:(NSString *)reuseIdentifier{
@@ -28,13 +30,32 @@ + (instancetype)dataSourceProviderWithCellReuseIdentifier:(NSString *)reuseIdent
2830
return [[[self class] alloc] initWithCellReuseIdentifier:reuseIdentifier];
2931
}
3032

33+
- (instancetype)initWithTableViewCellBlock:(SomoTableViewCellBlock)block{
34+
if (self = [super init]) {
35+
_tableViewCellBlock = block;
36+
_numberOfRowsInSection = 30;
37+
}
38+
return self;
39+
}
40+
41+
- (instancetype)initWithCollectionViewCellBlock:(SomoCollectionViewCellBlock)block{
42+
if (self = [super init]) {
43+
_collectionViewCellBlock = block;
44+
_numberOfRowsInSection = 30;
45+
}
46+
return self;
47+
}
48+
3149
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
3250
return self.numberOfRowsInSection;
3351
}
3452

3553
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
36-
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:_reuseIdentifier forIndexPath:indexPath];
37-
return cell;
54+
if (_reuseIdentifier) {
55+
return [tableView dequeueReusableCellWithIdentifier:_reuseIdentifier forIndexPath:indexPath];
56+
}else{
57+
return _tableViewCellBlock(tableView,indexPath);
58+
}
3859
}
3960

4061
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
@@ -48,8 +69,11 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
4869
}
4970

5071
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
51-
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:_reuseIdentifier forIndexPath:indexPath];
52-
return cell;
72+
if (_reuseIdentifier) {
73+
return [collectionView dequeueReusableCellWithReuseIdentifier:_reuseIdentifier forIndexPath:indexPath];
74+
}else{
75+
return _collectionViewCellBlock(collectionView, indexPath);
76+
}
5377
}
5478

5579
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{

0 commit comments

Comments
 (0)