19
19
#import " lVstate.h"
20
20
#import " lVgc.h"
21
21
#import " LVFlowLayout.h"
22
+ #import " LVRefreshHeader.h"
22
23
23
24
24
- // lua 对应的数据 key
25
+ #define NONE_REFRESH 0
26
+ #define NATIVE_REFRESH 1
27
+ #define EMPTY_REFRESH 2
25
28
26
29
27
30
@interface LVCollectionView ()
@@ -30,6 +33,32 @@ @interface LVCollectionView ()
30
33
31
34
32
35
@implementation LVCollectionView
36
+ // 下拉刷新
37
+ -(void ) lv_initEmptyRefreshHeader {// 初始化下拉刷新功能
38
+ LVRefreshHeader* refreshHeader = [[LVRefreshHeader alloc ] init ];
39
+ self.lv_refresh_header = refreshHeader;
40
+
41
+ __weak typeof (self) weakSelf = self;
42
+ refreshHeader.refreshingBlock = ^(){
43
+ [weakSelf lv_refreshHeaderToRefresh ];
44
+ };
45
+ }
46
+
47
+ - (void ) lv_hiddenRefreshHeader : (BOOL ) hidden {
48
+ self.lv_refresh_header .hidden = hidden;
49
+ }
50
+
51
+ - (void ) lv_beginRefreshing {// 进入刷新状态
52
+ [self .lv_refresh_header beginRefreshing ];
53
+ }
54
+
55
+ - (void ) lv_endRefreshing {// 结束刷新状态
56
+ [self .lv_refresh_header endRefreshing ];
57
+ }
58
+
59
+ - (BOOL ) lv_isRefreshing {// 是否正在刷新
60
+ return self.lv_refresh_header .isRefreshing ;
61
+ }
33
62
34
63
-(id ) init : (lv_State*) l {
35
64
LVFlowLayout* flowLayout = [[LVFlowLayout alloc ] init ];
@@ -93,12 +122,22 @@ - (void) luaviewScrollToTopWithAnimated:(BOOL)animated{
93
122
94
123
95
124
#pragma -mark lvNewCollectionView
96
- static int lvNewCollectionView0 (lv_State *L, BOOL refresh) {
125
+ static int lvNewCollectionView0 (lv_State *L, int refresh) {
97
126
Class c = [LVUtil upvalueClass: L defaultClass: [LVCollectionView class ]];
98
127
99
128
LVCollectionView* tableView = [[c alloc ] init: L];
100
- if ( refresh ) {
101
- [tableView lv_initRefreshHeader ];
129
+
130
+ switch (refresh){
131
+ case NONE_REFRESH:
132
+ break ;
133
+ case NATIVE_REFRESH:
134
+ [tableView lv_initRefreshHeader ];
135
+ break ;
136
+
137
+ case EMPTY_REFRESH:
138
+ [tableView lv_initEmptyRefreshHeader ];
139
+ break ;
140
+
102
141
}
103
142
104
143
NEW_USERDATA (userData, View);
@@ -120,11 +159,15 @@ static int lvNewCollectionView0 (lv_State *L, BOOL refresh) {
120
159
}
121
160
122
161
static int lvNewCollectionView (lv_State *L) {
123
- return lvNewCollectionView0 (L, NO );
162
+ return lvNewCollectionView0 (L, NONE_REFRESH );
124
163
}
125
164
126
165
static int lvNewRefreshCollectionView (lv_State *L) {
127
- return lvNewCollectionView0 (L, YES );
166
+ return lvNewCollectionView0 (L, NATIVE_REFRESH);
167
+ }
168
+
169
+ static int lvNewEmptyRefreshCollectionView (lv_State *L) {
170
+ return lvNewCollectionView0 (L, EMPTY_REFRESH);
128
171
}
129
172
130
173
static int reload (lv_State *L) {
@@ -255,9 +298,16 @@ +(int) lvClassDefine:(lv_State *)L globalName:(NSString*) globalName{
255
298
// CollectionView
256
299
[LVUtil reg: L clas: self cfunc: lvNewCollectionView globalName: globalName defaultName: @" CollectionView" ];
257
300
258
- // RefreshCollectionView
259
- NSString * refreshName = [NSString stringWithFormat: @" Refresh%@ " ,globalName];
260
- [LVUtil reg: L clas: self cfunc: lvNewRefreshCollectionView globalName: refreshName defaultName: @" RefreshCollectionView" ];
301
+ {
302
+ // RefreshCollectionView
303
+ NSString * refreshName = [NSString stringWithFormat: @" Refresh%@ " ,globalName];
304
+ [LVUtil reg: L clas: self cfunc: lvNewRefreshCollectionView globalName: refreshName defaultName: @" RefreshCollectionView" ];
305
+ }
306
+ {
307
+ // RefreshCollectionView
308
+ NSString * refreshName = [NSString stringWithFormat: @" EmptyRefresh%@ " ,globalName];
309
+ [LVUtil reg: L clas: self cfunc: lvNewEmptyRefreshCollectionView globalName: refreshName defaultName: @" EmptyRefreshCollectionView" ];
310
+ }
261
311
262
312
const struct lvL_reg memberFunctions [] = {
263
313
{" reload" , reload},
0 commit comments