Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iOS)(9_0_X): update content view according to safe area #11599

Merged
merged 3 commits into from
Apr 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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