【发布时间】:2018-02-05 09:24:30
【问题描述】:
第 1 天 React-Native 。尝试在 React-Native 应用程序中加载多个图像。但是,应用程序因错误而崩溃:
错误:组件不能包含子组件。如果你想 在图像顶部呈现内容,请考虑使用
<ImageBackground>组件或绝对定位。
我尝试解决这些现有问题,但未能解决我的问题:
- How to use ImageBackground to set background image for screen in react-native.
- Tile component issues with latest react 0.50.0 #709
还尝试将<ImageBackground> 替换为<Image>,但这也没有解决问题。
这是我的App.js 的代码:
import React, { Component } from 'react';
import {
StyleSheet,
View,
Image
} from 'react-native';
const playIcon = require('./images/play.png');
const volumeIcon = require('./images/sound.png');
const hdIcon = require('./images/hd-sign.png');
const fullScreenIcon = require('./images/full-screen.png');
const remoteImage = { uri:'https://s3.amazonaws.com/crysfel/public/book/new-york.jpg' };
export default class App extends Component<{}> {
render() {
return (
<Image source={remoteImage} style={styles.fullscreen}>
<View style={styles.container}>
<Image source={playIcon} style={styles.icon} />
<Image source={volumeIcon} style={styles.icon} />
<View style={styles.progress}>
<View style={styles.progressBar} />
</View>
<Image source={hdIcon} style={styles.icon} />
<Image source={fullScreenIcon} style={styles.icon} />
</View>
</Image>
);
}
}
const styles = StyleSheet.create({
fullscreen: {
flex: 1,
},
container: {
position: 'absolute',
backgroundColor: '#202020',
borderRadius: 5,
flexDirection: 'row',
height: 50,
padding: 5,
paddingTop: 16,
bottom: 30,
right: 10,
left: 10,
borderWidth: 1,
borderColor: '#303030',
},
icon: {
tintColor: '#fff',
height: 16,
width: 16,
marginLeft: 5,
marginRight: 5,
},
progress: {
backgroundColor: '#000',
borderRadius: 7,
flex: 1,
height: 14,
margin: 10,
marginTop: 2,
},
progressBar: {
backgroundColor: '#bf161c',
borderRadius: 5,
height: 10,
margin: 2,
width: 80,
},
});
什么可能导致此问题以及如何解决?
【问题讨论】:
标签: javascript android ios react-native