6
6
import _ from 'lodash' ;
7
7
import React , { useMemo , useState , useRef , useCallback , useEffect } from 'react' ;
8
8
import { LayoutChangeEvent } from 'react-native' ;
9
- import { Typography } from 'style' ;
10
9
import { useThemeProps } from 'hooks' ;
11
10
import { Constants } from '../../commons/new' ;
12
11
import ExpandableOverlay , { ExpandableOverlayProps , ExpandableOverlayMethods } from '../../incubator/expandableOverlay' ;
13
12
import TextField from '../textField' ;
14
- import Icon from '../icon' ;
15
- import View from '../view' ;
16
- import Text from '../text' ;
17
13
import PickerItemsList from './PickerItemsList' ;
18
14
import PickerItem from './PickerItem' ;
19
15
import PickerContext from './PickerContext' ;
20
16
import usePickerSelection from './helpers/usePickerSelection' ;
21
17
import usePickerLabel from './helpers/usePickerLabel' ;
22
18
import usePickerSearch from './helpers/usePickerSearch' ;
23
19
import useImperativePickerHandle from './helpers/useImperativePickerHandle' ;
20
+ import useFieldType from './helpers/useFieldType' ;
24
21
// import usePickerMigrationWarnings from './helpers/usePickerMigrationWarnings';
25
22
import { extractPickerItems } from './PickerPresenter' ;
26
23
import {
@@ -35,8 +32,6 @@ import {
35
32
PickerMethods
36
33
} from './types' ;
37
34
38
- const dropdown = require ( './assets/dropdown.png' ) ;
39
-
40
35
const DIALOG_PROPS = {
41
36
bottom : true ,
42
37
width : '100%' ,
@@ -134,6 +129,17 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
134
129
placeholder : themeProps . placeholder
135
130
} ) ;
136
131
132
+ const { placeholder, style, trailingAccessory} = themeProps ;
133
+ const { propsByFieldType, pickerInnerInput} = useFieldType ( {
134
+ fieldType,
135
+ preset,
136
+ trailingAccessory,
137
+ style,
138
+ placeholder,
139
+ labelStyle,
140
+ label
141
+ } ) ;
142
+
137
143
const onSelectedItemLayout = useCallback ( ( event : LayoutChangeEvent ) => {
138
144
const y = event . nativeEvent . layout . y ;
139
145
setSelectedItemPosition ( y ) ;
@@ -176,22 +182,6 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
176
182
...pickerModalProps
177
183
} ;
178
184
179
- const propsByFieldType = useMemo ( ( ) => {
180
- if ( fieldType === PickerFieldTypes . filter ) {
181
- return {
182
- preset : preset || null ,
183
- containerStyle : { flexDirection : 'row' } ,
184
- labelStyle : Typography . text70 ,
185
- trailingAccessory : themeProps . trailingAccessory ?? < Icon marginL-s1 source = { dropdown } />
186
- } ;
187
- } else if ( fieldType === PickerFieldTypes . settings ) {
188
- return {
189
- preset : preset || null ,
190
- label : undefined
191
- } ;
192
- }
193
- } , [ fieldType , preset , themeProps . trailingAccessory ] ) ;
194
-
195
185
const renderPickerItem = useCallback ( ( item : PickerItemProps , index : number ) : React . ReactElement => {
196
186
return < PickerItem key = { `${ index } -${ item . value } ` } { ...item } /> ;
197
187
} , [ ] ) ;
@@ -270,27 +260,6 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
270
260
items
271
261
] ) ;
272
262
273
- const renderPickerInnerInput = ( ) => {
274
- if ( fieldType === PickerFieldTypes . filter ) {
275
- return (
276
- < Text text70 numberOfLines = { 1 } style = { others . style } >
277
- { _ . isEmpty ( label ) ? others . placeholder : label }
278
- </ Text >
279
- ) ;
280
- } else if ( fieldType === PickerFieldTypes . settings ) {
281
- return (
282
- < View flexG row spread >
283
- < Text text70 style = { labelStyle } >
284
- { others . label }
285
- </ Text >
286
- < Text text70 $textPrimary style = { others . style } >
287
- { _ . isEmpty ( label ) ? others . placeholder : label }
288
- </ Text >
289
- </ View >
290
- ) ;
291
- }
292
- } ;
293
-
294
263
return (
295
264
//TODO : fix the ExpandableOverlay ts error
296
265
< PickerContext . Provider value = { contextValue } >
@@ -326,7 +295,7 @@ const Picker = React.forwardRef((props: PickerProps, ref) => {
326
295
value = { label }
327
296
selection = { Constants . isAndroid ? { start : 0 } : undefined }
328
297
>
329
- { renderPickerInnerInput ( ) }
298
+ { pickerInnerInput }
330
299
</ TextField >
331
300
) }
332
301
</ ExpandableOverlay >
0 commit comments