【发布时间】:2021-06-13 14:10:23
【问题描述】:
自定义按钮类 从“反应”导入反应,{组件}; 从 'react-native' 导入 {Platform, StyleSheet, Text, View, Button,TouchableOpacity};
导出默认类 FlatButton 扩展组件 { 状态={ 背景颜色:'#f01d71', backgroundColor2: '#f01d71', 按下:假, };
改变颜色(){ 如果(!this.state.pressed){ this.setState({pressed: true,backgroundColor: 'rgb(60,32,140)', backgroundColor2: '#f01d71'}); } 别的 { this.setState({ 按下: false,backgroundColor: '#f01d71', backgroundColor2: '#f01d71'}); } } 使成为() { 返回 (
justifyContent: 'center',
alignItems: 'center',
}}>
<TouchableOpacity
style={{
backgroundColor:this.state.backgroundColor,
borderRadius: 10,
padding: 10,
shadowColor: '#000000',
shadowOffset: {
width: 0,
height: 3
},
shadowRadius: 5,
shadowOpacity: 1.0
}}
onPress={()=>this.changeColor()}
>
<Text style={styles.buttonText}>{this.props.text}</Text>
</TouchableOpacity>
</View>
);
} }
const 样式 = StyleSheet.create({ 文本:{ 白颜色' }, 按钮文本:{ 白颜色', fontWeight : '粗体', 字体大小:16, justifyContent: '中心', }, });
我要渲染的第二个组件 从'react'导入反应,{useState,useEffect}; 从'react-native'导入{Text,View,StyleSheet,Button,Dimensions}; 从 '../shared/FlatButton' 导入 FlatButton const CustomizationView=()=>{ 返回(
</View>
<View style= {styles.btnflex}>
<FlatButton text="Crop" />
<FlatButton text="Crop" />
<FlatButton text="Crop" />
</View>
</View>
);
};
const 样式=StyleSheet.create({ 容器 : { 弹性:1, //边框宽度:5, //边框颜色:'黑色', paddingHorizontal : 10,
},
btnflex : {
flexDirection :'row',
marginTop: 5,
padding : 5,
justifyContent : 'space-between',
borderWidth : 5,
borderColor : 'red'
},
});
导出默认CustomizationView;
输出是 out put is this
【问题讨论】:
标签: react-native