/src/components/icon.js

https://bitbucket.org/LorenK/sdconnect · JavaScript · 53 lines · 46 code · 7 blank · 0 comment · 5 complexity · c22e52e08d7c059f4505df31b689cba1 MD5 · raw file

  1. import React from 'react'
  2. import { TouchableWithoutFeedback, View } from 'react-native'
  3. import MaterialIcon from 'react-native-vector-icons/MaterialIcons'
  4. import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'
  5. export class BasicIcon extends React.Component {
  6. render() {
  7. const { name, comName, size, color, backgroundColor, style } = this.props
  8. let icon
  9. if (comName) {
  10. icon = <MaterialCommunityIcon name={comName} size={size} color={color} style={style} />
  11. } else {
  12. icon = <MaterialIcon name={name} size={size} color={color} style={style} />
  13. }
  14. return (icon)
  15. }
  16. }
  17. export default class SIcon extends React.Component {
  18. render() {
  19. let { onPress, name, comName, size, color, backgroundColor, style } = this.props
  20. let icon
  21. if (comName) {
  22. icon = <MaterialCommunityIcon name={comName} size={size} color={color} style={style} />
  23. } else {
  24. icon = <MaterialIcon name={name} size={size} color={color} style={style} />
  25. }
  26. let content = icon
  27. if (backgroundColor) {
  28. const backgroundSize = size + 20
  29. content =
  30. <View style={{
  31. backgroundColor: backgroundColor,
  32. borderRadius: backgroundSize,
  33. alignItems: 'center',
  34. justifyContent: 'center',
  35. width: backgroundSize,
  36. height: backgroundSize}}>
  37. {icon}
  38. </View>
  39. }
  40. return (
  41. <TouchableWithoutFeedback onPress={onPress}>
  42. {content}
  43. </TouchableWithoutFeedback>
  44. )
  45. }
  46. }