Skip to content

Commit

Permalink
fix(ios): guard against nil proxy in TiViewController
Browse files Browse the repository at this point in the history
CI builds are running into hard crashes, typically on iPad but also
on iPhone. Crash logs indicate underlying null pointer for _proxy.

Fixes TIMOB-27930
  • Loading branch information
sgtcoolguy committed Jul 6, 2020
1 parent 51abc3e commit c2e5fb5
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ - (void)viewDidLayoutSubviews
CGRect bounds = [[self view] bounds];
NSLog(@"TIVIEWCONTROLLER DID LAYOUT SUBVIEWS %.1f %.1f", bounds.size.width, bounds.size.height);
#endif
if (!CGRectEqualToRect([_proxy sandboxBounds], [[self view] bounds])) {
if (_proxy != nil && !CGRectEqualToRect([_proxy sandboxBounds], [[self view] bounds])) {
[_proxy parentSizeWillChange];
}
[super viewDidLayoutSubviews];
Expand Down Expand Up @@ -138,30 +138,34 @@ - (void)loadView

- (void)viewWillAppear:(BOOL)animated
{
[_proxy parentWillShow];
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy viewWillAppear:animated];
if (_proxy != nil) {
[_proxy parentWillShow];
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy viewWillAppear:animated];
}
}
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[_proxy parentWillHide];
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy viewWillDisappear:animated];
if (_proxy != nil) {
[_proxy parentWillHide];
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy viewWillDisappear:animated];
}
}
[super viewWillDisappear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy viewDidAppear:animated];
}
[super viewDidAppear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy viewDidDisappear:animated];
}
[super viewDidDisappear:animated];
Expand All @@ -170,46 +174,46 @@ - (void)viewDidDisappear:(BOOL)animated
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
- (void)presentationControllerWillDismiss:(UIPresentationController *)presentationController
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy presentationControllerWillDismiss:presentationController];
}
}

- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy presentationControllerDidDismiss:presentationController];
}
}
#endif

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

- (void)systemLayoutFittingSizeDidChangeForChildContentContainer:(id<UIContentContainer>)container
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy systemLayoutFittingSizeDidChangeForChildContentContainer:container];
}
[super systemLayoutFittingSizeDidChangeForChildContentContainer:container];
}

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
}
[super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
}

- (void)preferredContentSizeDidChangeForChildContentContainer:(id<UIContentContainer>)container
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
[(id<TiWindowProtocol>)_proxy preferredContentSizeDidChangeForChildContentContainer:container];
}
[super preferredContentSizeDidChangeForChildContentContainer:container];
Expand All @@ -219,34 +223,36 @@ - (void)preferredContentSizeDidChangeForChildContentContainer:(id<UIContentConta

- (BOOL)prefersHomeIndicatorAutoHidden
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
return [(id<TiWindowProtocol>)_proxy homeIndicatorAutoHide];
} else {
return NO;
}

return NO;
}

#pragma mark - Status Bar Appearance

- (BOOL)prefersStatusBarHidden
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
return [(id<TiWindowProtocol>)_proxy hidesStatusBar];
} else {
return NO;
}

return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
if ([_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
if (_proxy != nil && [_proxy conformsToProtocol:@protocol(TiWindowProtocol)]) {
return [(id<TiWindowProtocol>)_proxy preferredStatusBarStyle];
} else if ([[[TiApp app] controller] topContainerController] != nil) {
}

if ([[[TiApp app] controller] topContainerController] != nil) {
// Prefer the style of the most recent view controller.
return [[[[TiApp app] controller] topContainerController] preferredStatusBarStyle];
} else {
return UIStatusBarStyleDefault;
}

return UIStatusBarStyleDefault;
}

- (BOOL)modalPresentationCapturesStatusBarAppearance
Expand Down

0 comments on commit c2e5fb5

Please sign in to comment.