-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
92 lines (74 loc) · 2.06 KB
/
index.js
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
'use strict';
import React, { Component } from 'react';
import {
NativeMethodsMixin,
NativeModules,
StyleSheet,
View,
requireNativeComponent,
} from 'react-native';
var SCROLLPAGEVIEW = 'ScrollPageView';
function extend(el, map) {
for (var i in map)
if (typeof(map[i])!='object')
el[i] = map[i];
return el;
}
var ScrollPageView = React.createClass({
mixins: [NativeMethodsMixin],
propTypes: {
onPageViewDidAppearedAtIndex: React.PropTypes.func,
},
getInitialState: function() {
return this._stateFromProps(this.props);
},
componentWillReceiveProps: function(nextProps) {
var state = this._stateFromProps(nextProps);
this.setState(state);
},
_stateFromProps: function(props) {
var pages = [];
React.Children.forEach(props.children, function (page, index) {
var el = {};
extend(el, page.props);
pages.push(el);
});
this.pages = pages;
return {pages};
},
render: function() {
return (
<View style={[{flex: 1}, this.props.style]}>
<RNScrollPageView
ref={SCROLLPAGEVIEW}
style={this.props.style}
pages={this.state.pages}
curIndex={this.props.curIndex}
onPageViewDidAppearedAtIndex={this._onPageViewDidAppearedAtIndex}>
</RNScrollPageView>
</View>
);
},
setPageIndex: function(index) {
NativeModules.RNScrollPageViewManager.setPageIndex(
findNodeHandle(this.tableView),
index
);
},
_onPageViewDidAppearedAtIndex: function(event) {
var data = event.nativeEvent;
this.props.onPageViewDidAppearedAtIndex(data.index);
}
});
ScrollPageView.Page = React.createClass({
propTypes: {
label: React.PropTypes.string,
renderCell: React.PropTypes.string,
pageIndex: React.PropTypes.number,
},
render() {
return null;
}
});
var RNScrollPageView = requireNativeComponent('RNScrollPageView', null);
module.exports = ScrollPageView;