gpt4 book ai didi

javascript - react native 渐变按钮

转载 作者:行者123 更新时间:2023-12-05 02:17:36 25 4
gpt4 key购买 nike

我的 btn 组件有问题,我正在使用 react-native-linear-gradient 库...

btn.js

import React,{ Component } from 'react';
import {View,Text,StyleSheet, TouchableOpacity} from 'react-native';
import {Button,Item} from 'native-base';

import LinearGradient from 'react-native-linear-gradient';

class GradientBtn extends Component {
constructor(props){
super(props);
}
render(){
return(
<LinearGradient colors={['#d7d7d7', '#fafafa', '#e8e8e8']}
style={[styles.btnContainer,{height:this.props.h,width:this.props.w}]}>
<Text style={styles.btn}>{this.props.name}</Text>
</LinearGradient>





);
}
}

var styles = StyleSheet.create({
btnContainer:{
backgroundColor:'#f0f0f0',
justifyContent:'center',
marginLeft:1
},
btn:{
textAlign:'center',
color:'#000',
fontWeight:'700',
fontSize:12
}
});

export default GradientBtn;

app.js

<View style={{flexDirection:'row',justifyContent:'space-between',marginTop:5}}>
<TouchableOpacity>
<GradientBtn h={35} w={'24.55%'} name="Open Corrective"/>
</TouchableOpacity>
<TouchableOpacity>
<GradientBtn h={35} w={'24.55%'} name="Open Corrective"/>
</TouchableOpacity>
<TouchableOpacity>
<GradientBtn h={35} w={'24.55%'} name="Open Corrective"/>
</TouchableOpacity>
<TouchableOpacity>
<GradientBtn h={35} w={'24.55%'} name="Open Corrective"/>
</TouchableOpacity>
</View>

当我从组件中删除 TouchableOpacity 标签时, View 会正常,但是当我放置此标签时,我想在该 btn 上触摸不透明度,然后我的 View 将压缩意味着宽度并且没有看到正确的 btn..

最佳答案

使用https://www.npmjs.com/package/react-native-linear-gradient

<LinearGradient colors={['#FF00FF', '#FFF000', '#FF0000']}
style={{borderRadius: 20, width: width/3}}
start={{ y: 0.0, x: 0.0 }} end={{ y: 0.0, x: 1.0 }}>

<Button style={{borderRadius: 20, width: width/3,
textAlign: 'center', color: '#fff'}} title={`Welcome`}/>

</LinearGradient>

<LinearGradient colors={['#4c669f', '#3b5998', '#192f6a']} 
style={styles.linearGradient}
start={{ y: 0.0, x: 0.0 }} end={{ y: 0.0, x: 1.0 }}>
<Text style={styles.buttonText}> Done </Text>
</LinearGradient>

const styles = StyleSheet.create({

linearGradient: {
flex: 1,
paddingLeft: 15
paddingRight: 15,
borderRadius: 5
},
buttonText: {
fontSize: 18,
fontFamily: 'Gill Sans',
textAlign: 'center',
margin: 10,
color: '#ffffff',
backgroundColor: 'transparent',
},

});

关于javascript - react native 渐变按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47463055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com