-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRCTEUPageView.m
90 lines (75 loc) · 2.22 KB
/
RCTEUPageView.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
//
// RCTEUPageView.m
// RCTEUPage
//
// Created by linyize on 15/6/10.
// Copyright (c) 2015年 mmslate. All rights reserved.
//
#import "RCTEUPageView.h"
#import "RCTEventDispatcher.h"
#import "RCTUIManager.h"
#import "RCTUtils.h"
#import "UIView+React.h"
#import "EUBaseModel.h"
@implementation RCTEUPageView
{
RCTEventDispatcher *_eventDispatcher;
}
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
{
CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
if ((self = [super initWithFrame:frame]))
{
_eventDispatcher = eventDispatcher;
_pageView = [[EUPageView alloc] initWithFrame:frame scrollDirection:UICollectionViewScrollDirectionHorizontal];
_pageView.delegate = self;
_pageView.dataSource = self;
_pageView.needCycleShow = YES;
[self addSubview:_pageView];
}
return self;
}
#pragma mark - EUPageViewDelegate
- (void)pageView:(EUPageView *)pageView willDisplayCell:(EUPageViewCell *)cell forItemAtRow:(NSInteger)row
{
// todo: 用eventDispatcher发送事件给js端
//[_eventDispatcher sendInputEventWithName:@"" body:@{}];
}
- (void)pageView:(EUPageView *)pageView didEndDisplayingCell:(EUPageViewCell *)cell forItemAtRow:(NSInteger)row
{
// todo: 用eventDispatcher发送事件给js端
//[_eventDispatcher sendInputEventWithName:@"" body:@{}];
}
#pragma mark - EUPageViewDataSource
- (NSInteger)numberOfItems
{
return _dataArray.count;
}
- (EUBaseModel *)modelForItemAtRow:(NSInteger)row
{
EUBaseModel *model = nil;
if (row < self.dataArray.count)
{
NSDictionary *rowdata = [self.dataArray objectAtIndex:row];
NSString *url = [rowdata objectForKey:@"url"];
NSString *type = [rowdata objectForKey:@"type"];
model = [[EUBaseModel alloc] init];
model.resourceUrl = url;
if ([type isEqualToString:@"html"]) {
model.cellType = CellTypeWeb;
}
else if ([type isEqualToString:@"image"]) {
model.cellType = CellTypeImage;
}
else if ([type isEqualToString:@"video"]) {
model.cellType = CellTypeVideo;
}
}
return model;
}
-(void)setDataArray:(NSArray *)dataArray
{
_dataArray = dataArray;
[_pageView.collectionView reloadData];
}
@end