Skip to content

Commit

Permalink
fix(iOS)(9_0_X): update content view according to safe area (#11599)
Browse files Browse the repository at this point in the history
* fix(ios): update content view according to safe area

* fix(ios): update content view according to safe area

Co-authored-by: ssekhri <ssekhri@axway.com>
  • Loading branch information
vijaysingh-axway and ssekhri authored Apr 13, 2020
1 parent 01e5798 commit 9b349fb
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion iphone/Classes/TiUIiPadPopoverProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ - (void)dealloc
//This shouldn't happen because we clear it on hide.
currentPopover = nil;
}
[viewController.view removeObserver:self forKeyPath:@"safeAreaInsets"];
RELEASE_TO_NIL(viewController);
RELEASE_TO_NIL(popoverView);
RELEASE_TO_NIL(closingCondition);
Expand Down Expand Up @@ -247,6 +248,7 @@ - (void)cleanup
}

[self forgetSelf];
[viewController.view removeObserver:self forKeyPath:@"safeAreaInsets"];
RELEASE_TO_NIL(viewController);
RELEASE_TO_NIL(popoverView);
[self performSelector:@selector(release) withObject:nil afterDelay:0.5];
Expand Down Expand Up @@ -358,14 +360,36 @@ - (UIViewController *)viewController
if ([contentViewProxy isKindOfClass:[TiWindowProxy class]]) {
[(TiWindowProxy *)contentViewProxy setIsManaged:YES];
viewController = [[(TiWindowProxy *)contentViewProxy hostingController] retain];

[viewController.view addObserver:self forKeyPath:@"safeAreaInsets" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
} else {
viewController = [[TiViewController alloc] initWithViewProxy:contentViewProxy];
[viewController.view addObserver:self forKeyPath:@"safeAreaInsets" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}
}
return viewController;
}

- (void)updateContentViewWithSafeAreaInsets:(UIEdgeInsets)edgeInsets
{
CGFloat oldTop = [[contentViewProxy valueForKey:@"top"] floatValue];
CGFloat oldLeft = [[contentViewProxy valueForKey:@"left"] floatValue];
CGFloat oldRight = [[contentViewProxy valueForKey:@"right"] floatValue];
CGFloat oldBottom = [[contentViewProxy valueForKey:@"bottom"] floatValue];

if (oldTop != edgeInsets.top) {
[contentViewProxy setTop:NUMFLOAT(edgeInsets.top)];
}
if (oldBottom != edgeInsets.bottom) {
[contentViewProxy setBottom:NUMFLOAT(edgeInsets.bottom)];
}
if (oldLeft != edgeInsets.left) {
[contentViewProxy setLeft:NUMFLOAT(edgeInsets.left)];
}
if (oldRight != edgeInsets.right) {
[contentViewProxy setRight:NUMFLOAT(edgeInsets.right)];
}
}

#pragma mark Delegate methods

- (void)proxyDidRelayout:(id)sender
Expand Down Expand Up @@ -434,6 +458,17 @@ - (void)popoverPresentationController:(UIPopoverPresentationController *)popover
popoverPresentationController.sourceRect = *rect;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context
{
if ([TiUtils isIOSVersionOrGreater:@"13.0"] && object == viewController.view && [keyPath isEqualToString:@"safeAreaInsets"]) {
UIEdgeInsets newInsets = [[change objectForKey:@"new"] UIEdgeInsetsValue];
UIEdgeInsets oldInsets = [[change objectForKey:@"old"] UIEdgeInsetsValue];
if (!UIEdgeInsetsEqualToEdgeInsets(oldInsets, newInsets)) {
[self updateContentViewWithSafeAreaInsets:newInsets];
}
}
}

@end

#endif

0 comments on commit 9b349fb

Please sign in to comment.