我尝试为其创建一个具有特定样式的按钮。我有超过 3 个属性,例如 justifyContent、alignItems、backgroundColor 和 height。我想将另一个组件的样式传递给它,以便按钮的 backgroundColor 属性发生变化。
我的代码:
import React from 'react';
import { Text, TouchableOpacity } from 'react-native';
const Button = ({ buttonName, csCode }) => {
const { buttonStyle, textStyle } = styles;
return (
<TouchableOpacity style={{ buttonStyle, backgroundColor: [csCode] }}>
<Text style={textStyle}>
{buttonName}
</Text>
</TouchableOpacity>
);
};
const styles = {
textStyle: {
alignSelf: 'center',
color: '#ffffff',
fontSize: 35,
fontWeight: '600',
},
buttonStyle: {
justifyContent: 'center',
alignSelf: 'stretch',
height: '20%',
}
};
export { Button };
在这里,buttonStyle 没有应用到按钮上,而是只应用了 backgroundColor 属性。有什么帮助吗?
谢谢。