0
我試圖在React Native中構建一個背景圖像組件,它只能用於本地圖像(因此使用的是iOS的URI),但是圖片顯示不出來React Native:背景圖片未顯示
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>
);