Skip to content

Commit

Permalink
UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LIJI32 committed Aug 31, 2024
1 parent 11f70c0 commit 50a56a4
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 45 deletions.
5 changes: 5 additions & 0 deletions iOS/GBActivityViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <UIKit/UIKit.h>

@interface GBActivityViewController : UIActivityViewController

@end
10 changes: 10 additions & 0 deletions iOS/GBActivityViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import "GBActivityViewController.h"

@implementation GBActivityViewController

- (UIModalPresentationStyle)modalPresentationStyle
{
return UIModalPresentationFormSheet;
}

@end
6 changes: 6 additions & 0 deletions iOS/GBBackgroundView.m
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,12 @@ - (void)setLayout:(GBLayout *)layout
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;
}

Expand Down
43 changes: 27 additions & 16 deletions iOS/GBCheckableAlertController.m
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
#import "GBCheckableAlertController.h"

/* Private API */
@interface UIAlertAction()
- (bool)_isChecked;
- (void)_setChecked:(bool)checked;
@end

@implementation GBCheckableAlertController
{
bool _addedChecks;
}

- (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];
}

Expand Down
1 change: 0 additions & 1 deletion iOS/GBPrinterFeedController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

@interface GBPrinterFeedController : UINavigationController
- (instancetype)initWithImage:(UIImage *)image;
- (void)emptyPrinterFeed;
@end

46 changes: 32 additions & 14 deletions iOS/GBPrinterFeedController.m
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -39,13 +44,13 @@ - (instancetype)initWithImage:(UIImage *)image
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)],
Expand All @@ -61,32 +66,45 @@ - (instancetype)initWithImage:(UIImage *)image
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;
}
}

- (void)presentShareSheet
{
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];
Expand Down
31 changes: 17 additions & 14 deletions iOS/GBViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
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];
Expand Down Expand Up @@ -301,11 +302,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
_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"
Expand All @@ -314,10 +311,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
_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];
Expand Down Expand Up @@ -374,6 +368,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

_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, *)) {
Expand Down Expand Up @@ -873,13 +869,19 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation dur
- (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);
}
Expand All @@ -888,8 +890,8 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
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);

Expand Down Expand Up @@ -1707,6 +1709,7 @@ - (void)showPrinterFeed
width:160
height:_currentPrinterImageData.length / 160 / sizeof(uint32_t)];

_window.backgroundColor = [UIColor blackColor];
[self presentViewController:[[GBPrinterFeedController alloc] initWithImage:image]
animated:true
completion:nil];
Expand Down

0 comments on commit 50a56a4

Please sign in to comment.