8000 支持空刷新CollectionView · newcoderzhang/LuaViewSDK@e56f4f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit e56f4f3

Browse files
author
城西
committed
支持空刷新CollectionView
1 parent d8f9f64 commit e56f4f3

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

IOS/LuaViewSDK/Classes/lvsdk/LVCollectionView.m

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
#import "lVstate.h"
2020
#import "lVgc.h"
2121
#import "LVFlowLayout.h"
22+
#import "LVRefreshHeader.h"
2223

2324

24-
// lua 对应的数据 key
25+
#define NONE_REFRESH 0
26+
#define NATIVE_REFRESH 1
27+
#define EMPTY_REFRESH 2
2528

2629

2730
@interface LVCollectionView ()
@@ -30,6 +33,32 @@ @interface LVCollectionView ()
3033

3134

3235
@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+
}
3362

3463
-(id) init:(lv_State*) l {
3564
LVFlowLayout* flowLayout = [[LVFlowLayout alloc] init];
@@ -93,12 +122,22 @@ - (void) luaviewScrollToTopWithAnimated:(BOOL)animated{
93122

94123

95124
#pragma -mark lvNewCollectionView
96-
static int lvNewCollectionView0 (lv_State *L, BOOL refresh) {
125+
static int lvNewCollectionView0 (lv_State *L, int refresh) {
97126
Class c = [LVUtil upvalueClass:L defaultClass:[LVCollectionView class]];
98127

99128
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+
102141
}
103142

104143
NEW_USERDATA(userData, View);
@@ -120,11 +159,15 @@ static int lvNewCollectionView0 (lv_State *L, BOOL refresh) {
120159
}
121160

122161
static int lvNewCollectionView (lv_State *L) {
123-
return lvNewCollectionView0(L, NO);
162+
return lvNewCollectionView0(L, NONE_REFRESH);
124163
}
125164

126165
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);
128171
}
129172

130173
static int reload (lv_State *L) {
@@ -255,9 +298,16 @@ +(int) lvClassDefine:(lv_State *)L globalName:(NSString*) globalName{
255298
// CollectionView
256299
[LVUtil reg:L clas:self cfunc:lvNewCollectionView globalName:globalName defaultName:@"CollectionView"];
257300

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+
}
261311

262312
const struct lvL_reg memberFunctions [] = {
263313
{"reload", reload},

0 commit comments

Comments
 (0)
0