const React = require('react'); const Component = React.Component; const { View, Switch, Slider, StyleSheet, Text, Button, ScrollView } = require('react-native'); const { connect } = require('react-redux'); const { ScreenHeader } = require('lib/components/screen-header.js'); const { _, setLocale } = require('lib/locale.js'); const { BaseScreenComponent } = require('lib/components/base-screen.js'); const { Dropdown } = require('lib/components/Dropdown.js'); const { themeStyle } = require('lib/components/global-style.js'); const { Setting } = require('lib/models/setting.js'); class ConfigScreenComponent extends BaseScreenComponent { static navigationOptions(options) { return { header: null }; } constructor() { super(); this.styles_ = {}; } styles() { const themeId = this.props.theme; const theme = themeStyle(themeId); if (this.styles_[themeId]) return this.styles_[themeId]; this.styles_ = {}; let styles = { body: { flex: 1, justifyContent: 'flex-start', flexDirection: 'column', }, settingContainer: { flex: 1, flexDirection: 'row', borderBottomWidth: 1, borderBottomColor: theme.dividerColor, paddingTop: theme.marginTop, paddingBottom: theme.marginBottom, paddingLeft: theme.marginLeft, paddingRight: theme.marginRight, }, settingText: { fontWeight: 'bold', color: theme.color, fontSize: theme.fontSize, flex: 1, }, settingControl: { color: theme.color, flex: 1, }, } styles.switchSettingText = Object.assign({}, styles.settingText); styles.switchSettingText.width = '80%'; styles.switchSettingContainer = Object.assign({}, styles.settingContainer); styles.switchSettingContainer.flexDirection = 'row'; styles.switchSettingContainer.justifyContent = 'space-between'; styles.switchSettingControl = Object.assign({}, styles.settingControl); delete styles.switchSettingControl.color; styles.switchSettingControl.width = '20%'; this.styles_[themeId] = StyleSheet.create(styles); return this.styles_[themeId]; } settingToComponent(key, value) { const themeId = this.props.theme; const theme = themeStyle(themeId); let output = null; const updateSettingValue = (key, value) => { Setting.setValue(key, value); } const md = Setting.settingMetadata(key); if (md.isEnum) { value = value.toString(); let items = []; const settingOptions = md.options(); for (let k in settingOptions) { if (!settingOptions.hasOwnProperty(k)) continue; items.push({ label: settingOptions[k], value: k.toString() }); } return ( {md.label()} { updateSettingValue(key, itemValue); }} /> ); } else if (md.type == Setting.TYPE_BOOL) { return ( {md.label()} updateSettingValue(key, value)} /> ); } else if (md.type == Setting.TYPE_INT) { return ( {md.label()} updateSettingValue(key, value)} /> ); } else { //throw new Error('Unsupported setting type: ' + setting.type); } return output; } render() { const settings = this.props.settings; let settingComps = []; for (let key in settings) { if (key == 'sync.target') continue; if (!settings.hasOwnProperty(key)) continue; if (!Setting.isPublic(key)) continue; const comp = this.settingToComponent(key, settings[key]); if (!comp) continue; settingComps.push(comp); } //style={this.styles().body} return ( { settingComps } ); } } const ConfigScreen = connect( (state) => { return { settings: state.settings, theme: state.settings.theme, }; } )(ConfigScreenComponent) module.exports = { ConfigScreen };