. , <Image>
. . . : https://medium.com/reactnative/background-images-in-react-native-191f3ed95a45
- <Image>
. <Image>
</Image>
. backgroundColor: 'transparent'
. , Android , iPhone . , . React Native . . .
const remote = 'https://s15.postimg.org/tw2qkvmcb/400px.png';
export default class BackgroundImage extends Component {
render() {
const resizeMode = 'center';
const text = 'This is some text inlaid in an <Image />';
return (
<Image
style={{
backgroundColor: '#ccc',
flex: 1,
resizeMode,
position: 'absolute',
width: '100%',
height: '100%',
justifyContent: 'center',
}}
source={{ uri: remote }}
>
<Text
style={{
backgroundColor: 'transparent',
textAlign: 'center',
fontSize: 30,
padding: 40,
}}
>
{text}
</Text>
</Image>
);
}
}
- . <View>
{position:'absolute', width: '100%', height: '100%'}
. <View>
<Image>
flex: 1
. resizeMode
. sibling <View>
{flex: 1, backgroundColor: 'transparent'}
. sibling <View>
. opacity
<Image>
sibling <View>
.
:
const remote = 'https://s15.postimg.org/tw2qkvmcb/400px.png';
export default class BackgroundImage extends Component {
render() {
const resizeMode = 'center';
const text = 'I am some centered text';
return (
<View
style={{
flex: 1,
backgroundColor: '#eee',
}}
>
<View
style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
}}
>
<Image
style={{
flex: 1,
resizeMode,
}}
source={{ uri: remote }}
/>
</View>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
justifyContent: 'center',
}}
>
<Text
style={{
textAlign: 'center',
fontSize: 40,
}}
>
{text}
</Text>
</View>
</View>
);
}
}