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 {
|
||||
SwitchIOS,
|
||||
Switch,
|
||||
Text,
|
||||
View
|
||||
} = React;
|
||||
|
@ -32,11 +32,11 @@ var BasicSwitchExample = React.createClass({
|
|||
render() {
|
||||
return (
|
||||
<View>
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
onValueChange={(value) => this.setState({falseSwitchIsOn: value})}
|
||||
style={{marginBottom: 10}}
|
||||
value={this.state.falseSwitchIsOn} />
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
onValueChange={(value) => this.setState({trueSwitchIsOn: value})}
|
||||
value={this.state.trueSwitchIsOn} />
|
||||
</View>
|
||||
|
@ -48,11 +48,11 @@ var DisabledSwitchExample = React.createClass({
|
|||
render() {
|
||||
return (
|
||||
<View>
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
disabled={true}
|
||||
style={{marginBottom: 10}}
|
||||
value={true} />
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
disabled={true}
|
||||
value={false} />
|
||||
</View>
|
||||
|
@ -70,14 +70,14 @@ var ColorSwitchExample = React.createClass({
|
|||
render() {
|
||||
return (
|
||||
<View>
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
onValueChange={(value) => this.setState({colorFalseSwitchIsOn: value})}
|
||||
onTintColor="#00ff00"
|
||||
style={{marginBottom: 10}}
|
||||
thumbTintColor="#0000ff"
|
||||
tintColor="#ff0000"
|
||||
value={this.state.colorFalseSwitchIsOn} />
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
onValueChange={(value) => this.setState({colorTrueSwitchIsOn: value})}
|
||||
onTintColor="#00ff00"
|
||||
thumbTintColor="#0000ff"
|
||||
|
@ -99,22 +99,22 @@ var EventSwitchExample = React.createClass({
|
|||
return (
|
||||
<View style={{ flexDirection: 'row', justifyContent: 'space-around' }}>
|
||||
<View>
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
onValueChange={(value) => this.setState({eventSwitchIsOn: value})}
|
||||
style={{marginBottom: 10}}
|
||||
value={this.state.eventSwitchIsOn} />
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
onValueChange={(value) => this.setState({eventSwitchIsOn: value})}
|
||||
style={{marginBottom: 10}}
|
||||
value={this.state.eventSwitchIsOn} />
|
||||
<Text>{this.state.eventSwitchIsOn ? 'On' : 'Off'}</Text>
|
||||
</View>
|
||||
<View>
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
onValueChange={(value) => this.setState({eventSwitchRegressionIsOn: value})}
|
||||
style={{marginBottom: 10}}
|
||||
value={this.state.eventSwitchRegressionIsOn} />
|
||||
<SwitchIOS
|
||||
<Switch
|
||||
onValueChange={(value) => this.setState({eventSwitchRegressionIsOn: value})}
|
||||
style={{marginBottom: 10}}
|
||||
value={this.state.eventSwitchRegressionIsOn} />
|
||||
|
@ -125,10 +125,7 @@ var EventSwitchExample = React.createClass({
|
|||
}
|
||||
});
|
||||
|
||||
exports.title = '<SwitchIOS>';
|
||||
exports.displayName = 'SwitchExample';
|
||||
exports.description = 'Native boolean input';
|
||||
exports.examples = [
|
||||
var examples = [
|
||||
{
|
||||
title: 'Switches can be set to true or false',
|
||||
render(): ReactElement { return <BasicSwitchExample />; }
|
||||
|
@ -137,16 +134,24 @@ exports.examples = [
|
|||
title: 'Switches can be disabled',
|
||||
render(): ReactElement { return <DisabledSwitchExample />; }
|
||||
},
|
||||
{
|
||||
title: 'Custom colors can be provided',
|
||||
render(): ReactElement { return <ColorSwitchExample />; }
|
||||
},
|
||||
{
|
||||
title: 'Change events can be detected',
|
||||
render(): ReactElement { return <EventSwitchExample />; }
|
||||
},
|
||||
{
|
||||
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('./ProgressBarAndroidExample'),
|
||||
require('./ScrollViewSimpleExample'),
|
||||
require('./SwitchAndroidExample'),
|
||||
require('./SwitchExample'),
|
||||
require('./RefreshControlExample'),
|
||||
require('./PullToRefreshViewAndroidExample.android'),
|
||||
require('./TextExample.android'),
|
||||
|
|
|
@ -46,7 +46,7 @@ var COMPONENTS = [
|
|||
require('./ScrollViewExample'),
|
||||
require('./SegmentedControlIOSExample'),
|
||||
require('./SliderIOSExample'),
|
||||
require('./SwitchIOSExample'),
|
||||
require('./SwitchExample'),
|
||||
require('./TabBarIOSExample'),
|
||||
require('./TextExample.ios'),
|
||||
require('./TextInputExample.ios'),
|
||||
|
|
Loading…
Reference in New Issue