From 19067a8fbc627193fdd2ee89b69e19d73352adc8 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 18 Sep 2015 17:18:09 -0700 Subject: [PATCH] Prevent setFrame:forView: being called for invalidated views Reviewed By: @vjeux Differential Revision: D2459295 --- React/Views/RCTModalHostView.m | 12 ++++++------ React/Views/RCTModalHostViewController.m | 11 +++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/React/Views/RCTModalHostView.m b/React/Views/RCTModalHostView.m index 6ccbf3261..a30f54898 100644 --- a/React/Views/RCTModalHostView.m +++ b/React/Views/RCTModalHostView.m @@ -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]; }); diff --git a/React/Views/RCTModalHostViewController.m b/React/Views/RCTModalHostViewController.m index 196dc6a81..055036726 100644 --- a/React/Views/RCTModalHostViewController.m +++ b/React/Views/RCTModalHostViewController.m @@ -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; } }