【问题标题】:React Native Undefined is not a functionReact Native Undefined 不是一个函数
【发布时间】:2016-07-31 23:33:54
【问题描述】:

我正在关注 iOS 的 React Native 教程:https://www.raywenderlich.com/126063/react-native-tutorial

由于 React-Native 中的 Android 教程缺乏,我试图将上面的 iOS 链接传输到 Android,但错误显示为:

我将NavigatorIOS 改为Navigator 内联:

'use strict';
//var React = require('react-native');

import React, {
  AppRegistry,
  Component,
  Navigator,
  Image,
  ListView,
  StyleSheet,
  Text,
  View
} from 'react-native';
var styles = React.StyleSheet.create({
  text: {
    color: 'black',
    backgroundColor: 'white',
    fontSize: 30,
    margin: 80
  },
  container: {
    flex: 1
  }
});


class HelloWorld extends React.Component {
  render() {
    return <React.Text style={styles.text}>Hello World (Again)</React.Text>;    
  }
}


class PropertyFinderApp extends React.Component {
  render() {
    return (
      <Navigator
        style={styles.container}
        initialRoute={{
          title: 'Property Finder',
          component: HelloWorld,
        }}
      />
    );
  }
}

React.AppRegistry.registerComponent('PropertyFinder', function() { return PropertyFinderApp });

我对 React-Native 比较陌生,如何缓解这种情况?

【问题讨论】:

  • 你想复制他们在文档中的例子吗..你似乎没有定义 renderScene...facebook.github.io/react-native/docs/navigator.html#content
  • @Abhay,有 Android React-Native 教程的来源吗?和我找到的一样吗?
  • 我不知道,但我相信 react native 的全部意义在于它应该适用于两者 - 当然,某些功能可能依赖于本地。

标签: android react-native undefined-function


【解决方案1】:

NavigatorIOS(顾名思义)是一个仅限 iO 的组件,其 API 与 Navigator 组件不同。顺便说一下,Navigator 组件是 React Native 团队官方支持的组件,所以这可能是您无论如何都应该尝试使用的组件。

更多信息,比较https://facebook.github.io/react-native/docs/navigatorios.html& https://facebook.github.io/react-native/docs/navigator.html

回到您的工作示例,您需要将 renderScene 属性添加到您的 Navigator 组件。我还更改了 initialRoute,因此它有一个要在 renderScene 方法中识别的键(在我看来,它比传递组件更干净)。

<Navigator
    style={styles.container}
    initialRoute={{
      title: 'Property Finder',
      component: 'HelloWorld',
    }}
    renderScene ={this._renderScene.bind(this)}
  />

然后添加_renderScene方法:

_renderScene(route, navigator) {
    if (route.component == 'HelloWorld') {
      return <HelloWorld />
    }
    // return a default homescreen or something when the route is not matched
   return <Home />
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    • 2019-06-10
    • 2017-10-26
    • 2019-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多