react-native-svg实现渐变边框矩形

import { StyleSheet, View } from "react-native";
import Svg, { LinearGradient, Rect, Stop } from "react-native-svg";

/**
* 带有渐变背景颜色、渐变边框
*/
export function LinearView({
 startColor = "#23040d",
 endColor = "#0e1f22",
 borderStartColor = "#FF1652",
 borderEndColor = "#24F4ED",
 bgColorX2 = "100%",
 bgColorY2 = "100%",
 lineColorX1 = "0",
 lineColorY1 = "0",
 lineColorX2 = "100%",
 lineColorY2 = "100%",
 cornerRadius = 16,
}) {
 return <View style={[StyleSheet.absoluteFill, { overflow: 'hidden' }]}>
   <Svg style={{ width: "100%", height: "100%" }}>
     <LinearGradient id="gradient" x1="0" y1="0" x2={bgColorX2} y2={bgColorY2}>
       <Stop offset="0" stopColor={startColor} />
       <Stop offset="1" stopColor={endColor} />
     </LinearGradient>
     <LinearGradient id="line" x1={lineColorX1} y1={lineColorY1} x2={lineColorX2} y2={lineColorY2}>
       <Stop offset="0" stopColor={borderStartColor} />
       <Stop offset="1" stopColor={borderEndColor} />
     </LinearGradient>
     <Rect width={"100%"}
       height={"100%"}
       fill={"url(#gradient)"}
       stroke={"url(#line)"}
       strokeWidth={1}
       strokeOpacity={0.5}
       strokeLinejoin="miter"
       strokeLinecap="square"
       x={0}
       y={0}
       rx={cornerRadius}//圆角大小
       ry={cornerRadius}
     />
   </Svg>
 </View>
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容