@@ -15,7 +15,6 @@ import {
15
15
} from 'react-native' ;
16
16
17
17
import styles from './style' ;
18
- import BaseComponent from './BaseComponent' ;
19
18
20
19
const ViewPropTypes = RNViewPropTypes || View . propTypes ;
21
20
@@ -40,7 +39,7 @@ const propTypes = {
40
39
overlayStyle : ViewPropTypes . style ,
41
40
cancelText : PropTypes . string ,
42
41
disabled : PropTypes . bool ,
43
- supportedOrientations : PropTypes . arrayOf ( PropTypes . oneOf ( [ 'portrait' , 'landscape' , 'portrait-upside-down' , 'landscape-left' , 'landscape-right' ] ) ) ,
42
+ supportedOrientations : Modal . propTypes . supportedOrientations ,
44
43
keyboardShouldPersistTaps : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . bool ] ) ,
45
44
backdropPressToClose : PropTypes . bool ,
46
45
} ;
@@ -69,39 +68,26 @@ const defaultProps = {
69
68
backdropPressToClose : false ,
70
69
} ;
71
70
72
- export default class ModalSelector extends BaseComponent {
71
+ export default class ModalSelector extends React . Component {
73
72
74
- constructor ( ) {
75
-
76
- super ( ) ;
77
-
78
- this . _bind (
79
- 'onChange' ,
80
- 'open' ,
81
- 'close' ,
82
- 'renderChildren'
83
- ) ;
73
+ constructor ( props ) {
74
+ super ( props ) ;
84
75
85
76
this . state = {
86
- modalVisible : false ,
87
- transparent : false ,
88
- selected : 'please select' ,
89
- changedItem : undefined ,
77
+ modalVisible : false ,
78
+ selected : props . initValue ,
79
+ cancelText : props . cancelText ,
80
+ changedItem : undefined ,
90
81
} ;
91
82
}
92
83
93
- componentDidMount ( ) {
94
- this . setState ( { selected : this . props . initValue } ) ;
95
- this . setState ( { cancelText : this . props . cancelText } ) ;
96
- }
97
-
98
84
componentWillReceiveProps ( nextProps ) {
99
85
if ( nextProps . initValue !== this . props . initValue ) {
100
86
this . setState ( { selected : nextProps . initValue } ) ;
101
87
}
102
88
}
103
89
104
- onChange ( item ) {
90
+ onChange = ( item ) => {
105
91
if ( Platform . OS === 'android' || ! Modal . propTypes . onDismiss ) {
106
92
// RN >= 0.50 on iOS comes with the onDismiss prop for Modal which solves RN issue #10471
107
93
this . props . onChange ( item ) ;
@@ -110,28 +96,28 @@ export default class ModalSelector extends BaseComponent {
110
96
this . close ( ) ;
111
97
}
112
98
113
- close ( ) {
99
+ close = ( ) => {
114
100
this . setState ( {
115
101
modalVisible : false ,
116
102
} ) ;
117
103
}
118
104
119
- open ( ) {
105
+ open = ( ) => {
120
106
this . setState ( {
121
107
modalVisible : true ,
122
108
changedItem : undefined ,
123
109
} ) ;
124
110
}
125
111
126
- renderSection ( section ) {
112
+ renderSection = ( section ) => {
127
113
return (
128
114
< View key = { section . key } style = { [ styles . sectionStyle , this . props . sectionStyle ] } >
129
115
< Text style = { [ styles . sectionTextStyle , this . props . sectionTextStyle ] } > { section . label } </ Text >
130
116
</ View >
131
117
) ;
132
118
}
133
119
134
- renderOption ( option , isLastItem ) {
120
+ renderOption = ( option , isLastItem ) => {
135
121
return (
136
122
< TouchableOpacity key = { option . key } onPress = { ( ) => this . onChange ( option ) } >
137
123
< View style = { [ styles . optionStyle , this . props . optionStyle , isLastItem &&
@@ -141,7 +127,7 @@ export default class ModalSelector extends BaseComponent {
141
127
</ TouchableOpacity > ) ;
142
128
}
143
129
144
- renderOptionList ( ) {
130
+ renderOptionList = ( ) => {
145
131
146
132
let options = this . props . data . map ( ( item , index ) => {
147
133
if ( item . section ) {
@@ -175,7 +161,7 @@ export default class ModalSelector extends BaseComponent {
175
161
</ TouchableWithoutFeedback > ) ;
176
162
}
177
163
178
- renderChildren ( ) {
164
+ renderChildren = ( ) => {
179
165
180
166
if ( this . props . children ) {
181
167
return this . props . children ;
0 commit comments