2015-03-11 02:11:28 +00:00
|
|
|
/**
|
2015-03-26 18:24:15 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
|
|
|
* @flow
|
2015-03-11 02:11:28 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
|
|
|
PickerIOS,
|
|
|
|
Text,
|
|
|
|
View,
|
|
|
|
} = React;
|
|
|
|
|
|
|
|
var PickerItemIOS = PickerIOS.Item;
|
|
|
|
|
|
|
|
var CAR_MAKES_AND_MODELS = {
|
|
|
|
amc: {
|
|
|
|
name: 'AMC',
|
|
|
|
models: ['AMX', 'Concord', 'Eagle', 'Gremlin', 'Matador', 'Pacer'],
|
|
|
|
},
|
|
|
|
alfa: {
|
|
|
|
name: 'Alfa-Romeo',
|
|
|
|
models: ['159', '4C', 'Alfasud', 'Brera', 'GTV6', 'Giulia', 'MiTo', 'Spider'],
|
|
|
|
},
|
|
|
|
aston: {
|
|
|
|
name: 'Aston Martin',
|
|
|
|
models: ['DB5', 'DB9', 'DBS', 'Rapide', 'Vanquish', 'Vantage'],
|
|
|
|
},
|
|
|
|
audi: {
|
|
|
|
name: 'Audi',
|
|
|
|
models: ['90', '4000', '5000', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'Q5', 'Q7'],
|
|
|
|
},
|
|
|
|
austin: {
|
|
|
|
name: 'Austin',
|
|
|
|
models: ['America', 'Maestro', 'Maxi', 'Mini', 'Montego', 'Princess'],
|
|
|
|
},
|
|
|
|
borgward: {
|
|
|
|
name: 'Borgward',
|
|
|
|
models: ['Hansa', 'Isabella', 'P100'],
|
|
|
|
},
|
|
|
|
buick: {
|
|
|
|
name: 'Buick',
|
|
|
|
models: ['Electra', 'LaCrosse', 'LeSabre', 'Park Avenue', 'Regal',
|
|
|
|
'Roadmaster', 'Skylark'],
|
|
|
|
},
|
|
|
|
cadillac: {
|
|
|
|
name: 'Cadillac',
|
|
|
|
models: ['Catera', 'Cimarron', 'Eldorado', 'Fleetwood', 'Sedan de Ville'],
|
|
|
|
},
|
|
|
|
chevrolet: {
|
|
|
|
name: 'Chevrolet',
|
|
|
|
models: ['Astro', 'Aveo', 'Bel Air', 'Captiva', 'Cavalier', 'Chevelle',
|
|
|
|
'Corvair', 'Corvette', 'Cruze', 'Nova', 'SS', 'Vega', 'Volt'],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var PickerExample = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
carMake: 'cadillac',
|
|
|
|
modelIndex: 3,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var make = CAR_MAKES_AND_MODELS[this.state.carMake];
|
|
|
|
var selectionString = make.name + ' ' + make.models[this.state.modelIndex];
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text>Please choose a make for your car:</Text>
|
|
|
|
<PickerIOS
|
|
|
|
selectedValue={this.state.carMake}
|
|
|
|
onValueChange={(carMake) => this.setState({carMake, modelIndex: 0})}>
|
|
|
|
{Object.keys(CAR_MAKES_AND_MODELS).map((carMake) => (
|
|
|
|
<PickerItemIOS
|
|
|
|
key={carMake}
|
|
|
|
value={carMake}
|
|
|
|
label={CAR_MAKES_AND_MODELS[carMake].name}
|
2015-12-08 15:44:56 +00:00
|
|
|
/>
|
|
|
|
))}
|
2015-03-11 02:11:28 +00:00
|
|
|
</PickerIOS>
|
|
|
|
<Text>Please choose a model of {make.name}:</Text>
|
|
|
|
<PickerIOS
|
|
|
|
selectedValue={this.state.modelIndex}
|
|
|
|
key={this.state.carMake}
|
|
|
|
onValueChange={(modelIndex) => this.setState({modelIndex})}>
|
2015-12-08 15:44:56 +00:00
|
|
|
{CAR_MAKES_AND_MODELS[this.state.carMake].models.map((modelName, modelIndex) => (
|
|
|
|
<PickerItemIOS
|
|
|
|
key={this.state.carMake + '_' + modelIndex}
|
|
|
|
value={modelIndex}
|
|
|
|
label={modelName}
|
|
|
|
/>
|
|
|
|
))}
|
2015-03-11 02:11:28 +00:00
|
|
|
</PickerIOS>
|
|
|
|
<Text>You selected: {selectionString}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-12-08 15:44:56 +00:00
|
|
|
var PickerStyleExample = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
carMake: 'cadillac',
|
2015-12-08 21:23:01 +00:00
|
|
|
modelIndex: 0,
|
2015-12-08 15:44:56 +00:00
|
|
|
};
|
|
|
|
},
|
2015-12-08 21:23:01 +00:00
|
|
|
|
2015-12-08 15:44:56 +00:00
|
|
|
render: function() {
|
|
|
|
var make = CAR_MAKES_AND_MODELS[this.state.carMake];
|
|
|
|
var selectionString = make.name + ' ' + make.models[this.state.modelIndex];
|
|
|
|
return (
|
|
|
|
<PickerIOS
|
|
|
|
itemStyle={{fontSize: 25, color: 'red', textAlign: 'left', fontWeight: 'bold'}}
|
|
|
|
selectedValue={this.state.carMake}
|
|
|
|
onValueChange={(carMake) => this.setState({carMake, modelIndex: 0})}>
|
|
|
|
{Object.keys(CAR_MAKES_AND_MODELS).map((carMake) => (
|
|
|
|
<PickerItemIOS
|
|
|
|
key={carMake}
|
|
|
|
value={carMake}
|
|
|
|
label={CAR_MAKES_AND_MODELS[carMake].name}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</PickerIOS>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-06-22 16:43:30 +00:00
|
|
|
exports.displayName = (undefined: ?string);
|
2015-03-11 02:11:28 +00:00
|
|
|
exports.title = '<PickerIOS>';
|
|
|
|
exports.description = 'Render lists of selectable options with UIPickerView.';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: '<PickerIOS>',
|
2015-03-23 22:07:33 +00:00
|
|
|
render: function(): ReactElement {
|
2015-03-11 02:11:28 +00:00
|
|
|
return <PickerExample />;
|
|
|
|
},
|
2015-12-08 15:44:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '<PickerIOS> with custom styling',
|
|
|
|
render: function(): ReactElement {
|
|
|
|
return <PickerStyleExample />;
|
|
|
|
},
|
2015-03-11 02:11:28 +00:00
|
|
|
}];
|