美文网首页
RN渐变按钮

RN渐变按钮

作者: demoly | 来源:发表于2020-12-23 15:52 被阅读0次

react-native渐变效果,渐变背景组件封装

组件文件

import React,{Component} from 'react';
import { Text,StyleSheet } from "react-native";
import { TouchableOpacity } from 'react-native-gesture-handler';
import LinearGradient from 'react-native-linear-gradient';

class GradientBtn extends Component {
    //设置默认值
    static defaultProps={
        sizeStyle:{width:'100%',height:45,borderRadius:22.5,alignSelf:'center'},
        textStyle:{fontSize:18,color:'white'},
        colorStyle:['#9b63cd','#e0708c'],
    }
    render() { 
        return (
            <TouchableOpacity style={{width:'100%',height:'100%',overflow:'hidden',...this.props.sizeStyle}}>
                <LinearGradient start={{x:0,y:0}} end={{x:1,y:0}} colors={this.props.colorStyle} style={styles.linearStyle}>
                    <Text style={this.props.textStyle}>{this.props.children}</Text>
                </LinearGradient>
            </TouchableOpacity>
        );
    }
}

const styles = StyleSheet.create({
    linearStyle:{width:'100%',height:'100%',justifyContent:'center',alignItems:'center'},
});

export default GradientBtn;

使用(自己修改一下导入路径)

import GradientBtn from "../component/gradient_btn";

<GradientBtn sizeStyle={{width:'100%',height:45,borderRadius:22.5,alignSelf:'center'}} textStyle={{fontSize:18,color:'white'}} colorStyle={['#9b63cd','#e0708c']}>获取验证码</GradientBtn>

相关文章

网友评论

      本文标题:RN渐变按钮

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