summaryrefslogtreecommitdiff
path: root/frontend/app/components/socialSetting.js
blob: 1c2f2a33c5324029a23450994c9b2d13af3c7491 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import {
  View,
  StyleSheet,
} from 'react-native';
import {
  RkText,
  RkTheme,
} from 'react-native-ui-kitten';
import PropTypes from 'prop-types';
import { RkSwitch } from './switch/index';

export class SocialSetting extends React.Component {
  static propTypes = {
    name: PropTypes.string.isRequired,
    icon: PropTypes.node.isRequired,
    selected: PropTypes.bool,
    tintColor: PropTypes.string,
  };
  static defaultProps = {
    selected: true,
    tintColor: RkTheme.current.colors.accent,
  };

  constructor(props) {
    super(props);
    this.state = {
      selected: this.props.selected,
    };
  }

  onSwitchValueChanged = (value) => {
    this.setState({ selected: value });
  };

  render() {
    const color = this.state.selected ? this.props.tintColor : RkTheme.current.colors.disabled;
    return (
      <View style={styles.container}>
        <View style={styles.left}>
          <RkText rkType='awesome large' style={[styles.icon, { color }]}>{this.props.icon}</RkText>
          <RkText rkType='small' style={{ color }}>{this.props.name}</RkText>
        </View>
        <RkSwitch value={this.state.selected} onValueChange={this.onSwitchValueChanged} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    flex: 1,
    justifyContent: 'space-between',
    alignItems: 'center',
    paddingVertical: 14,
  },
  left: {
    flexDirection: 'row',
    alignItems: 'center',
  },
  icon: {
    width: 35,
    alignItems: 'center',
  },
});