Merge branch 'charlesmchen/orientationVsBackgroundScreenshot'

pull/1/head
Matthew Chen 6 years ago
commit 41922dfd27

@ -94,6 +94,7 @@ static NSTimeInterval launchStartedAt;
// The user experience is reasonable: if the user activates the app // The user experience is reasonable: if the user activates the app
// while in landscape, the user sees a rotation animation. // while in landscape, the user sees a rotation animation.
@property (nonatomic) BOOL isLandscapeEnabled; @property (nonatomic) BOOL isLandscapeEnabled;
@property (nonatomic) BOOL shouldEnableLandscape;
@property (nonatomic, nullable) NSTimer *landscapeTimer; @property (nonatomic, nullable) NSTimer *landscapeTimer;
@end @end
@ -180,7 +181,7 @@ static NSTimeInterval launchStartedAt;
- (void)applicationDidEnterBackground:(UIApplication *)application { - (void)applicationDidEnterBackground:(UIApplication *)application {
OWSLogWarn(@"applicationDidEnterBackground."); OWSLogWarn(@"applicationDidEnterBackground.");
[self disableLandscape]; [self updateShouldEnableLandscape];
[DDLog flushLog]; [DDLog flushLog];
} }
@ -188,7 +189,7 @@ static NSTimeInterval launchStartedAt;
- (void)applicationWillEnterForeground:(UIApplication *)application { - (void)applicationWillEnterForeground:(UIApplication *)application {
OWSLogWarn(@"applicationWillEnterForeground."); OWSLogWarn(@"applicationWillEnterForeground.");
[self disableLandscape]; [self updateShouldEnableLandscape];
} }
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
@ -309,6 +310,14 @@ static NSTimeInterval launchStartedAt;
selector:@selector(registrationLockDidChange:) selector:@selector(registrationLockDidChange:)
name:NSNotificationName_2FAStateDidChange name:NSNotificationName_2FAStateDidChange
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(isScreenBlockActiveDidChange:)
name:IsScreenBlockActiveDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reportedApplicationStateDidChange:)
name:ReportedApplicationStateDidChangeNotification
object:nil];
OWSLogInfo(@"application: didFinishLaunchingWithOptions completed."); OWSLogInfo(@"application: didFinishLaunchingWithOptions completed.");
@ -651,7 +660,7 @@ static NSTimeInterval launchStartedAt;
// be called _before_ we become active. // be called _before_ we become active.
[self clearAllNotificationsAndRestoreBadgeCount]; [self clearAllNotificationsAndRestoreBadgeCount];
[self enableLandscapeAfterDelay]; [self updateShouldEnableLandscape];
OWSLogInfo(@"applicationDidBecomeActive completed."); OWSLogInfo(@"applicationDidBecomeActive completed.");
} }
@ -766,7 +775,7 @@ static NSTimeInterval launchStartedAt;
OWSLogWarn(@"applicationWillResignActive."); OWSLogWarn(@"applicationWillResignActive.");
[self disableLandscape]; [self updateShouldEnableLandscape];
[DDLog flushLog]; [DDLog flushLog];
} }
@ -988,6 +997,11 @@ static NSTimeInterval launchStartedAt;
if (!self.isLandscapeEnabled) { if (!self.isLandscapeEnabled) {
return UIInterfaceOrientationMaskPortrait; return UIInterfaceOrientationMaskPortrait;
} }
// We use isAppForegroundAndActive which depends on "reportedApplicationState"
// and therefore is more conservative about being active.
if (!CurrentAppContext().isAppForegroundAndActive) {
return UIInterfaceOrientationMaskPortrait;
}
// This clause shouldn't be necessary, but it's nice to // This clause shouldn't be necessary, but it's nice to
// be explicit about our invariants. // be explicit about our invariants.
if (!self.hasInitialRootViewController) { if (!self.hasInitialRootViewController) {
@ -1026,10 +1040,26 @@ static NSTimeInterval launchStartedAt;
} }
// See comments on isLandscapeEnabled property. // See comments on isLandscapeEnabled property.
- (void)disableLandscape - (void)updateShouldEnableLandscape
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
// We use isAppForegroundAndActive which depends on "reportedApplicationState"
// and therefore is more conservative about being active.
self.shouldEnableLandscape = (CurrentAppContext().isAppForegroundAndActive && [AppReadiness isAppReady]
&& ![OWSWindowManager sharedManager].isScreenBlockActive);
}
// See comments on isLandscapeEnabled property.
- (void)setShouldEnableLandscape:(BOOL)shouldEnableLandscape
{
if (_shouldEnableLandscape == shouldEnableLandscape) {
return;
}
_shouldEnableLandscape = shouldEnableLandscape;
void (^disableLandscape)(void) = ^{
BOOL wasEnabled = self.isLandscapeEnabled; BOOL wasEnabled = self.isLandscapeEnabled;
self.isLandscapeEnabled = NO; self.isLandscapeEnabled = NO;
[self.landscapeTimer invalidate]; [self.landscapeTimer invalidate];
@ -1038,6 +1068,22 @@ static NSTimeInterval launchStartedAt;
if (wasEnabled) { if (wasEnabled) {
[UIViewController attemptRotationToDeviceOrientation]; [UIViewController attemptRotationToDeviceOrientation];
} }
};
if (shouldEnableLandscape) {
disableLandscape();
// Enable Async
NSTimeInterval delay = 0.35f;
self.landscapeTimer = [NSTimer weakScheduledTimerWithTimeInterval:delay
target:self
selector:@selector(enableLandscape)
userInfo:nil
repeats:NO];
} else {
// Disable.
disableLandscape();
}
} }
// See comments on isLandscapeEnabled property. // See comments on isLandscapeEnabled property.
@ -1052,20 +1098,6 @@ static NSTimeInterval launchStartedAt;
[UIViewController attemptRotationToDeviceOrientation]; [UIViewController attemptRotationToDeviceOrientation];
} }
// See comments on isLandscapeEnabled property.
- (void)enableLandscapeAfterDelay
{
OWSAssertIsOnMainThread();
[self disableLandscape];
NSTimeInterval delay = 0.35f;
self.landscapeTimer = [NSTimer weakScheduledTimerWithTimeInterval:delay
target:self
selector:@selector(enableLandscape)
userInfo:nil
repeats:NO];
}
#pragma mark Push Notifications Delegate Methods #pragma mark Push Notifications Delegate Methods
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
@ -1326,6 +1358,8 @@ static NSTimeInterval launchStartedAt;
[self.primaryStorage touchDbAsync]; [self.primaryStorage touchDbAsync];
[self updateShouldEnableLandscape];
// Every time the user upgrades to a new version: // Every time the user upgrades to a new version:
// //
// * Update account attributes. // * Update account attributes.
@ -1388,6 +1422,16 @@ static NSTimeInterval launchStartedAt;
[self enableBackgroundRefreshIfNecessary]; [self enableBackgroundRefreshIfNecessary];
} }
- (void)isScreenBlockActiveDidChange:(NSNotification *)notification
{
[self updateShouldEnableLandscape];
}
- (void)reportedApplicationStateDidChange:(NSNotification *)notification
{
[self updateShouldEnableLandscape];
}
- (void)ensureRootViewController - (void)ensureRootViewController
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();

@ -1,11 +1,13 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import <SignalServiceKit/AppContext.h> #import <SignalServiceKit/AppContext.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
extern NSString *const ReportedApplicationStateDidChangeNotification;
@interface MainAppContext : NSObject <AppContext> @interface MainAppContext : NSObject <AppContext>
@end @end

@ -1,5 +1,5 @@
// //
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2019 Open Whisper Systems. All rights reserved.
// //
#import "MainAppContext.h" #import "MainAppContext.h"
@ -12,6 +12,8 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
NSString *const ReportedApplicationStateDidChangeNotification = @"ReportedApplicationStateDidChangeNotification";
@interface MainAppContext () @interface MainAppContext ()
@property (atomic) UIApplicationState reportedApplicationState; @property (atomic) UIApplicationState reportedApplicationState;
@ -74,6 +76,20 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Notifications #pragma mark - Notifications
- (void)setReportedApplicationState:(UIApplicationState)reportedApplicationState
{
OWSAssertIsOnMainThread();
if (_reportedApplicationState == reportedApplicationState) {
return;
}
_reportedApplicationState = reportedApplicationState;
[[NSNotificationCenter defaultCenter] postNotificationName:ReportedApplicationStateDidChangeNotification
object:nil
userInfo:nil];
}
- (void)applicationWillEnterForeground:(NSNotification *)notification - (void)applicationWillEnterForeground:(NSNotification *)notification
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();

@ -4,6 +4,10 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
extern NSString *const OWSWindowManagerCallDidChangeNotification;
extern NSString *const IsScreenBlockActiveDidChangeNotification;
// This VC can become first responder // This VC can become first responder
// when presented to ensure that the input accessory is updated. // when presented to ensure that the input accessory is updated.
@interface OWSWindowRootViewController : UIViewController @interface OWSWindowRootViewController : UIViewController
@ -12,7 +16,6 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - #pragma mark -
extern NSString *const OWSWindowManagerCallDidChangeNotification;
const CGFloat OWSWindowManagerCallBannerHeight(void); const CGFloat OWSWindowManagerCallBannerHeight(void);
extern const UIWindowLevel UIWindowLevel_Background; extern const UIWindowLevel UIWindowLevel_Background;
@ -28,8 +31,7 @@ extern const UIWindowLevel UIWindowLevel_Background;
@property (nonatomic, readonly) UIWindow *rootWindow; @property (nonatomic, readonly) UIWindow *rootWindow;
@property (nonatomic, readonly) UIWindow *menuActionsWindow; @property (nonatomic, readonly) UIWindow *menuActionsWindow;
@property (nonatomic) BOOL isScreenBlockActive;
- (void)setIsScreenBlockActive:(BOOL)isScreenBlockActive;
- (BOOL)isAppWindow:(UIWindow *)window; - (BOOL)isAppWindow:(UIWindow *)window;

@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
NSString *const OWSWindowManagerCallDidChangeNotification = @"OWSWindowManagerCallDidChangeNotification"; NSString *const OWSWindowManagerCallDidChangeNotification = @"OWSWindowManagerCallDidChangeNotification";
NSString *const IsScreenBlockActiveDidChangeNotification = @"IsScreenBlockActiveDidChangeNotification";
const CGFloat OWSWindowManagerCallBannerHeight(void) const CGFloat OWSWindowManagerCallBannerHeight(void)
{ {
if (@available(iOS 11.4, *)) { if (@available(iOS 11.4, *)) {
@ -146,8 +148,6 @@ const UIWindowLevel UIWindowLevel_MessageActions(void)
// UIWindowLevel_ScreenBlocking() if active. // UIWindowLevel_ScreenBlocking() if active.
@property (nonatomic) UIWindow *screenBlockingWindow; @property (nonatomic) UIWindow *screenBlockingWindow;
@property (nonatomic) BOOL isScreenBlockActive;
@property (nonatomic) BOOL shouldShowCallView; @property (nonatomic) BOOL shouldShowCallView;
@property (nonatomic, nullable) UIViewController *callViewController; @property (nonatomic, nullable) UIViewController *callViewController;
@ -308,6 +308,10 @@ const UIWindowLevel UIWindowLevel_MessageActions(void)
_isScreenBlockActive = isScreenBlockActive; _isScreenBlockActive = isScreenBlockActive;
[self ensureWindowState]; [self ensureWindowState];
[[NSNotificationCenter defaultCenter] postNotificationName:IsScreenBlockActiveDidChangeNotification
object:nil
userInfo:nil];
} }
- (BOOL)isAppWindow:(UIWindow *)window - (BOOL)isAppWindow:(UIWindow *)window

Loading…
Cancel
Save