在 React Native 中出现 "Undefined is not an object (evaluating StyleSheet.create)" 错误

Getting "Undefined is not an object (evaluating StyleSheet.create)" error in React Native

我是 react-native 的新手,我正在尝试在我正在创建的应用程序中使用滑动导航。我已经安装了 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

我收到的错误是 "undefined is not an object (evaluating 'StyleSheet.create')"。我已经尝试破解它一段时间了,但没有任何运气.. 这就是我的代码,任何帮助将不胜感激!

为了访问 React Native components 您需要从 react-native 而不是 react

导入它们
import {
  View,
  Text,
  StyleSheet
} from 'react-native'