Skip to content

Commit c32c9d9

Browse files
committed
v0.4.2
### v0.4.2 - Add `animated` option. - Add `showsVerticalScrollIndicator` option
1 parent c053578 commit c32c9d9

3 files changed

Lines changed: 45 additions & 31 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ You can find them in the example.
2121

2222
## Update History
2323

24+
### v0.4.2
25+
- Add `animated` option.
26+
- Add `showsVerticalScrollIndicator` option
27+
2428
### v0.4.1
2529
- Fix bug: [\#27](https://github.com/sohobloo/react-native-modal-dropdown/issues/27) Fix a flex style bug.
2630
- Enhancement: [\#26](https://github.com/sohobloo/react-native-modal-dropdown/issues/26) Support object type of options.
@@ -86,10 +90,12 @@ You can also render your option row and row separator by implement `renderRow` a
8690
### Props
8791
Prop | Type | Optional | Default | Description
8892
------------------- | -------- | -------- | --------- | -----------
89-
`disabled` | bool | Yes | false | disable/enable the component.
93+
`disabled` | bool | Yes | false | disable / enable the component.
9094
`defaultIndex` | number | Yes | -1 | Init selected index. `-1`: None is selected. **This only change the highlight of the dropdown row, you have to give a `defaultValue` to change the init text.**
9195
`defaultValue` | string | Yes | Please select... | Init text of the button. **Invalid in wrapper mode.**
9296
`options` | array | Yes | | Options. **The dropdown will show a loading indicator if `options` is `null`/`undefined`.**
97+
`animated` | bool | Yes | true | Disable / enable fade animation.
98+
`showsVerticalScrollIndicator` | bool | Yes | true | Show / hide vertical scroll indicator.
9399
`style` | object | Yes | | Style of the button.
94100
`textStyle` | object | Yes | | Style of the button text. **Invalid in wrapper mode.**
95101
`dropdownStyle` | object | Yes | | Style of the dropdown list.

components/ModalDropdown.js

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ import {
2727
const TOUCHABLE_ELEMENTS = ['TouchableHighlight', 'TouchableOpacity', 'TouchableWithoutFeedback', 'TouchableWithNativeFeedback'];
2828

2929
export default class ModalDropdown extends Component {
30-
static defaultProps = {
31-
disabled: false,
32-
defaultIndex: -1,
33-
defaultValue: 'Please select...',
34-
options: null,
35-
};
36-
3730
static propTypes = {
3831
disabled: PropTypes.bool,
3932
defaultIndex: PropTypes.number,
4033
defaultValue: PropTypes.string,
4134
options: PropTypes.array,
4235

36+
animated: PropTypes.bool,
37+
showsVerticalScrollIndicator: PropTypes.bool,
38+
4339
style: PropTypes.oneOfType([PropTypes.number, PropTypes.object, PropTypes.array]),
4440
textStyle: PropTypes.oneOfType([PropTypes.number, PropTypes.object, PropTypes.array]),
4541
dropdownStyle: PropTypes.oneOfType([PropTypes.number, PropTypes.object, PropTypes.array]),
@@ -50,7 +46,16 @@ export default class ModalDropdown extends Component {
5046

5147
onDropdownWillShow: PropTypes.func,
5248
onDropdownWillHide: PropTypes.func,
53-
onSelect: PropTypes.func,
49+
onSelect: PropTypes.func
50+
};
51+
52+
static defaultProps = {
53+
disabled: false,
54+
defaultIndex: -1,
55+
defaultValue: 'Please select...',
56+
options: null,
57+
animated: true,
58+
showsVerticalScrollIndicator: true
5459
};
5560

5661
constructor(props) {
@@ -66,7 +71,7 @@ export default class ModalDropdown extends Component {
6671
loading: props.options == null,
6772
showDropdown: false,
6873
buttonText: props.defaultValue,
69-
selectedIndex: props.defaultIndex,
74+
selectedIndex: props.defaultIndex
7075
};
7176
}
7277

@@ -86,7 +91,7 @@ export default class ModalDropdown extends Component {
8691
disabled: nextProps.disabled,
8792
loading: nextProps.options == null,
8893
buttonText: buttonText,
89-
selectedIndex: selectedIndex,
94+
selectedIndex: selectedIndex
9095
});
9196
}
9297

@@ -111,14 +116,14 @@ export default class ModalDropdown extends Component {
111116
show() {
112117
this._updatePosition(() => {
113118
this.setState({
114-
showDropdown: true,
119+
showDropdown: true
115120
});
116121
});
117122
}
118123

119124
hide() {
120125
this.setState({
121-
showDropdown: false,
126+
showDropdown: false
122127
});
123128
}
124129

@@ -137,7 +142,7 @@ export default class ModalDropdown extends Component {
137142

138143
this.setState({
139144
buttonText: value,
140-
selectedIndex: idx,
145+
selectedIndex: idx
141146
});
142147
}
143148

@@ -171,10 +176,12 @@ export default class ModalDropdown extends Component {
171176
_renderModal() {
172177
if (this.state.showDropdown && this._buttonFrame) {
173178
let frameStyle = this._calcPosition();
179+
let animationType = this.props.animated ? 'fade' : 'none';
174180
return (
175-
<Modal animationType='fade'
181+
<Modal animationType={animationType}
176182
transparent={true}
177-
onRequestClose={this._onRequestClose.bind(this)}>
183+
onRequestClose={this._onRequestClose.bind(this)}
184+
supportedOrientations={['portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right']}>
178185
<TouchableWithoutFeedback onPress={this._onModalPress.bind(this)}>
179186
<View style={styles.modal}>
180187
<View style={[styles.dropdown, this.props.dropdownStyle, frameStyle]}>
@@ -203,7 +210,7 @@ export default class ModalDropdown extends Component {
203210
var style = {
204211
height: dropdownHeight,
205212
top: showInBottom ? this._buttonFrame.y + this._buttonFrame.h : Math.max(0, this._buttonFrame.y - dropdownHeight),
206-
}
213+
};
207214

208215
if (showInLeft) {
209216
style.left = this._buttonFrame.x;
@@ -250,28 +257,29 @@ export default class ModalDropdown extends Component {
250257
renderRow={this._renderRow.bind(this)}
251258
renderSeparator={this.props.renderSeparator || this._renderSeparator.bind(this)}
252259
automaticallyAdjustContentInsets={false}
260+
showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator}
253261
/>
254262
);
255263
}
256264

257265
get _dataSource() {
258266
let ds = new ListView.DataSource({
259-
rowHasChanged: (r1, r2) => r1 !== r2,
267+
rowHasChanged: (r1, r2) => r1 !== r2
260268
});
261269
return ds.cloneWithRows(this.props.options);
262270
}
263271

264272
_renderRow(rowData, sectionID, rowID, highlightRow) {
265273
let key = `row_${rowID}`;
266-
let highlighted = rowID == this.state.selectedIndex
274+
let highlighted = rowID == this.state.selectedIndex;
267275
let row = !this.props.renderRow ?
268276
(<Text style={[styles.rowText, highlighted && styles.highlightedRowText]}>
269277
{rowData}
270278
</Text>) :
271279
this.props.renderRow(rowData, rowID, highlighted);
272280
let preservedProps = {
273281
key: key,
274-
onPress: () => this._onRowPress(rowData, sectionID, rowID, highlightRow),
282+
onPress: () => this._onRowPress(rowData, sectionID, rowID, highlightRow)
275283
};
276284
if (TOUCHABLE_ELEMENTS.find(name => name == row.type.displayName)) {
277285
var props = {...row.props};
@@ -333,13 +341,13 @@ export default class ModalDropdown extends Component {
333341
this._nextIndex = rowID;
334342
this.setState({
335343
buttonText: rowData.toString(),
336-
selectedIndex: rowID,
344+
selectedIndex: rowID
337345
});
338346
}
339347
if (!this.props.onDropdownWillHide ||
340348
this.props.onDropdownWillHide() !== false) {
341349
this.setState({
342-
showDropdown: false,
350+
showDropdown: false
343351
});
344352
}
345353
}
@@ -354,13 +362,13 @@ export default class ModalDropdown extends Component {
354362

355363
const styles = StyleSheet.create({
356364
button: {
357-
justifyContent: 'center',
365+
justifyContent: 'center'
358366
},
359367
buttonText: {
360-
fontSize: 12,
368+
fontSize: 12
361369
},
362370
modal: {
363-
flexGrow: 1,
371+
flexGrow: 1
364372
},
365373
dropdown: {
366374
position: 'absolute',
@@ -369,10 +377,10 @@ const styles = StyleSheet.create({
369377
borderColor: 'lightgray',
370378
borderRadius: 2,
371379
backgroundColor: 'white',
372-
justifyContent: 'center',
380+
justifyContent: 'center'
373381
},
374382
loading: {
375-
alignSelf: 'center',
383+
alignSelf: 'center'
376384
},
377385
list: {
378386
//flexGrow: 1,
@@ -383,13 +391,13 @@ const styles = StyleSheet.create({
383391
fontSize: 11,
384392
color: 'gray',
385393
backgroundColor: 'white',
386-
textAlignVertical: 'center',
394+
textAlignVertical: 'center'
387395
},
388396
highlightedRowText: {
389-
color: 'black',
397+
color: 'black'
390398
},
391399
separator: {
392400
height: StyleSheet.hairlineWidth,
393-
backgroundColor: 'lightgray',
401+
backgroundColor: 'lightgray'
394402
}
395403
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-modal-dropdown",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "A react-native dropdown component for both iOS and Android.",
55
"keywords": [
66
"react",

0 commit comments

Comments
 (0)