From 50a56a4b6890a090da40b4cf44b9845d0ba4d2c5 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 1 Sep 2024 01:00:15 +0300 Subject: [PATCH] UI fixes --- iOS/GBActivityViewController.h | 5 ++++ iOS/GBActivityViewController.m | 10 +++++++ iOS/GBBackgroundView.m | 6 +++++ iOS/GBCheckableAlertController.m | 43 ++++++++++++++++++----------- iOS/GBPrinterFeedController.h | 1 - iOS/GBPrinterFeedController.m | 46 ++++++++++++++++++++++---------- iOS/GBViewController.m | 31 +++++++++++---------- 7 files changed, 97 insertions(+), 45 deletions(-) create mode 100644 iOS/GBActivityViewController.h create mode 100644 iOS/GBActivityViewController.m diff --git a/iOS/GBActivityViewController.h b/iOS/GBActivityViewController.h new file mode 100644 index 0000000..adf5af6 --- /dev/null +++ b/iOS/GBActivityViewController.h @@ -0,0 +1,5 @@ +#import + +@interface GBActivityViewController : UIActivityViewController + +@end diff --git a/iOS/GBActivityViewController.m b/iOS/GBActivityViewController.m new file mode 100644 index 0000000..0c436a5 --- /dev/null +++ b/iOS/GBActivityViewController.m @@ -0,0 +1,10 @@ +#import "GBActivityViewController.h" + +@implementation GBActivityViewController + +- (UIModalPresentationStyle)modalPresentationStyle +{ + return UIModalPresentationFormSheet; +} + +@end diff --git a/iOS/GBBackgroundView.m b/iOS/GBBackgroundView.m index 57f4c84..e061542 100644 --- a/iOS/GBBackgroundView.m +++ b/iOS/GBBackgroundView.m @@ -487,6 +487,12 @@ static GB_key_mask_t angleToKeyMask(double angle) screenFrame.origin.y += 8; screenFrame.size.width -= 16; screenFrame.size.height -= 16; + + if (@available(iOS 13.0, *)) { + self.overrideUserInterfaceStyle = layout.theme.isDark? UIUserInterfaceStyleDark : UIUserInterfaceStyleLight; + self.tintColor = layout.theme.brandColor; + } + _screenLabel.frame = screenFrame; } diff --git a/iOS/GBCheckableAlertController.m b/iOS/GBCheckableAlertController.m index d1d2b98..9b9ae73 100644 --- a/iOS/GBCheckableAlertController.m +++ b/iOS/GBCheckableAlertController.m @@ -1,5 +1,11 @@ #import "GBCheckableAlertController.h" +/* Private API */ +@interface UIAlertAction() +- (bool)_isChecked; +- (void)_setChecked:(bool)checked; +@end + @implementation GBCheckableAlertController { bool _addedChecks; @@ -7,25 +13,30 @@ - (void)viewWillAppear:(BOOL)animated { - if (!_addedChecks && _selectedAction) { - _addedChecks = true; - NSMutableSet *set = [NSMutableSet setWithObject:self.view]; - while (set.count) { - UIView *view = [set anyObject]; - [set removeObject:view]; - if ([view.debugDescription containsString:_selectedAction.debugDescription]) { - UIImageView *checkImage = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"checkmark"]]; - CGRect bounds = view.bounds; - CGRect frame = checkImage.frame; - frame.origin.x = bounds.size.width - frame.size.width - 12; - frame.origin.y = round((bounds.size.height - frame.size.height) / 2); - checkImage.frame = frame; - [view addSubview:checkImage]; - break; + if (@available(iOS 13.0, *)) { + if (!_addedChecks && _selectedAction) { + _addedChecks = true; + NSMutableSet *set = [NSMutableSet setWithObject:self.view]; + while (set.count) { + UIView *view = [set anyObject]; + [set removeObject:view]; + if ([view.debugDescription containsString:_selectedAction.debugDescription]) { + UIImageView *checkImage = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"checkmark"]]; + CGRect bounds = view.bounds; + CGRect frame = checkImage.frame; + frame.origin.x = bounds.size.width - frame.size.width - 12; + frame.origin.y = round((bounds.size.height - frame.size.height) / 2); + checkImage.frame = frame; + [view addSubview:checkImage]; + break; + } + [set addObjectsFromArray:view.subviews]; } - [set addObjectsFromArray:view.subviews]; } } + else { + [_selectedAction _setChecked:true]; + } [super viewWillAppear:animated]; } diff --git a/iOS/GBPrinterFeedController.h b/iOS/GBPrinterFeedController.h index fda34e5..ca4ac2e 100644 --- a/iOS/GBPrinterFeedController.h +++ b/iOS/GBPrinterFeedController.h @@ -2,6 +2,5 @@ @interface GBPrinterFeedController : UINavigationController - (instancetype)initWithImage:(UIImage *)image; -- (void)emptyPrinterFeed; @end diff --git a/iOS/GBPrinterFeedController.m b/iOS/GBPrinterFeedController.m index 155edfd..603cfd5 100644 --- a/iOS/GBPrinterFeedController.m +++ b/iOS/GBPrinterFeedController.m @@ -1,27 +1,32 @@ #import "GBPrinterFeedController.h" #import "GBViewController.h" +#import "GBActivityViewController.h" @implementation GBPrinterFeedController { - UIViewController *_scrollViewController; UIImage *_image; } - (instancetype)initWithImage:(UIImage *)image { _image = image; - _scrollViewController = [[UIViewController alloc] init]; - _scrollViewController.title = @"Printer Feed"; - _scrollViewController.view.backgroundColor = [UIColor systemBackgroundColor]; + UIViewController *scrollViewController = [[UIViewController alloc] init]; + scrollViewController.title = @"Printer Feed"; + if (@available(iOS 13.0, *)) { + scrollViewController.view.backgroundColor = [UIColor systemBackgroundColor]; + } + else { + scrollViewController.view.backgroundColor = [UIColor whiteColor]; + } - UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:_scrollViewController.view.bounds]; + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewController.view.bounds]; scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; scrollView.scrollEnabled = true; scrollView.pagingEnabled = false; scrollView.showsVerticalScrollIndicator = true; scrollView.showsHorizontalScrollIndicator = false; - [_scrollViewController.view addSubview:scrollView]; + [scrollViewController.view addSubview:scrollView]; CGSize size = image.size; while (size.width < 320) { @@ -39,13 +44,13 @@ CGSize contentSize = size; self.preferredContentSize = contentSize; - self = [self initWithRootViewController:_scrollViewController]; + self = [self initWithRootViewController:scrollViewController]; UIBarButtonItem *close = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(dismissFromParent)]; [self.visibleViewController.navigationItem setLeftBarButtonItem:close]; - [_scrollViewController setToolbarItems:@[ + [scrollViewController setToolbarItems:@[ [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(presentShareSheet)], @@ -61,24 +66,37 @@ return self; } +- (UIView *)viewToMask +{ + UIView *targetView = self.view; + while (targetView.superview != targetView.window && + targetView.superview.superview != targetView.window){ + targetView = targetView.superview; + } + return targetView; +} + - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; if ([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad) { - CGRect frame = self.view.frame; + UIView *targetView = self.view; + CGRect frame = targetView.frame; frame.origin.x = ([UIScreen mainScreen].bounds.size.width - 320) / 2; frame.size.width = 320; - self.view.frame = frame; + targetView.frame = frame; - UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.view.bounds + UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(frame.origin.x, 0, + 320, 4096) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight - cornerRadii:CGSizeMake(12.0, 12.0)]; + cornerRadii:CGSizeMake(10, 10)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = self.view.bounds; maskLayer.path = maskPath.CGPath; + + self.viewToMask.layer.mask = maskLayer; - self.view.layer.mask = maskLayer; } } @@ -86,7 +104,7 @@ { NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"Game Boy Printer Image.png"]]; [UIImagePNGRepresentation(_image) writeToURL:url atomically:false]; - [self presentViewController:[[UIActivityViewController alloc] initWithActivityItems:@[url] + [self presentViewController:[[GBActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil] animated:true completion:nil]; diff --git a/iOS/GBViewController.m b/iOS/GBViewController.m index dab9f5c..e6dd3a4 100644 --- a/iOS/GBViewController.m +++ b/iOS/GBViewController.m @@ -222,7 +222,8 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) GBTheme *theme = [GBSettingsViewController themeNamed:newValue]; _horizontalLayout = [[GBHorizontalLayout alloc] initWithTheme:theme]; _verticalLayout = [[GBVerticalLayout alloc] initWithTheme:theme]; - + _printerSpinner.color = theme.brandColor; + [self willRotateToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:0]; [_backgroundView reloadThemeImages]; @@ -301,11 +302,7 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) } _backCaptureDevices = filteredBackCameras; - UIEdgeInsets insets = self.window.safeAreaInsets; - _cameraPositionButton = [[UIButton alloc] initWithFrame:CGRectMake(insets.left + 8, - _backgroundView.bounds.size.height - 8 - insets.bottom - 32, - 32, - 32)]; + _cameraPositionButton = [[UIButton alloc] init]; [self didRotateFromInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation]; if (@available(iOS 13.0, *)) { [_cameraPositionButton setImage:[UIImage systemImageNamed:@"camera.rotate" @@ -314,10 +311,7 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) _cameraPositionButton.backgroundColor = [UIColor systemBackgroundColor]; // Configure the change camera button stacked on top of the camera position button - _changeCameraButton = [[UIButton alloc] initWithFrame:CGRectMake(insets.left + 8, - _backgroundView.bounds.size.height - 8 - insets.bottom - 32 - 32 - 8, - 32, - 32)]; + _changeCameraButton = [[UIButton alloc] init]; [_changeCameraButton setImage:[UIImage systemImageNamed:@"camera.aperture" withConfiguration:[UIImageSymbolConfiguration configurationWithScale:UIImageSymbolScaleLarge]] forState:UIControlStateNormal]; @@ -374,6 +368,8 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) _printerButton = [[UIButton alloc] init]; _printerSpinner = [[UIActivityIndicatorView alloc] init]; + _printerSpinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite; + _printerSpinner.color = _verticalLayout.theme.brandColor; [self didRotateFromInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation]; if (@available(iOS 13.0, *)) { @@ -873,13 +869,19 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { UIEdgeInsets insets = self.window.safeAreaInsets; + bool landscape = true; + if (_orientation == UIInterfaceOrientationPortrait || _orientation == UIInterfaceOrientationPortraitUpsideDown) { + landscape = false; + } + + _cameraPositionButton.frame = CGRectMake(insets.left + 8, _backgroundView.bounds.size.height - 8 - insets.bottom - 32, 32, 32); if (_changeCameraButton) { - _changeCameraButton.frame = CGRectMake(insets.left + 8, - _backgroundView.bounds.size.height - 8 - insets.bottom - 32 - 32 - 8, + _changeCameraButton.frame = CGRectMake(insets.left + 8 + (landscape? (32 + 8) : 0 ), + _backgroundView.bounds.size.height - 8 - insets.bottom - 32 - (landscape? 0 : (32 + 8)), 32, 32); } @@ -888,8 +890,8 @@ static void rumbleCallback(GB_gameboy_t *gb, double amp) 32, 32); - _printerSpinner.frame = CGRectMake(_backgroundView.bounds.size.width - 8 - insets.right - 32, - _backgroundView.bounds.size.height - 8 - insets.bottom - 32 - 32 - 8, + _printerSpinner.frame = CGRectMake(_backgroundView.bounds.size.width - 8 - insets.right - 32 - (landscape? (32 + 4) : 0), + _backgroundView.bounds.size.height - 8 - insets.bottom - 32 - (landscape? 0 : (32 + 4)), 32, 32); @@ -1707,6 +1709,7 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response width:160 height:_currentPrinterImageData.length / 160 / sizeof(uint32_t)]; + _window.backgroundColor = [UIColor blackColor]; [self presentViewController:[[GBPrinterFeedController alloc] initWithImage:image] animated:true completion:nil];