Skip to content

Commit

Permalink
Fixes initial screen size (#4781)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogevbd authored Feb 24, 2019
1 parent f5ada51 commit e036743
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
13 changes: 7 additions & 6 deletions lib/ios/RNNReactRootViewCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@ - (instancetype)initWithBridge:(RCTBridge*)bridge {
return self;
}

- (RNNReactView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
- (RNNReactView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId availableSize:(CGSize)availableSize reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
if (!rootViewId) {
@throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
}

RNNReactView *view = [[RNNReactView alloc] initWithBridge:_bridge
moduleName:name
initialProperties:@{@"componentId": rootViewId}
reactViewReadyBlock:reactViewReadyBlock];
moduleName:name
initialProperties:@{@"componentId": rootViewId}
availableSize:availableSize
reactViewReadyBlock:reactViewReadyBlock];
return view;
}

- (UIView*)createRootViewFromComponentOptions:(RNNComponentOptions*)componentOptions {
return [self createRootView:componentOptions.name.get rootViewId:componentOptions.componentId.get reactViewReadyBlock:nil];
return [self createRootView:componentOptions.name.get rootViewId:componentOptions.componentId.get availableSize:CGSizeZero reactViewReadyBlock:nil];
}

- (UIView*)createRootViewFromComponentOptions:(RNNComponentOptions*)componentOptions reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
return [self createRootView:componentOptions.name.get rootViewId:componentOptions.componentId.get reactViewReadyBlock:reactViewReadyBlock];
return [self createRootView:componentOptions.name.get rootViewId:componentOptions.componentId.get availableSize:CGSizeZero reactViewReadyBlock:reactViewReadyBlock];
}

@end
2 changes: 1 addition & 1 deletion lib/ios/RNNReactView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);

@interface RNNReactView : RCTRootView <RCTRootViewDelegate>

- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock;
- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties availableSize:(CGSize)availableSize reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock;

@property (nonatomic, copy) void (^rootViewDidChangeIntrinsicSize)(CGSize intrinsicSize);
@property (nonatomic, copy) RNNReactViewReadyCompletionBlock reactViewReadyBlock;
Expand Down
3 changes: 2 additions & 1 deletion lib/ios/RNNReactView.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

@implementation RNNReactView

- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
- (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties availableSize:(CGSize)availableSize reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
_reactViewReadyBlock = reactViewReadyBlock;
[bridge.uiManager setAvailableSize:availableSize forRootView:self];

return self;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (void)renderTreeAndWait:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)r
}

__block RNNReactViewReadyCompletionBlock readyBlockCopy = readyBlock;
UIView* reactView = [_creator createRootView:self.layoutInfo.name rootViewId:self.layoutInfo.componentId reactViewReadyBlock:^{
UIView* reactView = [_creator createRootView:self.layoutInfo.name rootViewId:self.layoutInfo.componentId availableSize:[UIScreen mainScreen].bounds.size reactViewReadyBlock:^{
[_presenter renderComponents:self.resolveOptions perform:^{
if (readyBlockCopy) {
readyBlockCopy();
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNRootViewCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@protocol RNNRootViewCreator

- (RNNReactView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock;
- (RNNReactView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId availableSize:(CGSize)availableSize reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock;

- (UIView*)createRootViewFromComponentOptions:(RNNComponentOptions*)componentOptions;

Expand Down

0 comments on commit e036743

Please sign in to comment.