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
|
||||
{
|
||||
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];
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue