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>
相关推荐
朦胧之7 天前
React Native 新架构 (一)
前端·react native
野槐9 天前
react实例与总结(一)
javascript·react native·react.js
GISer_Jing11 天前
React Native:跨平台移动应用开发的明星框架
javascript·react native·react.js
No Silver Bullet12 天前
ReactNative进阶(五十九):存量 react-native 项目适配 HarmonyOS NEXT
react native·react.js·harmonyos
江湖行骗老中医12 天前
React Native 开发 安卓项目构建工具Gradle的配置和使用
android·react native·react.js
@大迁世界12 天前
React Native 列表组件:FlashList、FlatList 及更多
javascript·react native·react.js·ecmascript
screct_demo18 天前
详细介绍 React Native 的动画系统。主要包括 Animated 组件的各种用法:
javascript·react native·react.js
朦胧之19 天前
Expo 框架开发移动应用
前端·react native
@大迁世界20 天前
React Native 0.77 发布:更强的样式支持与性能优化
javascript·react native·react.js·ecmascript
Orange30151122 天前
react-native网络调试工具Reactotron保姆级教程
前端·react native