【发布时间】:2020-08-17 11:46:02
【问题描述】:
在反应本机登录按钮中,我试图将图标水平向左和垂直放置在中心,并将文本水平和垂直放置在中心。使用下面的代码,只要我将 alignSelf 作为图标上的“中心”,它就会失去其垂直位置。根据文档 alignSelf 应该只覆盖横轴而不是主轴中的属性。这里的图标是 SVG 图标。
const GoogleSignInBtn = ({style, onPress, children}) => {
const {buttonStyles, textStyle, iconStyle} = styles;
return (
<TouchableOpacity onPress={onPress} style={buttonStyles}>
<GoogleIcon style={iconStyle} />
<Text style={textStyle}>{children}</Text>
</TouchableOpacity>
);
};
const styles = {
textStyle: {
color: '#007aff',
fontSize: 16,
fontWeight: '600',
paddingTop: 10,
paddingBottom: 10,
},
buttonStyles: {
justifyContent: 'center',
alignItems: 'center',
marginTop: 5,
flex: 1,
borderRadius: 5,
borderWidth: 1,
borderColor: '#007aff',
marginLeft: 5,
marginRight: 5,
},
iconStyle: {
height: 20,
width: 20,
alignSelf: 'flex-start',
},
[Screen Shot of output][1]};
【问题讨论】:
标签: react-native flexbox