index.js 2.4 KB
Newer Older
ItbGcthate's avatar
ItbGcthate 已提交
1
import React, {Component} from 'react';
ItbGcthate's avatar
ItbGcthate 已提交
2
import {View, StyleSheet} from 'react-native';
ItbGcthate's avatar
ItbGcthate 已提交
3
import MyButton from '../MyButton';
ItbGcthate's avatar
ItbGcthate 已提交
4
import {bannerStyle} from '../GlobalSetting';
ItbGcthate's avatar
ItbGcthate 已提交
5 6 7 8 9 10

class BannerStyle extends Component {
  constructor() {
    super();
  }

ItbGcthate's avatar
ItbGcthate 已提交
11
  /**
ItbGcthate's avatar
ItbGcthate 已提交
12
   * return a function to change bannerStyle
ItbGcthate's avatar
ItbGcthate 已提交
13 14 15
   * @param num
   * @returns {(function(): void)|*}
   */
ItbGcthate's avatar
ItbGcthate 已提交
16 17
  changeBannerStyle = num => {
    return () => {
ItbGcthate's avatar
ItbGcthate 已提交
18
      bannerStyle.set(num);
ItbGcthate's avatar
ItbGcthate 已提交
19 20 21 22
      this.forceUpdate();
    };
  };

ItbGcthate's avatar
ItbGcthate 已提交
23 24 25
  render() {
    return (
      <View style={styles.container}>
ItbGcthate's avatar
ItbGcthate 已提交
26 27
        <MyButton
          title={'模式1'}
ItbGcthate's avatar
ItbGcthate 已提交
28
          {...styles.myButton1}
ItbGcthate's avatar
ItbGcthate 已提交
29
          onPress={this.changeBannerStyle(1)}
ItbGcthate's avatar
ItbGcthate 已提交
30
          disabled={bannerStyle.get() === 1}
ItbGcthate's avatar
ItbGcthate 已提交
31
        />
ItbGcthate's avatar
ItbGcthate 已提交
32 33
        <MyButton
          title={'模式2'}
ItbGcthate's avatar
ItbGcthate 已提交
34
          {...styles.myButton2}
ItbGcthate's avatar
ItbGcthate 已提交
35
          onPress={this.changeBannerStyle(2)}
ItbGcthate's avatar
ItbGcthate 已提交
36
          disabled={bannerStyle.get() === 2}
ItbGcthate's avatar
ItbGcthate 已提交
37
        />
ItbGcthate's avatar
ItbGcthate 已提交
38 39
        <MyButton
          title={'模式3'}
ItbGcthate's avatar
ItbGcthate 已提交
40
          {...styles.myButton3}
ItbGcthate's avatar
ItbGcthate 已提交
41
          onPress={this.changeBannerStyle(3)}
ItbGcthate's avatar
ItbGcthate 已提交
42
          disabled={bannerStyle.get() === 3}
ItbGcthate's avatar
ItbGcthate 已提交
43
        />
ItbGcthate's avatar
ItbGcthate 已提交
44 45
        <MyButton
          title={'模式4'}
ItbGcthate's avatar
ItbGcthate 已提交
46
          {...styles.myButton4}
ItbGcthate's avatar
ItbGcthate 已提交
47
          onPress={this.changeBannerStyle(4)}
ItbGcthate's avatar
ItbGcthate 已提交
48
          disabled={bannerStyle.get() === 4}
ItbGcthate's avatar
ItbGcthate 已提交
49 50 51 52 53 54 55 56 57 58 59 60
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: '#F2E2CE',
    //opacity: 0.5,
    flex: 1,
  },
ItbGcthate's avatar
ItbGcthate 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  myButton1: {
    textEnabled: {
      color: '#bf7636',
    },
    buttonStyle: {
      width: '75%',
      borderRadius: 15,
      borderWidth: 2,
    },
    buttonEnabled: {
      backgroundColor: '#f7e2c3',
      borderColor: '#c98c55',
    },
  },
  myButton2: {
    textEnabled: {
      color: '#60bed9',
    },
    buttonStyle: {
      width: '75%',
      borderRadius: 15,
      borderWidth: 2,
    },
    buttonEnabled: {
      backgroundColor: '#daeae7',
      borderColor: '#70d1e7',
    },
  },
  myButton3: {
    textEnabled: {
      color: '#ee8bc0',
    },
    buttonStyle: {
      width: '75%',
      borderRadius: 15,
      borderWidth: 2,
    },
    buttonEnabled: {
      backgroundColor: '#f9dbe4',
      borderColor: '#fbb9df',
    },
  },
  myButton4: {
    textEnabled: {
      color: '#d75c4b',
    },
    buttonStyle: {
      width: '75%',
      borderRadius: 15,
      borderWidth: 2,
    },
    buttonEnabled: {
      backgroundColor: '#f1b2a6',
      borderColor: '#e76051',
    },
  },
ItbGcthate's avatar
ItbGcthate 已提交
117 118 119
});

export default BannerStyle;