2016-05-03 6 views
3

カスタムUIViewを幅と高さのスタイルに対応させようとしています。リアクション高さ/幅スタイルに対応するネイティブカスタムiOSビュー

#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:

<MyCustomView style={{width: 200, height: 300}}/> 

私はhttps://github.com/brentvatne/react-native-dashed-border-example

で簡単な例を密接に続いてきた現在、私の見ると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 

で終わるしかし、ビューが表示され、0.00であることをself.bounds.size.heightを報告していません。

これは私が逃したことがありますか?私はRCTBridgeを採用する必要がありますか?私は、以前のラインにhttps://github.com/brentvatne/react-native-dashed-border-example/blob/master/BVDashedBorderViewManager.m#L9のように

@synthesize bridge = _bridge; 

を持っていなかったが、私はあなたのビューでreactSetFrameを上書きすることができます

答えて

3

を「ブリッジが設定されていません」というエラーを持って、それが更新されますたびにフレームへのアクセスを取得します

:あなたがそのファイルの入っていないなら

- (void)reactSetFrame:(CGRect)frame 
{ 
    CGFloat height = frame.size.height; 
    // Do something with the height here 
    [super reactSetFrame: frame]; 
} 

あなたはUIViewの反応カテゴリをインポートする必要がありますによってネイティブレイアウトに反応

+0

私も '#import" UIView + React.h " – Adamski

+0

ありがとう!私はそれを –

関連する問題