Skip to content

Commit 9f3bc08

Browse files
committed
Support object options.
#26 Be sure to render your own trigger or I don't know what text to display on it.
1 parent b409774 commit 9f3bc08

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

.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

components/ModalDropdown.js

Lines changed: 4 additions & 4 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;
@@ -332,7 +332,7 @@ export default class ModalDropdown extends Component {
332332
this._nextValue = rowData;
333333
this._nextIndex = rowID;
334334
this.setState({
335-
buttonText: rowData,
335+
buttonText: rowData.toString(),
336336
selectedIndex: rowID,
337337
});
338338
}

example/index.js

Lines changed: 16 additions & 3 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() {

0 commit comments

Comments
 (0)