我是本机反应的新手,我正在尝试在正在创建的应用程序中使用滑动导航。我已经安装了randomcolor以及native-react-swipe,但是由于某些原因,我仍然遇到错误。
import React, {Component} from 'react';
import Swiper from 'react-native-swiper'
import randomcolor from 'randomcolor'
const {
View,
Text,
StyleSheet
} = React
const styles = StyleSheet.create({
container: {
flex: 1
},
view: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}
});
class TitleText extends React.Component {
render() {
return (
<Text style={{ fontSize: 48, color: 'white' }}>
{this.props.label}
</Text>
)
}
}
class Home extends React.Component {
viewStyle() {
return {
flex: 1,
backgroundColor: randomcolor(),
justifyContent: 'center',
alignItems: 'center',
}
}
render() {
return (
<Swiper
loop={false}
showsPagination={false}
index={1}>
<View style={this.viewStyle()}>
<TitleText label="Left" />
</View>
<Swiper
horizontal={false}
loop={false}
showsPagination={false}
index={1}>
<View style={this.viewStyle()}>
<TitleText label="Top" />
</View>
<View style={this.viewStyle()}>
<TitleText label="Home" />
</View>
<View style={this.viewStyle()}>
<TitleText label="Bottom" />
</View>
</Swiper>
<View style={this.viewStyle()}>
<TitleText label="Right" />
</View>
</Swiper>
)
}
}
export default Home
我得到的错误提示“未定义不是对象(正在评估'StyleSheet.create')”。我已经尝试破解了一段时间,但没有任何运气。 这就是我的代码,任何帮助将不胜感激!
答案 0 :(得分:3)
要访问 React Native components
,您需要从react-native
而非react
import {
View,
Text,
StyleSheet
} from 'react-native'