1
1
import _ from 'lodash' ;
2
2
import React , { Component } from 'react' ;
3
+ import PropTypes from 'prop-types' ;
3
4
import autobind from 'react-autobind' ;
4
- import { StyleSheet , FlatList } from 'react-native' ;
5
+ import { StyleSheet , FlatList , ViewPropTypes } from 'react-native' ;
5
6
import { Navigation } from 'react-native-navigation' ;
6
- import { ThemeManager , Constants , Assets , Colors , View , Text , Button , Carousel , TextField , Image } from 'react-native-ui-lib' ; //eslint-disable-line
7
+ import {
8
+ ThemeManager ,
9
+ Constants ,
10
+ Assets ,
11
+ Colors ,
12
+ View ,
13
+ Text ,
14
+ Button ,
15
+ Carousel ,
16
+ TextField ,
17
+ Image ,
18
+ } from 'react-native-ui-lib' ; //eslint-disable-line
7
19
import { navigationData } from './MenuStructure' ;
8
20
21
+ export default class MainScreen extends Component {
22
+ static propTypes = {
23
+ containerStyle : ViewPropTypes . style ,
24
+ renderItem : PropTypes . func ,
25
+ renderSectionTitle : PropTypes . func ,
26
+ pageStyle : ViewPropTypes . style ,
27
+ } ;
9
28
10
- export default class UiLibExplorerMenu extends Component {
11
29
constructor ( props ) {
12
30
super ( props ) ;
13
31
autobind ( this ) ;
@@ -34,9 +52,7 @@ export default class UiLibExplorerMenu extends Component {
34
52
35
53
/** Events */
36
54
onChangePage ( newPage ) {
37
- this . setState ( {
38
- currentPage : newPage ,
39
- } ) ;
55
+ this . setState ( { currentPage : newPage } ) ;
40
56
}
41
57
42
58
onSearchBoxBlur ( ) {
@@ -65,7 +81,7 @@ export default class UiLibExplorerMenu extends Component {
65
81
} ;
66
82
}
67
83
68
- navigationButtonPressed = ( event ) => {
84
+ navigationButtonPressed = event => {
69
85
const { buttonId} = event ;
70
86
const data = this . getMenuData ( ) ;
71
87
@@ -77,6 +93,7 @@ export default class UiLibExplorerMenu extends Component {
77
93
} ) ;
78
94
break ;
79
95
case 'uilib.searchButton' :
96
+ this . input . focus ( ) ;
80
97
this . toggleTopBar ( false ) ;
81
98
break ;
82
99
default :
@@ -123,7 +140,7 @@ export default class UiLibExplorerMenu extends Component {
123
140
}
124
141
125
142
/** Actions */
126
- toggleTopBar = ( shouldShow ) => {
143
+ toggleTopBar = shouldShow => {
127
144
Navigation . mergeOptions ( this . props . componentId , {
128
145
topBar : {
129
146
visible : shouldShow ,
@@ -134,14 +151,16 @@ export default class UiLibExplorerMenu extends Component {
134
151
135
152
closeSearchBox ( ) {
136
153
this . toggleTopBar ( true ) ;
154
+ this . input . blur ( ) ;
137
155
}
138
156
139
157
openScreen ( row ) {
140
158
this . closeSearchBox ( ) ;
141
- setImmediate ( ( ) => {
159
+
160
+ setTimeout ( ( ) => {
142
161
this . filterExplorerScreens ( '' ) ;
143
- } ) ;
144
- this . pushScreen ( row ) ;
162
+ this . pushScreen ( row ) ;
163
+ } , 0 ) ;
145
164
}
146
165
147
166
filterExplorerScreens ( filterText ) {
@@ -152,7 +171,7 @@ export default class UiLibExplorerMenu extends Component {
152
171
filteredNavigationData = data ;
153
172
} else {
154
173
_ . each ( data , ( menuSection , menuSectionKey ) => {
155
- const filteredMenuSection = _ . filter ( menuSection . screens , ( menuItem ) => {
174
+ const filteredMenuSection = _ . filter ( menuSection . screens , menuItem => {
156
175
const { title, description, tags} = menuItem ;
157
176
return (
158
177
_ . includes ( _ . lowerCase ( title ) , _ . toLower ( filterText ) ) ||
@@ -178,12 +197,11 @@ export default class UiLibExplorerMenu extends Component {
178
197
return (
179
198
< View row spread style = { { height : Constants . isIOS ? ( Constants . isIphoneX ? 80 : 60 ) : 56 } } >
180
199
< TextField
181
- ref = { r => ( this . toggledSearch = r ) }
200
+ ref = { r => ( this . input = r ) }
201
+ value = { this . state . filterText }
182
202
placeholder = "Search your component.."
183
203
onChangeText = { this . filterExplorerScreens }
184
204
onBlur = { this . onSearchBoxBlur }
185
- onDismiss = { this . onSearchBoxBlur }
186
- value = { this . state . filterText }
187
205
style = { {
188
206
marginTop : Constants . isIOS ? Constants . statusBarHeight + 10 : 14 ,
189
207
marginLeft : 16 ,
@@ -196,17 +214,23 @@ export default class UiLibExplorerMenu extends Component {
196
214
style = { { marginRight : 16 , marginTop : Constants . isIOS ? Constants . statusBarHeight : 0 } }
197
215
iconSource = { Assets . icons . search }
198
216
size = { 'small' }
199
- onPress = { this . onSearchBoxBlur }
200
217
backgroundColor = { 'transparent' }
218
+ onPress = { this . onSearchBoxBlur }
201
219
/>
202
220
</ View >
203
221
) ;
204
222
}
205
223
206
224
renderItem ( { item} ) {
225
+ const { renderItem} = this . props ;
226
+
227
+ if ( renderItem ) {
228
+ return renderItem ( { item} , this . openScreen ) ;
229
+ }
230
+
207
231
return (
208
232
< View centerV row paddingL-20 marginB-10 >
209
- < Image source = { Assets . icons . chevronRight } style = { { tintColor : Colors . dark10 } } supportRTL />
233
+ < Image source = { Assets . icons . chevronRight } style = { { tintColor : Colors . dark10 } } supportRTL />
210
234
< Text
211
235
style = { [ item . deprecate && styles . entryTextDeprecated ] }
212
236
dark10
@@ -254,7 +278,24 @@ export default class UiLibExplorerMenu extends Component {
254
278
) ;
255
279
}
256
280
281
+ renderSectionTitle ( title ) {
282
+ const { renderSectionTitle} = this . props ;
283
+
284
+ if ( renderSectionTitle ) {
285
+ return renderSectionTitle ( title ) ;
286
+ }
287
+
288
+ return (
289
+ < View style = { styles . pageTitleContainer } >
290
+ < Text text40 style = { { alignSelf : 'flex-start' } } >
291
+ { title }
292
+ </ Text >
293
+ </ View >
294
+ ) ;
295
+ }
296
+
257
297
renderCarousel ( data ) {
298
+ const { renderItem, pageStyle} = this . props ;
258
299
const dividerTransforms = [ - 10 , - 55 , - 20 ] ;
259
300
const dividerWidths = [ '60%' , '75%' , '90%' ] ;
260
301
const keys = _ . keys ( data ) ;
@@ -263,10 +304,8 @@ export default class UiLibExplorerMenu extends Component {
263
304
< Carousel onChangePage = { this . onChangePage } ref = { carousel => ( this . carousel = carousel ) } >
264
305
{ _ . map ( data , ( section , key ) => {
265
306
return (
266
- < View key = { key } style = { styles . page } >
267
- < View style = { styles . pageTitleContainer } >
268
- < Text text40 style = { { alignSelf : 'flex-start' } } > { section . title } </ Text >
269
- </ View >
307
+ < View key = { key } style = { [ styles . page , pageStyle ] } >
308
+ { this . renderSectionTitle ( section . title ) }
270
309
< View
271
310
style = { [
272
311
styles . pageTitleExtraDivider ,
@@ -275,7 +314,12 @@ export default class UiLibExplorerMenu extends Component {
275
314
] }
276
315
/>
277
316
< View flex >
278
- < FlatList data = { section . screens } keyExtractor = { item => item . title } renderItem = { this . renderItem } />
317
+ < FlatList
318
+ showsVerticalScrollIndicator = { false }
319
+ data = { section . screens }
320
+ keyExtractor = { item => item . title }
321
+ renderItem = { this . renderItem }
322
+ />
279
323
</ View >
280
324
</ View >
281
325
) ;
@@ -288,26 +332,25 @@ export default class UiLibExplorerMenu extends Component {
288
332
const flatData = _ . flatMap ( data ) ;
289
333
290
334
return (
291
- < View paddingH-24 >
292
- < FlatList
293
- keyboardShouldPersistTaps = 'always'
294
- data = { flatData }
295
- keyExtractor = { ( item , index ) => index . toString ( ) }
296
- renderItem = { this . renderItem }
297
- />
298
- </ View >
335
+ < FlatList
336
+ keyboardShouldPersistTaps = "always"
337
+ data = { flatData }
338
+ keyExtractor = { ( item , index ) => index . toString ( ) }
339
+ renderItem = { this . renderItem }
340
+ />
299
341
) ;
300
342
}
301
343
302
344
render ( ) {
345
+ const { containerStyle} = this . props ;
303
346
const { filteredNavigationData, filterText} = this . state ;
304
347
const showNoResults = _ . isEmpty ( filteredNavigationData ) && ! ! filterText ;
305
348
const showResults = ! _ . isEmpty ( filteredNavigationData ) && ! ! filterText ;
306
349
const showCarousel = ! filterText ;
307
350
const data = this . getMenuData ( ) ;
308
351
309
352
return (
310
- < View testID = "demo_main_screen" flex bg-dark80 >
353
+ < View testID = "demo_main_screen" flex bg-dark80 style = { containerStyle } >
311
354
{ this . renderHeader ( ) }
312
355
{ showNoResults && (
313
356
< View paddingH-24 >
@@ -347,7 +390,7 @@ const styles = StyleSheet.create({
347
390
} ,
348
391
pageTitleExtraDivider : {
349
392
marginTop : 5 ,
350
- marginBottom : 22 ,
393
+ // marginBottom: 22,
351
394
} ,
352
395
entryTextDeprecated : {
353
396
textDecorationLine : 'line-through' ,
0 commit comments