Prevent setFrame:forView: being called for invalidated views
Reviewed By: @vjeux Differential Revision: D2459295
This commit is contained in:
parent
450cd5c406
commit
19067a8fbc
|
@ -19,7 +19,7 @@
|
||||||
@implementation RCTModalHostView
|
@implementation RCTModalHostView
|
||||||
{
|
{
|
||||||
RCTBridge *_bridge;
|
RCTBridge *_bridge;
|
||||||
BOOL _hasModalView;
|
BOOL _isValid;
|
||||||
RCTModalHostViewController *_modalViewController;
|
RCTModalHostViewController *_modalViewController;
|
||||||
RCTTouchHandler *_touchHandler;
|
RCTTouchHandler *_touchHandler;
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
|
||||||
_bridge = bridge;
|
_bridge = bridge;
|
||||||
_modalViewController = [RCTModalHostViewController new];
|
_modalViewController = [RCTModalHostViewController new];
|
||||||
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:bridge];
|
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:bridge];
|
||||||
|
_isValid = YES;
|
||||||
|
|
||||||
__weak RCTModalHostView *weakSelf = self;
|
__weak typeof(self) weakSelf = self;
|
||||||
_modalViewController.boundsDidChangeBlock = ^(CGRect newBounds) {
|
_modalViewController.boundsDidChangeBlock = ^(CGRect newBounds) {
|
||||||
[weakSelf notifyForBoundsChange:newBounds];
|
[weakSelf notifyForBoundsChange:newBounds];
|
||||||
};
|
};
|
||||||
|
@ -45,28 +46,26 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
|
||||||
|
|
||||||
- (void)notifyForBoundsChange:(CGRect)newBounds
|
- (void)notifyForBoundsChange:(CGRect)newBounds
|
||||||
{
|
{
|
||||||
if (_hasModalView) {
|
if (_modalViewController.view && _isValid) {
|
||||||
[_bridge.uiManager setFrame:newBounds forView:_modalViewController.view];
|
[_bridge.uiManager setFrame:newBounds forView:_modalViewController.view];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)reactSubviews
|
- (NSArray *)reactSubviews
|
||||||
{
|
{
|
||||||
return _hasModalView ? @[_modalViewController.view] : @[];
|
return [NSArray arrayWithObjects:_modalViewController.view, nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)insertReactSubview:(UIView *)subview atIndex:(__unused NSInteger)atIndex
|
- (void)insertReactSubview:(UIView *)subview atIndex:(__unused NSInteger)atIndex
|
||||||
{
|
{
|
||||||
[subview addGestureRecognizer:_touchHandler];
|
[subview addGestureRecognizer:_touchHandler];
|
||||||
_modalViewController.view = subview;
|
_modalViewController.view = subview;
|
||||||
_hasModalView = YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeReactSubview:(UIView *)subview
|
- (void)removeReactSubview:(UIView *)subview
|
||||||
{
|
{
|
||||||
RCTAssert(subview == _modalViewController.view, @"Cannot remove view other than modal view");
|
RCTAssert(subview == _modalViewController.view, @"Cannot remove view other than modal view");
|
||||||
_modalViewController.view = nil;
|
_modalViewController.view = nil;
|
||||||
_hasModalView = NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didMoveToSuperview
|
- (void)didMoveToSuperview
|
||||||
|
@ -83,6 +82,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
|
||||||
|
|
||||||
- (void)invalidate
|
- (void)invalidate
|
||||||
{
|
{
|
||||||
|
_isValid = NO;
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[_modalViewController dismissViewControllerAnimated:self.animated completion:nil];
|
[_modalViewController dismissViewControllerAnimated:self.animated completion:nil];
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,18 +9,17 @@
|
||||||
|
|
||||||
#import "RCTModalHostViewController.h"
|
#import "RCTModalHostViewController.h"
|
||||||
|
|
||||||
@interface RCTModalHostViewController ()
|
@implementation RCTModalHostViewController {
|
||||||
|
CGRect _lastViewFrame;
|
||||||
@end
|
}
|
||||||
|
|
||||||
@implementation RCTModalHostViewController
|
|
||||||
|
|
||||||
- (void)viewDidLayoutSubviews
|
- (void)viewDidLayoutSubviews
|
||||||
{
|
{
|
||||||
[super viewDidLayoutSubviews];
|
[super viewDidLayoutSubviews];
|
||||||
|
|
||||||
if (self.boundsDidChangeBlock) {
|
if (self.boundsDidChangeBlock && !CGRectEqualToRect(_lastViewFrame, self.view.frame)) {
|
||||||
self.boundsDidChangeBlock(self.view.bounds);
|
self.boundsDidChangeBlock(self.view.bounds);
|
||||||
|
_lastViewFrame = self.view.frame;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue