Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 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 | 2x 11x 11x 10x 10x 2x 10x 1x 10x 10x 1x 9x 1x 10x 2x 2x 10x | /*eslint-disable no-console */ import PropTypes from 'prop-types'; import React from 'react'; import { StyleSheet, Text, View, TouchableOpacity } from 'react-native'; import { ViewPropTypes, withTheme } from '../config'; const Badge = props => { const { containerStyle, textStyle, wrapperStyle, onPress, component, value, children, element, theme, ...attributes } = props; if (element) return element; let childElement = ( <Text style={StyleSheet.flatten([styles.text, textStyle && textStyle])}> {value} </Text> ); if (children) { childElement = children; } if (children && value) { console.error('Badge can only contain either child element or value'); } let Component = View; if (component) { Component = component; } else if (onPress) { Component = TouchableOpacity; } return ( <View style={StyleSheet.flatten([ styles.container && wrapperStyle && wrapperStyle, ])} > <Component {...attributes} style={StyleSheet.flatten([ styles.badge(theme), containerStyle && containerStyle, ])} onPress={onPress} > {childElement} </Component> </View> ); }; Badge.propTypes = { containerStyle: ViewPropTypes.style, wrapperStyle: ViewPropTypes.style, textStyle: Text.propTypes.style, children: PropTypes.oneOfType([ PropTypes.element, PropTypes.arrayOf(PropTypes.element), ]), value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), onPress: PropTypes.func, component: PropTypes.func, element: PropTypes.element, theme: PropTypes.object, }; const styles = { container: { flexDirection: 'row', }, badge: theme => ({ padding: 12, paddingTop: 3, paddingBottom: 3, borderRadius: 20, alignItems: 'center', justifyContent: 'center', backgroundColor: theme.colors.primary, }), text: { fontSize: 14, color: 'white', }, }; export { Badge }; export default withTheme(Badge, 'Badge'); |