Update examples for the converged Switch component
Reviewed By: mkonicek Differential Revision: D2811302 Pulled By: bestander fb-gh-sync-id: 069dc618510124d6978464979774828c46670124
This commit is contained in:
parent
cb91d652fa
commit
05f31a0cbf
|
@ -1,70 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
|
||||||
*/
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var React = require('React');
|
|
||||||
|
|
||||||
var SwitchAndroid = require('SwitchAndroid');
|
|
||||||
var Text = require('Text');
|
|
||||||
var UIExplorerBlock = require('UIExplorerBlock');
|
|
||||||
var UIExplorerPage = require('UIExplorerPage');
|
|
||||||
|
|
||||||
var SwitchAndroidExample = React.createClass({
|
|
||||||
statics: {
|
|
||||||
title: '<SwitchAndroid>',
|
|
||||||
description: 'Standard Android two-state toggle component.'
|
|
||||||
},
|
|
||||||
|
|
||||||
getInitialState : function() {
|
|
||||||
return {
|
|
||||||
trueSwitchIsOn: true,
|
|
||||||
falseSwitchIsOn: false,
|
|
||||||
colorTrueSwitchIsOn: true,
|
|
||||||
colorFalseSwitchIsOn: false,
|
|
||||||
eventSwitchIsOn: false,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function() {
|
|
||||||
return (
|
|
||||||
<UIExplorerPage title="<SwitchAndroid>">
|
|
||||||
<UIExplorerBlock title="Switches can be set to true or false">
|
|
||||||
<SwitchAndroid
|
|
||||||
onValueChange={(value) => this.setState({falseSwitchIsOn: value})}
|
|
||||||
style={{marginBottom: 10}}
|
|
||||||
value={this.state.falseSwitchIsOn} />
|
|
||||||
<SwitchAndroid
|
|
||||||
onValueChange={(value) => this.setState({trueSwitchIsOn: value})}
|
|
||||||
value={this.state.trueSwitchIsOn} />
|
|
||||||
</UIExplorerBlock>
|
|
||||||
<UIExplorerBlock title="Switches can be disabled">
|
|
||||||
<SwitchAndroid
|
|
||||||
disabled={true}
|
|
||||||
style={{marginBottom: 10}}
|
|
||||||
value={true} />
|
|
||||||
<SwitchAndroid
|
|
||||||
disabled={true}
|
|
||||||
value={false} />
|
|
||||||
</UIExplorerBlock>
|
|
||||||
<UIExplorerBlock title="Change events can be detected">
|
|
||||||
<SwitchAndroid
|
|
||||||
onValueChange={(value) => this.setState({eventSwitchIsOn: value})}
|
|
||||||
style={{marginBottom: 10}}
|
|
||||||
value={this.state.eventSwitchIsOn} />
|
|
||||||
<SwitchAndroid
|
|
||||||
onValueChange={(value) => this.setState({eventSwitchIsOn: value})}
|
|
||||||
style={{marginBottom: 10}}
|
|
||||||
value={this.state.eventSwitchIsOn} />
|
|
||||||
<Text>{this.state.eventSwitchIsOn ? 'On' : 'Off'}</Text>
|
|
||||||
</UIExplorerBlock>
|
|
||||||
<UIExplorerBlock title="Switches are controlled components">
|
|
||||||
<SwitchAndroid />
|
|
||||||
<SwitchAndroid value={true} />
|
|
||||||
</UIExplorerBlock>
|
|
||||||
</UIExplorerPage>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = SwitchAndroidExample;
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
var React = require('react-native');
|
var React = require('react-native');
|
||||||
var {
|
var {
|
||||||
SwitchIOS,
|
Switch,
|
||||||
Text,
|
Text,
|
||||||
View
|
View
|
||||||
} = React;
|
} = React;
|
||||||
|
@ -32,11 +32,11 @@ var BasicSwitchExample = React.createClass({
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<SwitchIOS
|
<Switch
|
||||||
onValueChange={(value) => this.setState({falseSwitchIsOn: value})}
|
onValueChange={(value) => this.setState({falseSwitchIsOn: value})}
|
||||||
style={{marginBottom: 10}}
|
style={{marginBottom: 10}}
|
||||||
value={this.state.falseSwitchIsOn} />
|
value={this.state.falseSwitchIsOn} />
|
||||||
<SwitchIOS
|
<Switch
|
||||||
onValueChange={(value) => this.setState({trueSwitchIsOn: value})}
|
onValueChange={(value) => this.setState({trueSwitchIsOn: value})}
|
||||||
value={this.state.trueSwitchIsOn} />
|
value={this.state.trueSwitchIsOn} />
|
||||||
</View>
|
</View>
|
||||||
|
@ -48,11 +48,11 @@ var DisabledSwitchExample = React.createClass({
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<SwitchIOS
|
<Switch
|
||||||
disabled={true}
|
disabled={true}
|
||||||
style={{marginBottom: 10}}
|
style={{marginBottom: 10}}
|
||||||
value={true} />
|
value={true} />
|
||||||
<SwitchIOS
|
<Switch
|
||||||
disabled={true}
|
disabled={true}
|
||||||
value={false} />
|
value={false} />
|
||||||
</View>
|
</View>
|
||||||
|
@ -70,14 +70,14 @@ var ColorSwitchExample = React.createClass({
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<SwitchIOS
|
<Switch
|
||||||
onValueChange={(value) => this.setState({colorFalseSwitchIsOn: value})}
|
onValueChange={(value) => this.setState({colorFalseSwitchIsOn: value})}
|
||||||
onTintColor="#00ff00"
|
onTintColor="#00ff00"
|
||||||
style={{marginBottom: 10}}
|
style={{marginBottom: 10}}
|
||||||
thumbTintColor="#0000ff"
|
thumbTintColor="#0000ff"
|
||||||
tintColor="#ff0000"
|
tintColor="#ff0000"
|
||||||
value={this.state.colorFalseSwitchIsOn} />
|
value={this.state.colorFalseSwitchIsOn} />
|
||||||
<SwitchIOS
|
<Switch
|
||||||
onValueChange={(value) => this.setState({colorTrueSwitchIsOn: value})}
|
onValueChange={(value) => this.setState({colorTrueSwitchIsOn: value})}
|
||||||
onTintColor="#00ff00"
|
onTintColor="#00ff00"
|
||||||
thumbTintColor="#0000ff"
|
thumbTintColor="#0000ff"
|
||||||
|
@ -99,22 +99,22 @@ var EventSwitchExample = React.createClass({
|
||||||
return (
|
return (
|
||||||
<View style={{ flexDirection: 'row', justifyContent: 'space-around' }}>
|
<View style={{ flexDirection: 'row', justifyContent: 'space-around' }}>
|
||||||
<View>
|
<View>
|
||||||
<SwitchIOS
|
<Switch
|
||||||
onValueChange={(value) => this.setState({eventSwitchIsOn: value})}
|
onValueChange={(value) => this.setState({eventSwitchIsOn: value})}
|
||||||
style={{marginBottom: 10}}
|
style={{marginBottom: 10}}
|
||||||
value={this.state.eventSwitchIsOn} />
|
value={this.state.eventSwitchIsOn} />
|
||||||
<SwitchIOS
|
<Switch
|
||||||
onValueChange={(value) => this.setState({eventSwitchIsOn: value})}
|
onValueChange={(value) => this.setState({eventSwitchIsOn: value})}
|
||||||
style={{marginBottom: 10}}
|
style={{marginBottom: 10}}
|
||||||
value={this.state.eventSwitchIsOn} />
|
value={this.state.eventSwitchIsOn} />
|
||||||
<Text>{this.state.eventSwitchIsOn ? 'On' : 'Off'}</Text>
|
<Text>{this.state.eventSwitchIsOn ? 'On' : 'Off'}</Text>
|
||||||
</View>
|
</View>
|
||||||
<View>
|
<View>
|
||||||
<SwitchIOS
|
<Switch
|
||||||
onValueChange={(value) => this.setState({eventSwitchRegressionIsOn: value})}
|
onValueChange={(value) => this.setState({eventSwitchRegressionIsOn: value})}
|
||||||
style={{marginBottom: 10}}
|
style={{marginBottom: 10}}
|
||||||
value={this.state.eventSwitchRegressionIsOn} />
|
value={this.state.eventSwitchRegressionIsOn} />
|
||||||
<SwitchIOS
|
<Switch
|
||||||
onValueChange={(value) => this.setState({eventSwitchRegressionIsOn: value})}
|
onValueChange={(value) => this.setState({eventSwitchRegressionIsOn: value})}
|
||||||
style={{marginBottom: 10}}
|
style={{marginBottom: 10}}
|
||||||
value={this.state.eventSwitchRegressionIsOn} />
|
value={this.state.eventSwitchRegressionIsOn} />
|
||||||
|
@ -125,10 +125,7 @@ var EventSwitchExample = React.createClass({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.title = '<SwitchIOS>';
|
var examples = [
|
||||||
exports.displayName = 'SwitchExample';
|
|
||||||
exports.description = 'Native boolean input';
|
|
||||||
exports.examples = [
|
|
||||||
{
|
{
|
||||||
title: 'Switches can be set to true or false',
|
title: 'Switches can be set to true or false',
|
||||||
render(): ReactElement { return <BasicSwitchExample />; }
|
render(): ReactElement { return <BasicSwitchExample />; }
|
||||||
|
@ -137,16 +134,24 @@ exports.examples = [
|
||||||
title: 'Switches can be disabled',
|
title: 'Switches can be disabled',
|
||||||
render(): ReactElement { return <DisabledSwitchExample />; }
|
render(): ReactElement { return <DisabledSwitchExample />; }
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: 'Custom colors can be provided',
|
|
||||||
render(): ReactElement { return <ColorSwitchExample />; }
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: 'Change events can be detected',
|
title: 'Change events can be detected',
|
||||||
render(): ReactElement { return <EventSwitchExample />; }
|
render(): ReactElement { return <EventSwitchExample />; }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Switches are controlled components',
|
title: 'Switches are controlled components',
|
||||||
render(): ReactElement { return <SwitchIOS />; }
|
render(): ReactElement { return <Switch />; }
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (React.Platform.OS === 'ios') {
|
||||||
|
examples.push({
|
||||||
|
title: 'Custom colors can be provided',
|
||||||
|
render(): ReactElement { return <ColorSwitchExample />; }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.title = '<Switch>';
|
||||||
|
exports.displayName = 'SwitchExample';
|
||||||
|
exports.description = 'Native boolean input';
|
||||||
|
exports.examples = examples;
|
Binary file not shown.
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 147 KiB |
|
@ -27,7 +27,7 @@ var COMPONENTS = [
|
||||||
require('./ListViewExample'),
|
require('./ListViewExample'),
|
||||||
require('./ProgressBarAndroidExample'),
|
require('./ProgressBarAndroidExample'),
|
||||||
require('./ScrollViewSimpleExample'),
|
require('./ScrollViewSimpleExample'),
|
||||||
require('./SwitchAndroidExample'),
|
require('./SwitchExample'),
|
||||||
require('./RefreshControlExample'),
|
require('./RefreshControlExample'),
|
||||||
require('./PullToRefreshViewAndroidExample.android'),
|
require('./PullToRefreshViewAndroidExample.android'),
|
||||||
require('./TextExample.android'),
|
require('./TextExample.android'),
|
||||||
|
|
|
@ -46,7 +46,7 @@ var COMPONENTS = [
|
||||||
require('./ScrollViewExample'),
|
require('./ScrollViewExample'),
|
||||||
require('./SegmentedControlIOSExample'),
|
require('./SegmentedControlIOSExample'),
|
||||||
require('./SliderIOSExample'),
|
require('./SliderIOSExample'),
|
||||||
require('./SwitchIOSExample'),
|
require('./SwitchExample'),
|
||||||
require('./TabBarIOSExample'),
|
require('./TabBarIOSExample'),
|
||||||
require('./TextExample.ios'),
|
require('./TextExample.ios'),
|
||||||
require('./TextInputExample.ios'),
|
require('./TextInputExample.ios'),
|
||||||
|
|
Loading…
Reference in New Issue