1
1
'use strict' ;
2
2
/* jshint esnext: true */
3
3
4
- var React = require ( 'react' ) ;
5
- var ReactNative = require ( 'react-native' ) ;
6
- var { Component, PropTypes} = React ;
7
- var { ListView, StyleSheet, View, NativeModules} = ReactNative ;
8
- var UIManager = NativeModules . UIManager ;
9
- var merge = require ( 'merge' ) ;
10
-
11
- var SectionHeader = require ( './SectionHeader' ) ;
12
- var SectionList = require ( './SectionList' ) ;
13
- var CellWrapper = require ( './CellWrapper' ) ;
14
-
15
- class SelectableSectionsListView extends Component {
4
+ import React , {
5
+ Component ,
6
+ PropTypes ,
7
+ } from 'react' ;
8
+ import ReactNative , {
9
+ ListView ,
10
+ StyleSheet ,
11
+ View ,
12
+ NativeModules ,
13
+ } from 'react-native' ;
14
+ import merge from 'merge' ;
15
+
16
+ import SectionHeader from './SectionHeader' ;
17
+ import SectionList from './SectionList' ;
18
+ import CellWrapper from './CellWrapper' ;
19
+
20
+ const { UIManager } = NativeModules ;
21
+
22
+ export default class SelectableSectionsListView extends Component {
16
23
17
24
constructor ( props , context ) {
18
25
super ( props , context ) ;
@@ -90,24 +97,24 @@ class SelectableSectionsListView extends Component {
90
97
}
91
98
92
99
scrollToSection ( section ) {
93
- var y = 0 ;
94
- var headerHeight = this . props . headerHeight || 0 ;
100
+ let y = 0 ;
101
+ let headerHeight = this . props . headerHeight || 0 ;
95
102
y += headerHeight ;
96
103
97
104
if ( ! this . props . useDynamicHeights ) {
98
- var cellHeight = this . props . cellHeight ;
99
- var sectionHeaderHeight = this . props . sectionHeaderHeight ;
100
- var keys = Object . keys ( this . props . data ) ;
101
- var index = keys . indexOf ( section ) ;
105
+ const cellHeight = this . props . cellHeight ;
106
+ let sectionHeaderHeight = this . props . sectionHeaderHeight ;
107
+ const keys = Object . keys ( this . props . data ) ;
108
+ const index = keys . indexOf ( section ) ;
102
109
103
- var numcells = 0 ;
110
+ let numcells = 0 ;
104
111
for ( var i = 0 ; i < index ; i ++ ) {
105
112
numcells += this . props . data [ keys [ i ] ] . length ;
106
113
}
107
114
108
115
sectionHeaderHeight = index * sectionHeaderHeight ;
109
116
y += numcells * cellHeight + sectionHeaderHeight ;
110
- var maxY = this . totalHeight - this . containerHeight + headerHeight ;
117
+ const maxY = this . totalHeight - this . containerHeight + headerHeight ;
111
118
y = y > maxY ? maxY : y ;
112
119
113
120
this . refs . listview . scrollTo ( { x :0 , y, animated : true } ) ;
@@ -123,11 +130,11 @@ class SelectableSectionsListView extends Component {
123
130
}
124
131
125
132
renderSectionHeader ( sectionData , sectionId ) {
126
- var updateTag = this . props . useDynamicHeights ?
133
+ const updateTag = this . props . useDynamicHeights ?
127
134
this . updateTagInSectionMap :
128
135
null ;
129
136
130
- var title = this . props . getSectionTitle ?
137
+ const title = this . props . getSectionTitle ?
131
138
this . props . getSectionTitle ( sectionId ) :
132
139
sectionId ;
133
140
@@ -143,23 +150,23 @@ class SelectableSectionsListView extends Component {
143
150
}
144
151
145
152
renderFooter ( ) {
146
- var Footer = this . props . footer ;
153
+ const Footer = this . props . footer ;
147
154
return < Footer /> ;
148
155
}
149
156
150
157
renderHeader ( ) {
151
- var Header = this . props . header ;
158
+ const Header = this . props . header ;
152
159
return < Header /> ;
153
160
}
154
161
155
162
renderRow ( item , sectionId , index ) {
156
- var CellComponent = this . props . cell ;
163
+ const CellComponent = this . props . cell ;
157
164
index = parseInt ( index , 10 ) ;
158
165
159
- var isFirst = index === 0 ;
160
- var isLast = this . sectionItemCount [ sectionId ] - 1 === index ;
166
+ const isFirst = index === 0 ;
167
+ const isLast = this . sectionItemCount [ sectionId ] - 1 === index ;
161
168
162
- var props = {
169
+ const props = {
163
170
isFirst,
164
171
isLast,
165
172
sectionId,
@@ -177,7 +184,7 @@ class SelectableSectionsListView extends Component {
177
184
}
178
185
179
186
onScroll ( e ) {
180
- var offsetY = e . nativeEvent . contentOffset . y ;
187
+ const offsetY = e . nativeEvent . contentOffset . y ;
181
188
if ( this . props . updateScrollState ) {
182
189
this . setState ( {
183
190
offsetY
@@ -196,11 +203,11 @@ class SelectableSectionsListView extends Component {
196
203
}
197
204
198
205
render ( ) {
199
- var data = this . props . data ;
200
- var dataIsArray = Array . isArray ( data ) ;
201
- var sectionList ;
202
- var renderSectionHeader ;
203
- var dataSource ;
206
+ const { data } = this . props ;
207
+ const dataIsArray = Array . isArray ( data ) ;
208
+ let sectionList ;
209
+ let renderSectionHeader ;
210
+ let dataSource ;
204
211
205
212
if ( dataIsArray ) {
206
213
dataSource = this . state . dataSource . cloneWithRows ( data ) ;
@@ -220,15 +227,15 @@ class SelectableSectionsListView extends Component {
220
227
dataSource = this . state . dataSource . cloneWithRowsAndSections ( data ) ;
221
228
}
222
229
223
- var renderFooter = this . props . footer ?
230
+ const renderFooter = this . props . footer ?
224
231
this . renderFooter :
225
232
this . props . renderFooter ;
226
233
227
- var renderHeader = this . props . header ?
234
+ const renderHeader = this . props . header ?
228
235
this . renderHeader :
229
236
this . props . renderHeader ;
230
237
231
- var props = merge ( { } , this . props , {
238
+ const props = merge ( { } , this . props , {
232
239
onScroll : this . onScroll ,
233
240
onScrollAnimationEnd : this . onScrollAnimationEnd ,
234
241
dataSource,
@@ -252,13 +259,13 @@ class SelectableSectionsListView extends Component {
252
259
}
253
260
}
254
261
255
- var styles = StyleSheet . create ( {
262
+ const styles = StyleSheet . create ( {
256
263
container : {
257
264
flex : 1
258
265
}
259
266
} ) ;
260
267
261
- var stylesheetProp = PropTypes . oneOfType ( [
268
+ const stylesheetProp = PropTypes . oneOfType ( [
262
269
PropTypes . number ,
263
270
PropTypes . object ,
264
271
] ) ;
@@ -375,5 +382,3 @@ SelectableSectionsListView.propTypes = {
375
382
sectionListStyle : stylesheetProp
376
383
377
384
} ;
378
-
379
- module . exports = SelectableSectionsListView ;
0 commit comments