Prevent setFrame:forView: being called for invalidated views

Reviewed By: @vjeux

Differential Revision: D2459295
This commit is contained in:
Pieter De Baets 2015-09-18 17:18:09 -07:00 committed by facebook-github-bot-8
parent 450cd5c406
commit 19067a8fbc
2 changed files with 11 additions and 12 deletions

View File

@ -19,7 +19,7 @@
@implementation RCTModalHostView
{
RCTBridge *_bridge;
BOOL _hasModalView;
BOOL _isValid;
RCTModalHostViewController *_modalViewController;
RCTTouchHandler *_touchHandler;
}
@ -33,8 +33,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
_bridge = bridge;
_modalViewController = [RCTModalHostViewController new];
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:bridge];
_isValid = YES;
__weak RCTModalHostView *weakSelf = self;
__weak typeof(self) weakSelf = self;
_modalViewController.boundsDidChangeBlock = ^(CGRect newBounds) {
[weakSelf notifyForBoundsChange:newBounds];
};
@ -45,28 +46,26 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
- (void)notifyForBoundsChange:(CGRect)newBounds
{
if (_hasModalView) {
if (_modalViewController.view && _isValid) {
[_bridge.uiManager setFrame:newBounds forView:_modalViewController.view];
}
}
- (NSArray *)reactSubviews
{
return _hasModalView ? @[_modalViewController.view] : @[];
return [NSArray arrayWithObjects:_modalViewController.view, nil];
}
- (void)insertReactSubview:(UIView *)subview atIndex:(__unused NSInteger)atIndex
{
[subview addGestureRecognizer:_touchHandler];
_modalViewController.view = subview;
_hasModalView = YES;
}
- (void)removeReactSubview:(UIView *)subview
{
RCTAssert(subview == _modalViewController.view, @"Cannot remove view other than modal view");
_modalViewController.view = nil;
_hasModalView = NO;
}
- (void)didMoveToSuperview
@ -83,6 +82,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
- (void)invalidate
{
_isValid = NO;
dispatch_async(dispatch_get_main_queue(), ^{
[_modalViewController dismissViewControllerAnimated:self.animated completion:nil];
});

View File

@ -9,18 +9,17 @@
#import "RCTModalHostViewController.h"
@interface RCTModalHostViewController ()
@end
@implementation RCTModalHostViewController
@implementation RCTModalHostViewController {
CGRect _lastViewFrame;
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (self.boundsDidChangeBlock) {
if (self.boundsDidChangeBlock && !CGRectEqualToRect(_lastViewFrame, self.view.frame)) {
self.boundsDidChangeBlock(self.view.bounds);
_lastViewFrame = self.view.frame;
}
}