美文网首页React Native学习
react-native 颜色渐变之react-native-l

react-native 颜色渐变之react-native-l

作者: oc123 | 来源:发表于2018-06-27 17:11 被阅读318次

安装:

npm install react-native-linear-gradient --save-dev
react-native link react-native-linear-gradient  // 自动连接项目

安装之后运行react-native run-android可能会报错,别管多run几次;

例子:

import React from 'react'
import {
  View,
  Text,
  StyleSheet,
  Dimensions,
} from 'react-native'
import LinearGradient from 'react-native-linear-gradient'

class mine extends React.Component {
  constructor(props) {
    super(props)
    this.state = {

    }
  }
  render() {
    const bottomColor = `rgba(0, 0, 0, ${0})`
    const maskColor = `rgba(0, 0, 0, ${0.5})`
    return (
      <View style={{ flex: 1, backgroundColor: 'white' }}>
        <LinearGradient colors={[maskColor, bottomColor]} start={{ x: 0, y: 0 }} end={{ x: 0, y: 1 }} locations={[0, 0.75]} style={styles.linearGradient}>
          <Text style={styles.buttonText}>
            Sign in with Facebook
          </Text>
        </LinearGradient>

      </View>
    )
  }
}
const styles = StyleSheet.create({
  linearGradient: {
    height: 64,
    left: 0,
    top: 0,
    width: Dimensions.get('window').width,
  },
  buttonText: {
    fontSize: 18,
    fontFamily: 'Gill Sans',
    textAlign: 'center',
    margin: 10,
    color: '#ffffff',
    backgroundColor: 'transparent',
  },
})

module.exports = mine

配置:

color

传数组,一定要提供给他不少于两个元素,比如['red','blue'],表示从红到蓝的渐变。

本例用自定义颜色:
colors={[maskColor, bottomColor]}

start

传对象,可选;格式为{x:number,y:number}。坐标从左上角开始,声明渐变开始的位置,作为渐变整体大小的一部分。示例:{x:0.1,y:0.1}表示梯度将从左侧10%、顶部10%开始。

end

同start,指渐变的结束。

本例用例:
start={{ x: 0, y: 0 }}
end={{ x: 0, y: 1 }}

locations

传数组,可选;定义每个渐变颜色停止的位置,映射到颜色相同的索引颜色。例如:[0.1,0.75,1]表示第一种颜色将占0%-10%,第二种颜色将占据10%-75%,最终第三种色彩将占据75%-100%。

在上例的基础上,我们想让bottomColor占比少一点,让他占25%,即从0.75到1这个区间都为bottomColor,[0,0.75]为渐变区间。
locations就可以这样设置:

locations={[0, 0.75]}
本文参考自:https://www.jianshu.com/p/1412cf0ab3e7

自动连接出问题,尝试手动连接项目,官方文档:https://github.com/react-native-community/react-native-linear-gradient/blob/master/README.md

相关文章

  • react-native 颜色渐变之react-native-l

    安装: 安装之后运行react-native run-android可能会报错,别管多run几次; 例子: 配置:...

  • iOS 之渐变颜色

    效果如下: 自己写了一个分类: github完整代码 欢迎转载,转载请注明出处! ps: 主要更新原博客,其他博客...

  • 颜色渐变/渐变高亮/背景颜色渐变

    background: linear-gradient(to right, #ff6034, #ee0a24); ...

  • RN渐变按钮

    react-native渐变效果,渐变背景组件封装 组件文件 使用(自己修改一下导入路径)

  • 7.2.2 实战:用实色渐变制作水晶按钮

    1、选择渐变颜色,渐变工具 2、打开渐变编辑器 3、调整渐变颜色,拖动色标,改变颜色位置 4、拖动动点改变颜色的混...

  • 颜色渐变

    var mesh = creatGradPlane(0,0,0, 100,100, [[0, '#fcc'], [...

  • 颜色渐变

    颜色透明渐变效果 参考链接:UIView 的渐变色呈现CAGradientLayer的一些属性解析

  • 颜色渐变

    线性渐变:background : linear-gradient(起始颜色到结束颜色) 还可以指定角度 默认是从...

  • 颜色渐变

  • 颜色渐变

    在view的layer上添加一个渐变的layer 渐变过程加一个动画

网友评论

    本文标题:react-native 颜色渐变之react-native-l

    本文链接:https://www.haomeiwen.com/subject/wuobyftx.html