Skip to content

Commit

Permalink
Navigate to UIFontPickerViewController instead of presenting it
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Dec 6, 2020
1 parent 6f6511b commit 6cb0a30
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions app/AboutAppearanceViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

@interface AboutAppearanceViewController ()

@property UIFontPickerViewController *fontPicker API_AVAILABLE(ios(13));

@end

@implementation AboutAppearanceViewController
Expand All @@ -29,6 +31,20 @@ - (void)viewDidLoad {
}];
}

- (void)viewDidAppear:(BOOL)animated {
if (@available(iOS 13, *)) {
// Initialize the font picker ASAP, as it takes about a quarter second to initialize (XPC crap) and appears invisible until then.
// Re-initialize it after navigating away from it, to reset the table view highlight.
UIFontPickerViewControllerConfiguration *config = [UIFontPickerViewControllerConfiguration new];
config.filteredTraits = UIFontDescriptorTraitMonoSpace;
self.fontPicker = [[UIFontPickerViewController alloc] initWithConfiguration:config];
// Prevent the font picker from resizing the popup when it appears
self.fontPicker.preferredContentSize = CGSizeZero;
self.fontPicker.navigationItem.title = @"Font";
self.fontPicker.delegate = self;
}
}

#pragma mark - Table view data source

enum {
Expand Down Expand Up @@ -123,13 +139,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
}

- (IBAction)selectFont:(id)sender {
- (void)selectFont:(id)sender {
if (@available(iOS 13, *)) {
UIFontPickerViewControllerConfiguration *config = [UIFontPickerViewControllerConfiguration new];
config.filteredTraits = UIFontDescriptorTraitMonoSpace;
UIFontPickerViewController *fontPicker = [[UIFontPickerViewController alloc] initWithConfiguration:config];
fontPicker.delegate = self;
[self presentViewController:fontPicker animated:YES completion:nil];
[self.navigationController pushViewController:self.fontPicker animated:YES];
return;
}

Expand All @@ -139,6 +151,7 @@ - (IBAction)selectFont:(id)sender {

- (void)fontPickerViewControllerDidPickFont:(UIFontPickerViewController *)viewController API_AVAILABLE(ios(13.0)) {
UserPreferences.shared.fontFamily = viewController.selectedFontDescriptor.fontAttributes[UIFontDescriptorFamilyAttribute];
[self.navigationController popToViewController:self animated:YES];
}

- (IBAction)fontSizeChanged:(UIStepper *)sender {
Expand Down

0 comments on commit 6cb0a30

Please sign in to comment.