我正在开发一个 native 应用程序。应用程序屏幕之一包含专辑列表。我已经将每个相册容器分为Card和CardSection组件。
卡可以包含许多CardSection。 CardSection将包含一个图像和2个Text标题。我面临的问题是CardSection中内容的位置,因为flexDirection:'row'
无法正常工作。
这是CardSection.js
import React from 'react';
import {View, Text, Image} from 'react-native';
import Card from './Card';
import CardSection from "./CardSection";
const AlbumDetail = ({album}) => {
// destructing the props
const {title, artist, thumbnail_image} = album;
return (
<Card>
<CardSection>
<View style={styles.thumbnailContainerStyle}>
<Image style={styles.thumbnailStyle} source={{uri: thumbnail_image}} />
</View>
<View style={styles.headerContentStyle} >
<Text style={styles.headerTextStyle}>{title}</Text>
<Text>{artist}</Text>
</View>
</CardSection>
</Card>
);
};
const styles = {
headerContentStyle: {
flexDirection: 'column',
justifyContent: 'space-around'
},
headerTextStyle:{
fontSize:18
},
thumbnailStyle: {
height: 50,
width: 50
},
thumbnailContainerStyle: {
justifyContent: 'center',
alignItems: 'center',
margin: 10,
marginRight: 10
}
};
export default AlbumDetail;
这是CardSection.js
import React from 'react';
import {View} from 'react-native';
const CardSection = (props) => {
return (
<View styles={styles.containerStyle}>
{props.children}
</View>
);
};
const styles = {
containerStyle: {
borderBottomWidth: 1,
padding: 5,
backgroundColor: '#fff',
justifyContent: 'flex-start',
flexDirection: "row",
borderColor: '#ddd',
position: 'relative'
}
};
export default CardSection;
结果是,在图像的左侧和右侧放置的Image将有2个Text标题,其flexDirection将为
column
最佳答案
<View styles={styles.containerStyle}>
你有错字,它是styles
, Prop 应该是style
。
关于reactjs - flexDirection : "row" not working react-native,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51227149/