Skip to content

Commit c053578

Browse files
committed
Merge branch 'dev'
2 parents 0de03bf + baac8eb commit c053578

File tree

6 files changed

+43
-25
lines changed

6 files changed

+43
-25
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
.idea
77

88
npm-debug.log
9+
10+
example/ModalDropdown.js

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ You can find them in the example.
2121

2222
## Update History
2323

24+
### v0.4.1
25+
- Fix bug: [\#27](https://github.com/sohobloo/react-native-modal-dropdown/issues/27) Fix a flex style bug.
26+
- Enhancement: [\#26](https://github.com/sohobloo/react-native-modal-dropdown/issues/26) Support object type of options.
27+
2428
### v0.4.0
2529
- New feature:
2630
[\#10](https://github.com/sohobloo/react-native-modal-dropdown/issues/10) Support touchable component in `renderRow`.
2731
- New feature: [\#11](https://github.com/sohobloo/react-native-modal-dropdown/issues/11) Open `renderSeparator` prop API.
2832
- New feature: Add `adjustFrame` prop for user to adjust the frame style of the dropdown in case the component calculate a mistake frame. \(refer to [#9](https://github.com/sohobloo/react-native-modal-dropdown/issues/5)\) \([code sample](https://github.com/sohobloo/react-native-modal-dropdown/commit/0861d0a1bbe11c221696e8c664ef03ed475a3849#diff-f8c408fd257ff44ce4b01e5f8422b1e1)\)
2933
- Enhancement: Compatible with `react-native` v0.36.0 which has a [break change](https://github.com/facebook/react-native/commit/0a9b6bedb312eba22c5bc11498b1cc41363e5f27) causes the default button with zero size.
30-
- Enhancement: [#16](https://github.com/sohobloo/react-native-modal-dropdown/issues/16) Prevent from warnings if array of styles is used instead of stylesheet or object. Thanks to @NikolaBorislavovHristov .
34+
- Enhancement: [\#16](https://github.com/sohobloo/react-native-modal-dropdown/issues/16) Prevent from warnings if array of styles is used instead of stylesheet or object. Thanks to @NikolaBorislavovHristov .
3135

3236
### v0.3.2
3337
- Fix bug: [\#9](https://github.com/sohobloo/react-native-modal-dropdown/issues/9) *undefined is not an object (evaluating '_this.updatePosition.bind')* in v0.3.1.
@@ -85,7 +89,7 @@ Prop | Type | Optional | Default | Description
8589
`disabled` | bool | Yes | false | disable/enable the component.
8690
`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.**
8791
`defaultValue` | string | Yes | Please select... | Init text of the button. **Invalid in wrapper mode.**
88-
`options` | arrayOf(string)| Yes| | Options. **The dropdown will show a loading indicator if `options` is `null`/`undefined`.**
92+
`options` | array | Yes | | Options. **The dropdown will show a loading indicator if `options` is `null`/`undefined`.**
8993
`style` | object | Yes | | Style of the button.
9094
`textStyle` | object | Yes | | Style of the button text. **Invalid in wrapper mode.**
9195
`dropdownStyle` | object | Yes | | Style of the dropdown list.

components/ModalDropdown.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class ModalDropdown extends Component {
3838
disabled: PropTypes.bool,
3939
defaultIndex: PropTypes.number,
4040
defaultValue: PropTypes.string,
41-
options: PropTypes.arrayOf(PropTypes.string),
41+
options: PropTypes.array,
4242

4343
style: PropTypes.oneOfType([PropTypes.number, PropTypes.object, PropTypes.array]),
4444
textStyle: PropTypes.oneOfType([PropTypes.number, PropTypes.object, PropTypes.array]),
@@ -71,7 +71,7 @@ export default class ModalDropdown extends Component {
7171
}
7272

7373
componentWillReceiveProps(nextProps) {
74-
var buttonText = this._nextValue == null ? this.state.buttonText : this._nextValue;
74+
var buttonText = this._nextValue == null ? this.state.buttonText : this._nextValue.toString();
7575
var selectedIndex = this._nextIndex == null ? this.state.selectedIndex : this._nextIndex;
7676
if (selectedIndex < 0) {
7777
selectedIndex = nextProps.defaultIndex;
@@ -129,7 +129,7 @@ export default class ModalDropdown extends Component {
129129
}
130130

131131
if (idx >= 0) {
132-
value = this.props.options[idx];
132+
value = this.props.options[idx].toString();
133133
}
134134

135135
this._nextValue = value;
@@ -278,31 +278,35 @@ export default class ModalDropdown extends Component {
278278
props.key = preservedProps.key;
279279
props.onPress = preservedProps.onPress;
280280
switch (row.type.displayName) {
281-
case 'TouchableHighlight': {
281+
case 'TouchableHighlight':
282+
{
282283
return (
283284
<TouchableHighlight {...props}>
284285
{row.props.children}
285286
</TouchableHighlight>
286287
);
287288
}
288289
break;
289-
case 'TouchableOpacity': {
290+
case 'TouchableOpacity':
291+
{
290292
return (
291293
<TouchableOpacity {...props}>
292294
{row.props.children}
293295
</TouchableOpacity>
294296
);
295297
}
296298
break;
297-
case 'TouchableWithoutFeedback': {
299+
case 'TouchableWithoutFeedback':
300+
{
298301
return (
299302
<TouchableWithoutFeedback {...props}>
300303
{row.props.children}
301304
</TouchableWithoutFeedback>
302305
);
303306
}
304307
break;
305-
case 'TouchableWithNativeFeedback': {
308+
case 'TouchableWithNativeFeedback':
309+
{
306310
return (
307311
<TouchableWithNativeFeedback {...props}>
308312
{row.props.children}
@@ -328,7 +332,7 @@ export default class ModalDropdown extends Component {
328332
this._nextValue = rowData;
329333
this._nextIndex = rowID;
330334
this.setState({
331-
buttonText: rowData,
335+
buttonText: rowData.toString(),
332336
selectedIndex: rowID,
333337
});
334338
}
@@ -350,18 +354,17 @@ export default class ModalDropdown extends Component {
350354

351355
const styles = StyleSheet.create({
352356
button: {
353-
flexGrow: 1,
354357
justifyContent: 'center',
355358
},
356359
buttonText: {
357360
fontSize: 12,
358361
},
359362
modal: {
360-
flex: 1,
363+
flexGrow: 1,
361364
},
362365
dropdown: {
363366
position: 'absolute',
364-
height: (32 + StyleSheet.hairlineWidth) * 5,
367+
height: (33 + StyleSheet.hairlineWidth) * 5,
365368
borderWidth: StyleSheet.hairlineWidth,
366369
borderColor: 'lightgray',
367370
borderRadius: 2,
@@ -372,14 +375,12 @@ const styles = StyleSheet.create({
372375
alignSelf: 'center',
373376
},
374377
list: {
375-
flex: 1,
378+
//flexGrow: 1,
376379
},
377380
rowText: {
378-
flex: 1,
379381
paddingHorizontal: 6,
382+
paddingVertical: 10,
380383
fontSize: 11,
381-
height: 32,
382-
lineHeight: 32,
383384
color: 'gray',
384385
backgroundColor: 'white',
385386
textAlignVertical: 'center',

example/index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,20 @@ import {
1717
} from 'react-native';
1818

1919
import ModalDropdown from 'react-native-modal-dropdown';
20+
//import ModalDropdown from './ModalDropdown';
2021

2122
const DEMO_OPTIONS_1 = ['option 1', 'option 2', 'option 3', 'option 4', 'option 5', 'option 6', 'option 7', 'option 8', 'option 9'];
23+
const DEMO_OPTIONS_2 = [
24+
{"name": "Rex", "age": 30},
25+
{"name": "Mary", "age": 25},
26+
{"name": "John", "age": 41},
27+
{"name": "Jim", "age": 22},
28+
{"name": "Susan", "age": 52},
29+
{"name": "Brent", "age": 33},
30+
{"name": "Alex", "age": 16},
31+
{"name": "Ian", "age": 20},
32+
{"name": "Phil", "age": 24},
33+
];
2234

2335
class Demo extends Component {
2436
constructor(props) {
@@ -52,7 +64,7 @@ class Demo extends Component {
5264
<ModalDropdown style={styles.dropdown_2}
5365
textStyle={styles.dropdown_2_text}
5466
dropdownStyle={styles.dropdown_2_dropdown}
55-
options={DEMO_OPTIONS_1}
67+
options={DEMO_OPTIONS_2}
5668
renderRow={this._dropdown_2_renderRow.bind(this)}
5769
renderSeparator={(sectionID, rowID, adjacentRowHighlighted) => this._dropdown_2_renderSeparator(sectionID, rowID, adjacentRowHighlighted)}
5870
/>
@@ -127,7 +139,7 @@ class Demo extends Component {
127139
source={icon}
128140
/>
129141
<Text style={[styles.dropdown_2_row_text, highlighted && {color: 'mediumaquamarine'}]}>
130-
{rowData}
142+
{`${rowData.name} (${rowData.age})`}
131143
</Text>
132144
</View>
133145
</TouchableHighlight>
@@ -165,7 +177,8 @@ class Demo extends Component {
165177

166178
_dropdown_4_onSelect(idx, value) {
167179
// BUG: alert in a modal will auto dismiss and causes crash after reload and touch. @sohobloo 2016-12-1
168-
alert(`idx=${idx}, value='${value}'`);
180+
//alert(`idx=${idx}, value='${value}'`);
181+
console.debug(`idx=${idx}, value='${value}'`);
169182
}
170183

171184
_dropdown_5_show() {
@@ -242,8 +255,7 @@ const styles = StyleSheet.create({
242255
backgroundColor: 'cornflowerblue',
243256
},
244257
dropdown_2_text: {
245-
height: 40,
246-
lineHeight: 40,
258+
marginVertical: 10,
247259
marginHorizontal: 6,
248260
fontSize: 18,
249261
color: 'white',
@@ -258,7 +270,6 @@ const styles = StyleSheet.create({
258270
borderRadius: 3,
259271
},
260272
dropdown_2_row: {
261-
flex: 1,
262273
flexDirection: 'row',
263274
height: 40,
264275
alignItems: 'center',

example/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-demo",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "A demo for react-native-modal-dropdown component.",
55
"homepage": "https://github.com/sohobloo/react-native-modal-dropdown",
66
"license": "MIT",

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.0",
3+
"version": "0.4.1",
44
"description": "A react-native dropdown component for both iOS and Android.",
55
"keywords": [
66
"react",

0 commit comments

Comments
 (0)