SvgIcon.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* eslint-disable no-underscore-dangle */
  2. import * as React from 'react';
  3. import Svg, { Path } from 'react-native-svg';
  4. import { withTheme } from 'react-native-paper';
  5. import svgMap from '../Utils/SvgUtilsNew';
  6. function Icon(props) {
  7. const { name, type, theme, fillAll, Flip } = props;
  8. let { color, width, height } = props;
  9. const { colors } = theme;
  10. if (type) {
  11. color = colors[type];
  12. }
  13. if (!width) {
  14. width = 32;
  15. }
  16. if (!height) {
  17. height = 32;
  18. }
  19. const svgInfo = svgMap.get(name);
  20. const viewBox = svgInfo
  21. ? svgInfo.viewBox || '0 0 1024 1024'
  22. : '0 0 1024 1024';
  23. const pathList = svgInfo
  24. ? svgInfo.pathList || [
  25. {
  26. ...svgInfo,
  27. },
  28. ]
  29. : [];
  30. let transform = '';
  31. if (Flip) {
  32. transform = `rotate(180 ${svgInfo.defaultWidth / 2} ${
  33. svgInfo.defaultWidth / 2
  34. })`;
  35. }
  36. const pathComList = () => {
  37. return pathList.map((item, index) => {
  38. const pathProps = { ...item };
  39. if ((fillAll || !item.strokeWidth) && color) {
  40. pathProps.fill = color;
  41. }
  42. if (item.strokeWidth && color) {
  43. pathProps.stroke = color;
  44. }
  45. delete pathProps.viewBox;
  46. delete pathProps.defaultWidth;
  47. return <Path {...pathProps} key={index} transform={transform} />;
  48. });
  49. };
  50. return (
  51. <Svg width={width} height={height} viewBox={viewBox}>
  52. {pathComList()}
  53. </Svg>
  54. );
  55. }
  56. export default withTheme(Icon);