From 4f8010023460bdbf6726a22023c9958047ffb1fd Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 18 May 2018 09:37:59 -0400 Subject: [PATCH] Tapping on status bar returns to call We want to render the return-to-call banner behind the status bar, so the user can see the system clock, etc. But normally, doing so would mean we wouldn't receive touches in the top 20px of the screen. // FREEBIE --- Signal/src/AppDelegate.m | 13 +++++++++++++ .../ReturnToCallViewController.swift | 7 +++++++ SignalMessaging/contacts/ViewControllerUtils.h | 1 + SignalMessaging/contacts/ViewControllerUtils.m | 2 ++ 4 files changed, 23 insertions(+) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 71eefb5a3..49e60c194 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -1162,4 +1162,17 @@ static NSTimeInterval launchStartedAt; [AppUpdateNag.sharedInstance showAppUpgradeNagIfNecessary]; } +#pragma mark - status bar touches + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + [super touchesBegan:touches withEvent:event]; + CGPoint location = [[[event allTouches] anyObject] locationInView:[self window]]; + CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; + if (CGRectContainsPoint(statusBarFrame, location)) { + DDLogDebug(@"%@ touched status bar", self.logTag); + [[NSNotificationCenter defaultCenter] postNotificationName:TappedStatusBarNotification object:nil]; + } +} + @end diff --git a/SignalMessaging/ViewControllers/ReturnToCallViewController.swift b/SignalMessaging/ViewControllers/ReturnToCallViewController.swift index 2b5873d05..92e0d2292 100644 --- a/SignalMessaging/ViewControllers/ReturnToCallViewController.swift +++ b/SignalMessaging/ViewControllers/ReturnToCallViewController.swift @@ -17,6 +17,7 @@ public class ReturnToCallViewController: UIViewController { let returnToCallLabel = UILabel() public func startAnimating() { + NotificationCenter.default.addObserver(self, selector: #selector(didTapStatusBar(notification:)), name: .TappedStatusBar, object: nil) self.returnToCallLabel.layer.removeAllAnimations() self.returnToCallLabel.alpha = 1 UIView.animate(withDuration: 1, @@ -27,6 +28,7 @@ public class ReturnToCallViewController: UIViewController { } public func stopAnimating() { + NotificationCenter.default.removeObserver(self, name: .TappedStatusBar, object: nil) self.returnToCallLabel.layer.removeAllAnimations() } @@ -56,6 +58,11 @@ public class ReturnToCallViewController: UIViewController { self.delegate?.returnToCallWasTapped(self) } + @objc + public func didTapStatusBar(notification: Notification) { + self.delegate?.returnToCallWasTapped(self) + } + override public func viewWillLayoutSubviews() { Logger.debug("\(self.logTag) in \(#function)") diff --git a/SignalMessaging/contacts/ViewControllerUtils.h b/SignalMessaging/contacts/ViewControllerUtils.h index 168c3d553..bedba7671 100644 --- a/SignalMessaging/contacts/ViewControllerUtils.h +++ b/SignalMessaging/contacts/ViewControllerUtils.h @@ -8,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN extern const NSUInteger kMin2FAPinLength; extern const NSUInteger kMax2FAPinLength; +extern NSString *const TappedStatusBarNotification; @interface ViewControllerUtils : NSObject diff --git a/SignalMessaging/contacts/ViewControllerUtils.m b/SignalMessaging/contacts/ViewControllerUtils.m index eb9406cea..6215e4c3e 100644 --- a/SignalMessaging/contacts/ViewControllerUtils.m +++ b/SignalMessaging/contacts/ViewControllerUtils.m @@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN +NSString *const TappedStatusBarNotification = @"TappedStatusBarNotification"; + const NSUInteger kMin2FAPinLength = 4; const NSUInteger kMax2FAPinLength = 16;