@@ -5,7 +5,17 @@ import PropTypes from 'prop-types';
5
5
import { StyleSheet , FlatList , ViewPropTypes } from 'react-native' ;
6
6
import { Navigation } from 'react-native-navigation' ;
7
7
import { gestureHandlerRootHOC } from 'react-native-gesture-handler' ;
8
- import { Assets , Colors , View , Text , TouchableOpacity , TextField , Image , TabController } from 'react-native-ui-lib' ; //eslint-disable-line
8
+ import {
9
+ Assets ,
10
+ Colors ,
11
+ View ,
12
+ Text ,
13
+ TouchableOpacity ,
14
+ TextField ,
15
+ Image ,
16
+ Button ,
17
+ TabController
18
+ } from 'react-native-ui-lib' ; //eslint-disable-line
9
19
import { navigationData } from './MenuStructure' ;
10
20
11
21
const settingsIcon = require ( '../assets/icons/settings.png' ) ;
@@ -15,7 +25,7 @@ class MainScreen extends Component {
15
25
static propTypes = {
16
26
containerStyle : ViewPropTypes . style ,
17
27
renderItem : PropTypes . func ,
18
- pageStyle : ViewPropTypes . style
28
+ pageStyle : ViewPropTypes . style
19
29
} ;
20
30
21
31
settingsScreenName = 'unicorn.Settings' ;
@@ -52,7 +62,6 @@ class MainScreen extends Component {
52
62
53
63
onSearchBoxBlur = ( ) => {
54
64
this . closeSearchBox ( ) ;
55
- // this.filterExplorerScreens('');
56
65
} ;
57
66
58
67
getMenuData = ( ) => {
@@ -67,8 +76,8 @@ class MainScreen extends Component {
67
76
this . pushScreen ( {
68
77
name : this . settingsScreenName ,
69
78
passProps : {
70
- navigationData : data ,
71
- playground : this . props . playground ,
79
+ navigationData : data ,
80
+ playground : this . props . playground ,
72
81
extraSettingsUI : this . props . extraSettingsUI
73
82
}
74
83
} ) ;
@@ -105,12 +114,22 @@ class MainScreen extends Component {
105
114
this . closeSearchBox ( ) ;
106
115
107
116
setTimeout ( ( ) => {
108
- // this.filterExplorerScreens('');
109
117
this . pushScreen ( row ) ;
110
118
} , 0 ) ;
111
119
} ;
112
120
113
- filterExplorerScreens = filterText => {
121
+ updateSearch = filterText => {
122
+ this . setState ( { filterText} , ( ) => {
123
+ this . filterExplorerScreens ( ) ;
124
+ } ) ;
125
+ } ;
126
+
127
+ clearSearch = ( ) => {
128
+ this . updateSearch ( '' ) ;
129
+ } ;
130
+
131
+ filterExplorerScreens = ( ) => {
132
+ const { filterText} = this . state ;
114
133
let filteredNavigationData = { } ;
115
134
const data = this . getMenuData ( ) ;
116
135
@@ -134,32 +153,35 @@ class MainScreen extends Component {
134
153
}
135
154
136
155
this . setState ( {
137
- filterText,
138
156
filteredNavigationData
139
157
} ) ;
140
158
} ;
141
159
142
160
/** Renders */
143
161
renderSearch = ( ) => {
162
+ const { filterText} = this . state ;
144
163
return (
145
164
< TextField
165
+ migrate
146
166
ref = { r => ( this . input = r ) }
147
- value = { this . state . filterText }
167
+ value = { filterText }
148
168
testID = "uilib.search_for_component"
149
169
placeholder = "Search for your component..."
150
- onChangeText = { this . filterExplorerScreens }
170
+ onChangeText = { this . updateSearch }
151
171
onBlur = { this . onSearchBoxBlur }
152
- containerStyle = { { padding : 16 , paddingBottom : 0 } }
153
- style = { {
154
- padding : 12 ,
155
- backgroundColor : Colors . dark80 ,
156
- borderRadius : 8
157
- } }
172
+ containerStyle = { styles . searchContainer }
173
+ fieldStyle = { styles . searchField }
158
174
enableErrors = { false }
159
175
hideUnderline
160
176
floatingPlaceholder = { false }
161
177
text70
162
- rightButtonProps = { { iconSource : Assets . icons . search , style : { marginRight : 12 , alignSelf : 'center' } } }
178
+ trailingAccessory = {
179
+ filterText ? (
180
+ < Button link iconSource = { Assets . icons . demo . close } grey10 onPress = { this . clearSearch } />
181
+ ) : (
182
+ < Image source = { Assets . icons . demo . search } />
183
+ )
184
+ }
163
185
/>
164
186
) ;
165
187
} ;
@@ -251,7 +273,10 @@ class MainScreen extends Component {
251
273
{ showResults && this . renderSearchResults ( filteredNavigationData ) }
252
274
253
275
{ showCarousel && (
254
- < TabController asCarousel items = { _ . map ( data , section => ( { label : section . title , testID : `section.${ section . title } ` } ) ) } >
276
+ < TabController
277
+ asCarousel
278
+ items = { _ . map ( data , section => ( { label : section . title , testID : `section.${ section . title } ` } ) ) }
279
+ >
255
280
< TabController . TabBar testID = { 'mainScreenTabBar' } />
256
281
{ this . renderPages ( data ) }
257
282
</ TabController >
@@ -271,6 +296,15 @@ class MainScreen extends Component {
271
296
const styles = StyleSheet . create ( {
272
297
entryTextDeprecated : {
273
298
textDecorationLine : 'line-through'
299
+ } ,
300
+ searchContainer : {
301
+ padding : 16 ,
302
+ paddingBottom : 0
303
+ } ,
304
+ searchField : {
305
+ padding : 12 ,
306
+ backgroundColor : Colors . dark80 ,
307
+ borderRadius : 8
274
308
}
275
309
} ) ;
276
310
0 commit comments