我试图为npm中的react-native安装一个图像幻灯片附加组件。这是指向it的链接 。
然后我使用react-native run-android
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import Slideshow from 'react-native-slideshow';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
position: 1,
interval: null,
dataSource: [
{
title: 'Title 1',
caption: 'Caption 1',
url: 'http://placeimg.com/640/480/any',
}, {
title: 'Title 2',
caption: 'Caption 2',
url: 'http://placeimg.com/640/480/any',
}, {
title: 'Title 3',
caption: 'Caption 3',
url: 'http://placeimg.com/640/480/any',
},
],
};
}
componentWillMount() {
this.setState({
interval: setInterval(() => {
this.setState({
position: this.state.position === this.state.dataSource.length ? 0 : this.state.position + 1
});
}, 2000)
});
}
componentWillUnmount() {
clearInterval(this.state.interval);
}
render() {
return (
<View>
<Slideshow
dataSource={this.state.dataSource}
position={this.state.position}
onPositionChanged={position => this.setState({ position })}
/>
</View>
);
}
}
构建后,我得到一个白色的屏幕,当触摸它时,屏幕将显示以下错误窗口:
如何摆脱这个错误?