2016-09-07 02:45:08 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-09-07 02:45:08 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2018-08-09 15:32:04 +00:00
|
|
|
* @flow strict-local
|
2016-09-07 02:45:08 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2016-09-07 02:45:08 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const React = require('React');
|
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const Switch = require('Switch');
|
|
|
|
const Text = require('Text');
|
2017-05-06 03:50:47 +00:00
|
|
|
const RNTesterStatePersister = require('./RNTesterStatePersister');
|
2016-09-07 02:45:08 +00:00
|
|
|
const View = require('View');
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
class RNTesterSettingSwitchRow extends React.Component<
|
|
|
|
$FlowFixMeProps,
|
|
|
|
$FlowFixMeState,
|
|
|
|
> {
|
2018-02-08 18:26:45 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(newProps) {
|
2016-09-07 02:45:08 +00:00
|
|
|
const {onEnable, onDisable, persister} = this.props;
|
|
|
|
if (newProps.persister.state !== persister.state) {
|
|
|
|
newProps.persister.state ? onEnable() : onDisable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
const {label, persister} = this.props;
|
|
|
|
return (
|
|
|
|
<View style={styles.row}>
|
|
|
|
<Text>{label}</Text>
|
|
|
|
<Switch
|
|
|
|
value={persister.state}
|
2018-05-11 20:32:37 +00:00
|
|
|
onValueChange={value => {
|
2016-09-07 02:45:08 +00:00
|
|
|
persister.setState(() => value);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
row: {
|
|
|
|
padding: 10,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
},
|
|
|
|
});
|
2018-05-11 20:32:37 +00:00
|
|
|
RNTesterSettingSwitchRow = RNTesterStatePersister.createContainer(
|
|
|
|
RNTesterSettingSwitchRow,
|
|
|
|
{
|
|
|
|
cacheKeySuffix: ({label}) => 'Switch:' + label,
|
|
|
|
getInitialState: ({initialValue}) => initialValue,
|
|
|
|
},
|
|
|
|
);
|
2017-05-06 03:50:47 +00:00
|
|
|
module.exports = RNTesterSettingSwitchRow;
|