2015-12-10 55 views
4

我正在尝试使用ios工具栏并将其导入组件以用于反应原生。我不明白我出错的地方。当我使用var Tool = require('toolkit.ios.js');React原生自定义组件

时出现错误“uknown module Toolkit.ios.js”该文件在那里。我在这里错过了什么? 我想在这里按照这个教程,但使用工具栏组件 https://facebook.github.io/react-native/docs/native-components-ios.html#content

#import <Foundation/Foundation.h> 

@import UIKit; 

#import "RCTViewManager.h" 

@interface RCTToolBar : RCTViewManager 
@end 

@implementation RCTToolBar 


RCT_EXPORT_MODULE() 

- (UIView *)view 
{ 
    return [[UIToolbar alloc] init]; 
} 

@end 

// MapView.js

var React = require('react-native'); 
var { requireNativeComponent } = React; 

// requireNativeComponent automatically resolves this to "RCTMapManager" 

class ToolBar extends React.Component { 
    render() { 
    return <RCTToolBar />; 
    } 
} 

module.exports = requireNativeComponent('RCTToolBar', ToolBar); 

编辑:在复制和粘贴代码搞砸。

回答

2

你需要需要使用相对路径的文件,是这样的:var Tool = require('./path/to/componenttoolkit')

而且,你不需要在你需要声明ios.js,包装者是足够聪明,知道你的组件是什么,当您想拥有跨平台组件时,这也将最终有助于您。

+0

这是问题的一部分,另一个是因为我正在按照该示例命名文件RCTMapManager.m,它们已经存在,所以我得到了重复的引用。感谢您的意见。 –