@@ -2,11 +2,26 @@ import _ from 'lodash';
2
2
import PropTypes from 'prop-types' ;
3
3
import React , { Component } from 'react' ;
4
4
import { DeviceEventEmitter , requireNativeComponent , StyleSheet , View } from 'react-native' ;
5
- import { Picker } from '@react-native-community/picker' ;
5
+
6
6
import WheelPickerItem from './WheelPickerItem' ;
7
7
import { Constants } from '../../../src/helpers' ;
8
8
import { Typography , Colors } from '../../../src/style' ;
9
9
10
+ /* Safely require picker component */
11
+ let Picker = ( ) => null ;
12
+ if ( Constants . isIOS ) {
13
+ try {
14
+ Picker = require ( '@react-native-picker/picker' ) . Picker ; // New package
15
+ } catch ( e ) {
16
+ try {
17
+ Picker = require ( '@react-native-community/picker' ) . Picker ; // Deprecated package
18
+ console . warn ( `RNUILib Picker will soon migrate to use "@react-native-picker/picker" package instead of '@react-native-community/picker'` ) ;
19
+ } catch ( e ) {
20
+ console . error ( `RNUILib Picker requires installing "@react-native-picker/picker" dependency` ) ;
21
+ }
22
+ }
23
+ }
24
+
10
25
const WheelPickerNative = requireNativeComponent ( 'WheelPicker' , null ) ;
11
26
12
27
class WheelPicker extends Component {
@@ -41,7 +56,7 @@ class WheelPicker extends Component {
41
56
/**
42
57
* pass custom style for the picker item
43
58
*/
44
- itemStyle : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number ] ) , //eslint-disable-line
59
+ itemStyle : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number ] ) //eslint-disable-line
45
60
} ;
46
61
47
62
static defaultProps = {
@@ -57,12 +72,12 @@ class WheelPicker extends Component {
57
72
}
58
73
59
74
state = {
60
- items : this . getItems ( ) ,
75
+ items : this . getItems ( )
61
76
} ;
62
77
63
- onLogReceived = ( event ) => {
78
+ onLogReceived = event => {
64
79
console [ event . LogType ] ( event . TAG , event . text ) ;
65
- }
80
+ } ;
66
81
67
82
onValueChange ( event ) {
68
83
const index = event . nativeEvent . itemIndex ;
@@ -76,7 +91,7 @@ class WheelPicker extends Component {
76
91
getItems ( ) {
77
92
const items = _ . map ( React . Children . toArray ( this . props . children ) , child => ( {
78
93
value : child . props . value ,
79
- label : child . props . label ,
94
+ label : child . props . label
80
95
} ) ) ;
81
96
return items ;
82
97
}
@@ -94,10 +109,10 @@ class WheelPicker extends Component {
94
109
render ( ) {
95
110
const { style, color, labelStyle, itemHeight} = this . props ;
96
111
const { fontSize, fontFamily} = labelStyle ;
97
- let { color : labelColor } = labelStyle ;
112
+ const { color : labelColor } = labelStyle ;
98
113
99
114
return (
100
- < View collapsable = { false } style = { styles . container } >
115
+ < View collapsable = { false } style = { styles . container } >
101
116
< WheelPickerNative
102
117
data = { this . extractLabelsFromItems ( ) }
103
118
initialIndex = { this . getInitialIndex ( ) }
@@ -116,14 +131,14 @@ class WheelPicker extends Component {
116
131
117
132
const styles = StyleSheet . create ( {
118
133
container : {
119
- overflow : 'hidden' ,
134
+ overflow : 'hidden'
120
135
} ,
121
136
wheelPicker : {
122
137
width : 200 ,
123
- height : 200 ,
124
- } ,
138
+ height : 200
139
+ }
125
140
} ) ;
126
141
127
142
WheelPicker . Item = WheelPickerItem ;
128
143
129
- export default ( Constants . isAndroid ? WheelPicker : Picker ) ;
144
+ export default Constants . isAndroid ? WheelPicker : Picker ;
0 commit comments