VbeLinearGradient.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react';
  2. import Svg, {
  3. Defs,
  4. LinearGradient,
  5. Rect,
  6. Stop,
  7. } from 'react-native-svg';
  8. /**
  9. * 线性渐变色组件
  10. * @param {*} x1表示渲染起始位置的x坐标,y1表示渲染起始位置的y坐标,x2表示渲染结束位置的x坐标,y2表示渲染结束位置的y坐标,colorList表示渲染的颜色,它是一个颜色数组,数组长度必须大于等于2
  11. * @returns VbeLinearGradient
  12. */
  13. const VbeLinearGradient = ({ colorList=[], x1=0, y1=0, x2=50, y2=50 }) => (
  14. <Svg height="100%" width="100%">
  15. <Defs>
  16. <LinearGradient
  17. id="lgrad"
  18. x1={x1+"%"}
  19. y1={y1+"%"}
  20. x2={x2+"%"}
  21. y2={y2+"%"}>
  22. {colorList.map((value, index) => (
  23. <Stop
  24. key={`LinerGradientItem_${index}`}
  25. offset={value.offset}
  26. stopColor={value.color}
  27. stopOpacity={value.opacity}
  28. />
  29. ))}
  30. </LinearGradient>
  31. </Defs>
  32. <Rect x="0" y="0" width="100%" height="100%" fill="url(#lgrad)" />
  33. </Svg>
  34. );
  35. export default VbeLinearGradient;