Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Button component with icons and text
  3.  */
  4.  
  5. import React, { memo } from 'react';
  6. import { StyleSheet, TouchableOpacity, View, TextInput, Switch, Platform } from 'react-native';
  7. import { connect } from 'react-redux';
  8. import Palette from '../../../styles/palette';
  9. import MainText from '~/components/UI/Text/MainText';
  10. import ProfileNameText from '~/components/UI/Text/ProfileNameText';
  11. import Badge from '../Badge';
  12. import FastImage from '~/components/UI/FastImageWrapper';
  13. import { createTestingProps } from '~/locators/utils';
  14.  
  15. const
  16.     WRAPPER_VERTICAL_PADDING = 14,
  17.     ICON_DIMENSIONS = 24,
  18.     ICON_RIGHT_MARGIN = 15,
  19.     SUBTITLE_FONT_SIZE = 16;
  20.  
  21. const BlockButton = ({ onPress, icon, tintColor, tinted, color, title, subtitle, grey, subtitleCustom, subtext, value, onChange, badge, arrow, image, switcher, switchVal, iconFlexStart, testID, ...props }) => (
  22.     <TouchableOpacity {...props} {...createTestingProps(testID)} onPress={onPress} activeOpacity={onPress ? 0.16 : 1}>
  23.         <View style={styles.wrapper}>
  24.             {icon &&
  25.                 <FastImage style={[styles.icon, { tintColor }, tinted && { tintColor: color.mainColor }, iconFlexStart && { alignSelf: 'flex-start' }]} source={{ uri: icon }} />
  26.             }
  27.             <View style={styles.textWrap}>
  28.                 <View style={styles.titleWrap}>
  29.                     <MainText style={styles.title}>{title}</MainText>
  30.                 </View>
  31.                 {subtitle &&
  32.                     <View style={icon && styles.subtitleShift}>
  33.                         <ProfileNameText style={[styles.subtext, grey && styles.subtitleGrey, subtitleCustom]} noBold>{subtitle}</ProfileNameText>
  34.                     </View>
  35.                 }
  36.                 {subtext &&
  37.                     <MainText warmGrey>{subtext}</MainText>
  38.                 }
  39.                 {value &&
  40.                     <View style={icon && styles.subtitleShift}>
  41.                         <TextInput
  42.                             style={styles.textInput}
  43.                             value={value}
  44.                             onChangeText={onChange}
  45.                             underlineColorAndroid='transparent'
  46.                             placeholder=''
  47.                         />
  48.                     </View>
  49.                 }
  50.             </View>
  51.             {badge &&
  52.                 <Badge number={badge} />
  53.             }
  54.             {arrow &&
  55.                 <View style={styles.arrowWrap}>
  56.                     <FastImage style={styles.arrowImg} source={{ uri: image.button_arrow, }} />
  57.                 </View>
  58.             }
  59.             {switcher &&
  60.                 <View style={styles.arrowWrap}>
  61.                     <Switch
  62.                         value={switchVal}
  63.                         onValueChange={onChange}
  64.                         trackColor={switchVal ? color.mainColor : Palette.inactive}
  65.                     />
  66.                 </View>
  67.             }
  68.         </View>
  69.     </TouchableOpacity>
  70. );
  71.  
  72. const mapStateToProps = ({ statics: { image, color } }) => ({ image, color });
  73.  
  74. export default memo(connect(mapStateToProps)(BlockButton));
  75.  
  76. const styles = StyleSheet.create({
  77.     wrapper: {
  78.         alignSelf: 'stretch',
  79.         flexDirection: 'row',
  80.         alignItems: 'center',
  81.         paddingVertical: WRAPPER_VERTICAL_PADDING
  82.     },
  83.     icon: {
  84.         width: ICON_DIMENSIONS,
  85.         height: ICON_DIMENSIONS,
  86.         marginRight: ICON_RIGHT_MARGIN,
  87.     },
  88.     arrowWrap: {
  89.         justifyContent: 'center',
  90.         alignItems: 'center',
  91.     },
  92.     arrowImg: {
  93.         width: 24,
  94.         height: 24,
  95.     },
  96.     textWrap: {
  97.         flex: 1,
  98.     },
  99.     titleWrap: {
  100.         justifyContent: 'center',
  101.     },
  102.     title: {
  103.         fontWeight: 'bold',
  104.         fontSize: 16,
  105.     },
  106.     subtitleShift: {
  107.         paddingLeft: ICON_RIGHT_MARGIN * 2 + ICON_DIMENSIONS,
  108.     },
  109.     subtext: {
  110.         marginTop: 8,
  111.     },
  112.     textInput: {
  113.         fontSize: SUBTITLE_FONT_SIZE,
  114.         color: Palette.black,
  115.         marginTop: 8,
  116.     },
  117.     subtitleGrey: {
  118.         color: Palette.warmGrey,
  119.     },
  120. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement