From 3a157d9df673d950d30fda37bb0901276cd39ad8 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 12 Jul 2018 08:58:20 -0600 Subject: [PATCH] window level on iOS11 // FREEBIE --- SignalMessaging/utils/OWSWindowManager.m | 39 +++++++++++++++++++----- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/SignalMessaging/utils/OWSWindowManager.m b/SignalMessaging/utils/OWSWindowManager.m index 94f2a8120..af65f5db1 100644 --- a/SignalMessaging/utils/OWSWindowManager.m +++ b/SignalMessaging/utils/OWSWindowManager.m @@ -55,9 +55,27 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) { // Note: To cover the keyboard, this is higher than the ScreenBlocking level, // but this window is hidden when screen protection is shown. - return CGFLOAT_MAX - 100; + return CGFLOAT_MAX; } + +@interface MessageActionsWindow : UIWindow + +@end + +@implementation MessageActionsWindow + +- (UIWindowLevel)windowLevel +{ + // As of iOS11, setWindowLevel clamps the value below + // the height of the keyboard window. + // Because we want to display above the keyboard, we hardcode + // the `windowLevel` getter. + return UIWindowLevel_MessageActions(); +} + +@end + @implementation OWSWindowRootViewController - (BOOL)canBecomeFirstResponder @@ -184,15 +202,22 @@ const UIWindowLevel UIWindowLevel_MessageActions(void) - (UIWindow *)createMessageActionsWindowWithRoowWindow:(UIWindow *)rootWindow { - UIWindow *window = [[UIWindow alloc] initWithFrame:rootWindow.bounds]; + UIWindow *window; + if (@available(iOS 11, *)) { + // On iOS11, setting the windowLevel is insufficient, so we override + // the `windowLevel` getter. + window = [[MessageActionsWindow alloc] initWithFrame:rootWindow.bounds]; + } else { + // On iOS9, 10 overriding the `windowLevel` getter does not cause the + // window to be displayed above the keyboard, but setting the window + // level works. + window = [[UIWindow alloc] initWithFrame:rootWindow.bounds]; + window.windowLevel = UIWindowLevel_MessageActions(); + } + window.hidden = YES; - window.windowLevel = UIWindowLevel_MessageActions(); - // window.opaque = YES; window.backgroundColor = UIColor.clearColor; - - // window.rootViewController = navigationController; - return window; }