【发布时间】:2016-05-03 22:08:05
【问题描述】:
我正在尝试让我的自定义 UIView 响应宽度和高度样式,例如
<MyCustomView style={{width: 200, height: 300}}/>
我已经密切关注https://github.com/brentvatne/react-native-dashed-border-example 的简单示例
目前我的 View 和 ViewManager 看起来像:
#import "MyCustomView.h"
#import "RCTViewManager.h"
@implementation MyCustomView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Create the component view
}
return self;
}
@end
和 ViewManager:
@implementation MyCustomViewManager
RCT_EXPORT_MODULE();
- (UIView *)view
{
return [[MyCustomView alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
}
@end
但是,这当然总是填满屏幕。我希望能够设置这个组件的高度,最好使用通过style传递它的RN方法。
如果我遵循简单的边框示例,我最终会得到
@implementation MyCustomView
- (instancetype)init
{
self = [super init];
if (self) {
// Create the component view
}
return self;
}
@end
和
@implementation MyCustomViewManager
RCT_EXPORT_MODULE();
- (UIView *)view
{
return [[MyCustomView alloc] init];
}
@end
但视图不显示,并报告self.bounds.size.height 为 0.00。
有什么我错过了让它工作的东西吗?我需要使用 RCTBridge 吗?我之前确实有这条线
@synthesize bridge = _bridge;
与https://github.com/brentvatne/react-native-dashed-border-example/blob/master/BVDashedBorderViewManager.m#L9 一样,但我收到一条错误消息,提示“未设置网桥”
【问题讨论】:
标签: ios objective-c react-native