Files
PojavLauncher_iOS/Natives/LauncherSplitViewController.m
T
Eilionoir Tunnicliff 55f10e7751 2.1.1 - Fix issue with sidebar on iOS 12 and 13
Swapping between OneOver and OneBeside confuses iOS 12/13 and caused issues with opening the sidebar after it has been closed. With this fix, iOS 12 and 13 devices receive a hidden sidebar with no option to change this behavior, whereas iOS 14 and up keep the same behavior. When this is ported to the 2.2 code, there will be an additional option for iOS 14 and up users to swap between a hidden and docked sidebar when in landscape mode.
2022-12-18 17:50:28 -05:00

68 lines
2.5 KiB
Objective-C

#import "LauncherSplitViewController.h"
#import "LauncherMenuViewController.h"
#import "LauncherNavigationController.h"
#import "LauncherPreferences.h"
#import "utils.h"
extern NSMutableDictionary *prefDict;
@interface LauncherSplitViewController ()<UISplitViewControllerDelegate>{
}
@end
@implementation LauncherSplitViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIApplication.sharedApplication.idleTimerDisabled = YES;
setViewBackgroundColor(self.view);
setDefaultValueForPref(prefDict, @"control_safe_area", NSStringFromCGRect(getDefaultSafeArea()));
self.delegate = self;
[self changeDisplayModeForSize:self.view.frame.size];
LauncherMenuViewController *masterVc = [[LauncherMenuViewController alloc] init];
LauncherNavigationController *detailVc = [[LauncherNavigationController alloc] init];
detailVc.toolbarHidden = NO;
self.viewControllers = @[[[UINavigationController alloc] initWithRootViewController:masterVc], detailVc];
}
- (void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode {
if (self.preferredDisplayMode != displayMode) {
dispatch_async(dispatch_get_main_queue(), ^{
self.preferredDisplayMode = UISplitViewControllerDisplayModeSecondaryOnly;
});
}
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[self changeDisplayModeForSize:size];
}
- (void)changeDisplayModeForSize:(CGSize)size {
BOOL isPortrait = size.height > size.width;
if (@available(iOS 14.0, tvOS 14.0, *)) {
if (self.preferredDisplayMode == 0 || self.displayMode != UISplitViewControllerDisplayModeSecondaryOnly) {
self.preferredDisplayMode = isPortrait ?
UISplitViewControllerDisplayModeOneOverSecondary :
UISplitViewControllerDisplayModeOneBesideSecondary;
}
self.preferredSplitBehavior = isPortrait ?
UISplitViewControllerSplitBehaviorOverlay :
UISplitViewControllerSplitBehaviorTile;
} else {
if (self.preferredDisplayMode == 0 || self.displayMode != UISplitViewControllerDisplayModeSecondaryOnly) {
self.preferredDisplayMode = UISplitViewControllerDisplayModeOneOverSecondary;
}
}
}
- (void)dismissViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end