我试图通过使用文档中的EXPO示例来配置我的应用程序,同时它显示语法错误

时间:2017-12-22 09:10:33

标签: react-native react-native-android react-native-ios expo

我正在尝试使用在expo文档中找到的代码。我已经包含了我沉思的图像和字体,而它在离子线字体上显示出奇怪的错误,如预期的那样。虽然它是正确的。我找不到有什么问题?

function cacheImages(images) {
  return images.map(image => {
    if (typeof image === 'string') {
      return Image.prefetch(image);
    } else {
      return Asset.fromModule(image).downloadAsync();
    }
  });
}

function cacheFonts(fonts) {
  return fonts.map(font => Font.loadAsync(font));
}

export default class App extends React.Component {
   constructor() {
    super();
    this.state = {
     isReady: false,
      store: configureStore(() => this.setState({ isLoading: false })),
      mainApplication: false,
    };
  }


  async _loadAssetsAsync() {
    const imageAssets = cacheImages([
     require("./assets/icons/app.png"),
      require("./assets/icons/loading.png"),
      require("./img/img1.jpg"),
      require("./img/img2.jpg"),
      require("./img/img3.jpg"),

    ]);

    const fontAssets = cacheFonts([
     Ionicons: require("@expo/vector-icons/fonts/Ionicons.ttf"),
        Arial: require("native-base/Fonts/Roboto.ttf"),
        Roboto: require("native-base/Fonts/Roboto.ttf"),
        Roboto_medium: require("native-base/Fonts/Roboto_medium.ttf"),]);

    await Promise.all([...imageAssets, ...fontAssets]);
  }

 render() {
    if (!this.state.isReady) {
      return (
        <AppLoading
          startAsync={this._loadAssetsAsync}
          onFinish={() => this.setState({ isReady: true })}
          onError={console.warn}
        />
      );
    }
else {
    return (
      return  <Provider store={this.state.store}>
      <Root>
            <Nav/>
            </Root>
</Provider>;
    );
  }
}

此代码有什么问题,我该如何解决?

1 个答案:

答案 0 :(得分:0)

这些步骤可以帮助您解决问题:

  1. 检查package.json中的react-native-vector-icons是否为依赖项,如果存在则将其删除
  2. 运行npm install @expo/vector-icons --save
  3. 删除node_modules文件夹并再次运行npm install