reactjs - React Native:组件未呈现
问题描述
我正在导入一个自定义组件 (RecipeCard),但它没有出现在屏幕上。
我相当肯定这与我目前使用的样式有关。
fastimage 组件的工作方式与 RN 组件完全相同,可以在此处查看。
任何帮助表示赞赏!
文件 1
<View style={styles.container}>
<Head
headerText={this.props.type}
navigation={this.props.navigation}
backButton
/>
<FlatList
data={this.state.data}
renderItem={({ item }) => <RecipeCard {...item} />}
/>
</View>
const styles = {
container: {
flex: 1
}};
食谱卡
<FastImage
style={styles.imageStyle}
source={{ uri: this.props.image }}
>
<View style={styles.titleContainer}>
<Text style={styles.titleText}>
{this.props.title}
</Text>
<Text style={styles.subtitleText}>
{this.props.subtitle}
</Text>
</View>
</FastImage>
const styles = StyleSheet.create({
imageStyle: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'stretch',
backgroundColor: 'transparent',
},
titleContainer: {
position: 'absolute',
marginTop: 15,
zIndex: 2,
bottom: 13,
flex: 1,
width: '100%',
height: 70,
flexDirection: 'column',
alignItems: 'flex-start',
},
titleText: {
color: 'white',
fontWeight: '800',
paddingLeft: 5,
paddingTop: 10
},
subtitleText: {
color: '#adadad',
fontWeight: '500',
paddingLeft: 5,
paddingTop: 5,
}
});
解决方案
我尝试了您上面给出的示例,我能够看到图像有一点变化imageStyle
,刚刚添加height
并显示图像。
食谱卡组件
const RecipeCard = (props) => {
return (
<FastImage
style={styles.imageStyle}
source={{ uri: 'https://unsplash.it/400/400?image=1' }}
>
<View style={styles.titleContainer}>
<Text style={styles.titleText}>
{props.title}
</Text>
<Text style={styles.subtitleText}>
{props.subtitle}
</Text>
</View>
</FastImage>
);
}
在imageStyle
我添加了height
imageStyle: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'stretch',
backgroundColor: 'transparent',
height: 200
},
希望这可以帮助!
推荐阅读
- python-3.x - 如何在 tkinter 中有效地使用 Schedule Module 而不会出现 GUI Freeze
- prolog - 如何在 Prolog 中表示“Alberich 讨厌除了他自己以外的所有人”?
- iis - 在 Windows Server 2012 R2 上部署 .Net Core 3 - 错误 500.19
- json - 设置嵌套 JSON 对象的属性
- javascript - 如何创建自定义 JS 函数以将图像复制到 R Shiny 中的剪贴板
- c - 在 C 中创建直方图
- python - 如何在不终止进程的情况下关闭 Tkinter 窗口?
- sql - 在使用 OVER() 子句时避免除以零错误,即使在使用 nullif 之后也是如此
- python - 在多个 Seaborn Stripplot 中可视化样本大小
- python - 为什么我使用 Scrapy 在 fetch() 上从特定网站收到错误 429?