ReactNative实现文本渐变

我们直接上图,可以看到上面文本的效果,使用SVG实现

1.首先还是要引入react-native-svg库

2.使用该库下面的LinearGradient和Text

好,话不多说,我们看具体代码

复制代码
      <Svg width={422} height={30} viewBox={'0 0 422 30'}>
          <Defs>
            <LinearGradient
              id="Gradient"
              gradientUnits="userSpaceOnUse"
              x1="0"
              y1="0"
              x2={constNumberStyle[422]}
              y2="0">
              <Stop offset="0" stopColor={'rgba(49,122,247,1)'} />
              <Stop offset="1" stopColor={'rgba(255,123,76,1)'} />
            </LinearGradient>
            <Text
              id="Text"
              x={211}
              y={24}
              dominant-baseline="middle"
              fontSize={28}
              textAnchor="middle">
              文字是渐变色
            </Text>
          </Defs>
          <Use href="#Text" fill="url(#Gradient)" />
        </Svg>
相关推荐
光影少年8 小时前
react navite 安卓iOS 打包、签名、环境区分
前端·react native·react.js
墨狂之逸才10 小时前
React Native 环境变量方案选型:自定义、react-native-dotenv 与 react-native-config
react native
杉氧13 小时前
React 灵魂:深入剖析 Hooks 与副作用(Side Effects)陷阱
android·前端·react native
光影少年2 天前
react navite调试方案:Flipper、远程调试
前端·javascript·react native·react.js·前端框架
光影少年4 天前
react navite环境与工程化
前端·react native·react.js
真夜5 天前
RN热更新安全问题
前端·react native
杉氧5 天前
从 Modifier 到 Flexbox:React Native 布局与样式设计哲学
android·前端·react native
光影少年8 天前
react native打包优化、包体积瘦身、离线包/热更新方案
前端·react native·react.js