Files
PojavLauncher_iOS/Natives/LauncherSplitViewController.m
Duy Tran Khanh 8577636a4e Fix: user interaction issue on iOS below 14
The following changes apply for iOS 13.7 and below.
* Actually, a fake toolbar view is added on top of the real one, in
order for subviews (the version picker and the play button) to receive
user interaction properly
* Tweaked Split behavior to fix another dead-locked sidebar issue
* The toggle of hiding sidebar is now available
2023-01-19 20:45:34 +07: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 && self.displayMode != UISplitViewControllerDisplayModeSecondaryOnly) {
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 (self.preferredDisplayMode == 0 || self.displayMode != UISplitViewControllerDisplayModeSecondaryOnly) {
if([getPreference(@"hidden_sidebar") boolValue] == NO) {
self.preferredDisplayMode = isPortrait ?
UISplitViewControllerDisplayModeOneOverSecondary :
UISplitViewControllerDisplayModeOneBesideSecondary;
} else {
self.preferredDisplayMode = UISplitViewControllerDisplayModeSecondaryOnly;
}
}
if (@available(iOS 14.0, tvOS 14.0, *)) {
self.preferredSplitBehavior = isPortrait ?
UISplitViewControllerSplitBehaviorOverlay :
UISplitViewControllerSplitBehaviorTile;
}
}
- (void)dismissViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end