【发布时间】:2017-07-21 18:41:22
【问题描述】:
我试图在 React Native 中构建一个背景图像组件,它只能用于本地图像(jpg 和 png)加载(因此在 iOS 中使用 URI),但图像不显示
import React from 'react';
import {Image} from 'react-native';
const BackgroundImage = (props) => {
return (
<Image source={{uri: props.img }} style={styles.backgroundImage}>
{props.children}
</Image>
)
};
const styles = {
backgroundImage: {
flex: 1,
width: null,
height: null,
resizeMode: 'cover'
}
};
export {BackgroundImage};
用法:
const App = () => (
<BackgroundImage img='./assets/img/gradient.jpg'>
<View style={{flex: 1}}>
/* More things */
</View>
</BackgroundImage>
);
【问题讨论】:
标签: javascript image react-native