」警告:
每當我嘗試,包括我的成分在本地做出反應,我得到這個神祕的警告:
Warning: Native component for "RCTStripe" does not exist
組件確實存在。我爲它創建了一個iOS庫,其中RCTStripeManager.m/h
繼承自RCTViewManager
。 RCTStripe
從RCTView
繼承,並由管理員初始化並返回,等等。所有這些都是建立在另一個完美工作的模塊上的。
發生了什麼事?
下面是一些示例代碼:
RCTStripeManager.h
#import "RCTViewManager.h"
@interface RCTStripeManager : RCTViewManager
@end
RCTStripeManager.m
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#import "RCTLog.h"
#import "RCTStripe.h"
#import "RCTStripeManager.h"
@implementation RCTStripeManager
{
RCTStripe *_stripe;
}
@synthesize bridge = _bridge;
- (UIView *)view
{
_stripe = [[RCTStripe alloc] init];
return _stripe;
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}
RCT_EXPORT_MODULE();
@end
RCTStripe.h
#import "RCTView.h"
@interface RCTStripe : RCTView
@end
RCTStripe.m
#import <Stripe/Stripe.h>
#import "RCTStripe.h"
#import "RCTLog.h"
@implementation RCTStripe
- (id)init
{
if ((self = [super init])) {
// init code here
UILabel *myLabel = [[UILabel alloc] init];
[myLabel setText:@"Hello world"];
[self addSubview:myLabel];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
RCTAssert(self.subviews.count == 1, @"we should only have exactly one subview");
}
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex
{
RCTLogError(@"FBLoginButton does not support subviews");
return;
}
- (void)removeReactSubview:(UIView *)subview
{
RCTLogError(@"FBLoginButton does not support subviews");
return;
}
- (NSArray *)reactSubviews
{
return @[];
}
@end
index.ios.js
var React = require('react-native');
var {
StyleSheet,
NativeModules,
requireNativeComponent,
NativeMethodsMixin,
} = React;
var { StripeManager } = NativeModules;
var SuperStripe = React.createClass({
mixins: [NativeMethodsMixin],
render: function() {
var props = {
...this.props,
style: ([styles.base, this.props.style]),
};
return <RCTStripe {...props} />
},
});
var RCTStripe = requireNativeComponent('RCTStripe', SuperStripe);
var styles = StyleSheet.create({
base: {
width: 300,
height: 300,
},
});
module.exports = SuperStripe;
的完整代碼在https://github.com/lrettig/react-native-stripe。在example/
目錄內,運行npm install
和npm start
,然後打開example/ios/example.xcodeproj
並運行它。
謝謝。
你能指定更精確的步驟來解決這個問題嗎?我很困惑。您是否使用react-native鏈接連接了某些東西? –