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>
相关推荐
光影少年2 小时前
RN导航与路由
前端·react native·react.js
沉迷学习 日益消瘦1 天前
7 React Native / Expo 开发体验:项目结构、跨平台适配与构建发布
javascript·react native·react.js
太子釢3 天前
React Native Fabric 渲染链路
react native
光影少年3 天前
RN 原生动画 Animated 用法、动画性能优化
react native·react.js·掘金·金石计划
任磊abc4 天前
react native项目配置eslint+prettier
react native·eslint·prettier
sTone873754 天前
类RN框架通过Service暴露卡片渲染能力给AI Chat
android·react native
想你依然心痛4 天前
【共创季稿事节】HarmonyOS 7.0 应用框架(ArkUI-X)跨平台能力深度探索
flutter·react native·arkui-x·跨平台渲染·harmonyos 7.0·arkrender·组件兼容性
大龄秃头程序员5 天前
RN 新架构 Bridgeless 模式下原生向 RN 发事件:一次踩坑与复盘
react native
大龄秃头程序员5 天前
React Native 0.86 新架构实战:Fabric 原生组件开发的 4 个致命坑
react native