From 8c59076dae9ae8d8b3c1befd4503322dc40964d3 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Sat, 27 Jan 2018 11:58:50 +0800 Subject: [PATCH 01/10] Added better width on large devices --- .../TODocumentPickerViewController.m | 13 ++++++++++--- .../Views/TODocumentPickerHeaderView.m | 9 +++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/TODocumentPickerViewController/TODocumentPickerViewController.m b/TODocumentPickerViewController/TODocumentPickerViewController.m index f06eec7..5f80a82 100644 --- a/TODocumentPickerViewController/TODocumentPickerViewController.m +++ b/TODocumentPickerViewController/TODocumentPickerViewController.m @@ -151,7 +151,6 @@ - (void)viewDidLoad self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.rowHeight = 64.0f; - self.tableView.cellLayoutMarginsFollowReadableWidth = NO; self.tableView.sectionIndexBackgroundColor = self.view.backgroundColor; self.tableView.allowsMultipleSelectionDuringEditing = YES; @@ -262,7 +261,15 @@ - (void)configureToolbar - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - + + if (self.dataSource == nil) { + NSException *exception = [NSException exceptionWithName:NSInternalInconsistencyException + reason:@"TODocumentPickerViewController: A data source must be set before the view controller is presented" + userInfo:nil]; + [exception raise]; + return; + } + /* Configure the sizing and insetting of the header now that the table view will be ready */ UIEdgeInsets headerInsets = UIEdgeInsetsZero; headerInsets.left = self.tableView.separatorInset.left; @@ -823,7 +830,7 @@ - (BOOL)allCellsSelected - (id)dataSource { - if (_dataSource == nil) { + if (_dataSource == nil && self != self.rootViewController) { return self.rootViewController.dataSource; } diff --git a/TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m b/TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m index 3e1cece..b006eef 100644 --- a/TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m +++ b/TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m @@ -24,6 +24,7 @@ #import "TOSearchBar.h" static const CGFloat kTODocumentPickerHeaderViewPadding = 5.0f; +static const CGFloat kTODocumentPickerHeaderMaxWidth = 640.0f; @interface TODocumentPickerHeaderView () @@ -114,16 +115,16 @@ - (void)layoutSubviews // Layout the child views if (self.searchBar) { frame = self.searchBar.frame; - frame.origin.x = self.layoutMargins.left; - frame.size.width = self.bounds.size.width - (self.layoutMargins.left + self.layoutMargins.right); + frame.size.width = MIN(kTODocumentPickerHeaderMaxWidth, self.bounds.size.width - (self.layoutMargins.left + self.layoutMargins.right)); frame.size.height = 44.0f; frame.origin.y = self.layoutMargins.top; + frame.origin.x = CGRectGetMidX(self.bounds) - (frame.size.width * 0.5f); self.searchBar.frame = CGRectIntegral(frame); } frame = self.sortControl.frame; - frame.origin.x = self.layoutMargins.left; - frame.size.width = self.bounds.size.width - (self.layoutMargins.left + self.layoutMargins.right); + frame.size.width = MIN(kTODocumentPickerHeaderMaxWidth, self.bounds.size.width - (self.layoutMargins.left + self.layoutMargins.right)); + frame.origin.x = CGRectGetMidX(self.bounds) - (frame.size.width * 0.5f); frame.size.height = 33.0f; if (self.searchBar) { frame.origin.y = CGRectGetMaxY(self.searchBar.frame) + kTODocumentPickerHeaderViewPadding; From 39099e333e43e0a69ec979cb6879957b7452cf69 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Sat, 27 Jan 2018 13:36:40 +0800 Subject: [PATCH 02/10] =?UTF-8?q?Removed=20=E2=80=98Done=E2=80=99=20button?= =?UTF-8?q?=20from=20non-presented=20contoller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TODocumentPickerViewController.m | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/TODocumentPickerViewController/TODocumentPickerViewController.m b/TODocumentPickerViewController/TODocumentPickerViewController.m index 5f80a82..dac47eb 100644 --- a/TODocumentPickerViewController/TODocumentPickerViewController.m +++ b/TODocumentPickerViewController/TODocumentPickerViewController.m @@ -230,14 +230,21 @@ - (void)configureToolbar /* Toolbar button elements */ if (self.nonEditingToolbarItems == nil) { - if (self.doneButton == nil) { - self.doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) - style:UIBarButtonItemStyleDone - target:self - action:@selector(doneButtonTapped)]; + + /* Don't add a 'Done' button if we're not being presented modally */ + if (self.presentingViewController) { + if (self.doneButton == nil) { + self.doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) + style:UIBarButtonItemStyleDone + target:self + action:@selector(doneButtonTapped)]; + } + + self.nonEditingToolbarItems = @[self.doneButton, spaceItemLeft, labelItem, spaceItemRight]; + } + else { + self.nonEditingToolbarItems = @[spaceItemLeft, labelItem, spaceItemRight]; } - - self.nonEditingToolbarItems = @[self.doneButton, spaceItemLeft, labelItem, spaceItemRight]; } /* Set up editing buttons */ From 89ac1e8872f249c98fcbb4237d081dbfbe2f78f4 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Sat, 27 Jan 2018 13:36:53 +0800 Subject: [PATCH 03/10] Added custom bar item settings --- .../Models/TODocumentPickerConfiguration.h | 6 ++ .../TODocumentPickerViewController.m | 55 ++++++++++++++----- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/TODocumentPickerViewController/Models/TODocumentPickerConfiguration.h b/TODocumentPickerViewController/Models/TODocumentPickerConfiguration.h index 75bedf5..d5c64f0 100644 --- a/TODocumentPickerViewController/Models/TODocumentPickerConfiguration.h +++ b/TODocumentPickerViewController/Models/TODocumentPickerConfiguration.h @@ -37,6 +37,12 @@ NS_ASSUME_NONNULL_BEGIN /* Whether this controller shows and manages the navigation controller toolbar (Default is YES) */ @property (nonatomic, assign) BOOL showToolbar; +/* When not in 'Select' mode, the bar button items on the left hand side of the toolbar */ +@property (nonatomic, strong) NSArray *toolbarLeftItems; + +/* When not in 'Select' mode, the bar button items on the right hand side of the toolbar */ +@property (nonatomic, strong) NSArray *toolbarRightItems; + /* File formats that may be selected by this controller. (If nil, all files may be selected) */ @property (nonatomic, strong, nullable) NSArray *allowedFileExtensions; diff --git a/TODocumentPickerViewController/TODocumentPickerViewController.m b/TODocumentPickerViewController/TODocumentPickerViewController.m index dac47eb..bda1e8f 100644 --- a/TODocumentPickerViewController/TODocumentPickerViewController.m +++ b/TODocumentPickerViewController/TODocumentPickerViewController.m @@ -194,9 +194,6 @@ - (void)viewDidLoad /* Set-up Select All button */ self.selectAllButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Select All", @"") style:UIBarButtonItemStylePlain target:self action:@selector(selectAllButtonTapped)]; - - /* Set-up the toolbar */ - [self configureToolbar]; } - (void)configureToolbar @@ -228,23 +225,48 @@ - (void)configureToolbar UIBarButtonItem *spaceItemRight = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *labelItem = [[UIBarButtonItem alloc] initWithCustomView:self.toolBarLabel]; - /* Toolbar button elements */ + /* Toolbar button elements when not in 'Select' mode */ if (self.nonEditingToolbarItems == nil) { - /* Don't add a 'Done' button if we're not being presented modally */ - if (self.presentingViewController) { - if (self.doneButton == nil) { - self.doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) - style:UIBarButtonItemStyleDone - target:self - action:@selector(doneButtonTapped)]; - } - - self.nonEditingToolbarItems = @[self.doneButton, spaceItemLeft, labelItem, spaceItemRight]; + NSMutableArray *barItems = [NSMutableArray array]; + + /* Configure left side of toolbar */ + if (self.configuration.toolbarLeftItems) { + [barItems addObjectsFromArray:self.configuration.toolbarLeftItems]; } else { - self.nonEditingToolbarItems = @[spaceItemLeft, labelItem, spaceItemRight]; + /* Don't add a 'Done' button if we're not being presented modally */ + if (self.presentingViewController) { + if (self.doneButton == nil) { + self.doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) + style:UIBarButtonItemStyleDone + target:self + action:@selector(doneButtonTapped)]; + } + + [barItems addObject:self.doneButton]; + } } + + // Add the flexible element to center the label if there are less than 2 bar items on the left side + if (barItems.count < 2) { + [barItems addObject:spaceItemLeft]; + } + + // Add the label + [barItems addObject:labelItem]; + + // Add spacing if there's less than 2 items on the right side + if (self.configuration.toolbarRightItems.count < 2) { + [barItems addObject:spaceItemRight]; + } + + // Add right items + if (self.configuration.toolbarRightItems) { + [barItems addObjectsFromArray:self.configuration.toolbarRightItems]; + } + + self.nonEditingToolbarItems = [NSArray arrayWithArray:barItems]; } /* Set up editing buttons */ @@ -277,6 +299,9 @@ - (void)viewWillAppear:(BOOL)animated return; } + /* Set-up the toolbar */ + [self configureToolbar]; + /* Configure the sizing and insetting of the header now that the table view will be ready */ UIEdgeInsets headerInsets = UIEdgeInsetsZero; headerInsets.left = self.tableView.separatorInset.left; From 70276efa220e5606b2b08e62a0754941687c7c5a Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Sat, 27 Jan 2018 13:46:16 +0800 Subject: [PATCH 04/10] Fixed label alignment issue --- TODocumentPickerViewController/TODocumentPickerViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/TODocumentPickerViewController/TODocumentPickerViewController.m b/TODocumentPickerViewController/TODocumentPickerViewController.m index bda1e8f..4e69423 100644 --- a/TODocumentPickerViewController/TODocumentPickerViewController.m +++ b/TODocumentPickerViewController/TODocumentPickerViewController.m @@ -713,6 +713,7 @@ - (void)showFeedbackLabelIfNeeded self.feedbackLabel.font = [UIFont systemFontOfSize:16.0f]; self.feedbackLabel.textColor = [UIColor colorWithWhite:0.8f alpha:1.0f]; self.feedbackLabel.textAlignment = NSTextAlignmentCenter; + self.feedbackLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; [self.tableView addSubview:self.feedbackLabel]; } From f6941cae8bae4ffb3cd86ac925e151d62bda382d Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Sat, 27 Jan 2018 13:53:13 +0800 Subject: [PATCH 05/10] Fixed rotational issue with iPhone X --- .../TODocumentPickerViewController.m | 18 +++++++++--------- .../Views/TODocumentPickerHeaderView.m | 6 ++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/TODocumentPickerViewController/TODocumentPickerViewController.m b/TODocumentPickerViewController/TODocumentPickerViewController.m index 4e69423..57678bc 100644 --- a/TODocumentPickerViewController/TODocumentPickerViewController.m +++ b/TODocumentPickerViewController/TODocumentPickerViewController.m @@ -302,15 +302,6 @@ - (void)viewWillAppear:(BOOL)animated /* Set-up the toolbar */ [self configureToolbar]; - /* Configure the sizing and insetting of the header now that the table view will be ready */ - UIEdgeInsets headerInsets = UIEdgeInsetsZero; - headerInsets.left = self.tableView.separatorInset.left; - headerInsets.right = self.tableView.separatorInset.left; - headerInsets.top = 10.0f; - headerInsets.bottom = 10.0f; - self.headerView.layoutMargins = headerInsets; - [self.headerView sizeToFit]; - /* Add the header view to the table view */ UIView *tableHeaderView = [[UIView alloc] initWithFrame:self.headerView.bounds]; tableHeaderView.backgroundColor = self.view.backgroundColor; @@ -348,6 +339,15 @@ - (void)viewDidLayoutSubviews [self resetTableViewInitialOffset]; self.viewInitiallyLaidOut = YES; } + + /* Configure the sizing and insetting of the header now that the table view will be ready */ + UIEdgeInsets headerInsets = UIEdgeInsetsZero; + headerInsets.left = self.tableView.separatorInset.left; + headerInsets.right = self.tableView.separatorInset.left; + headerInsets.top = 10.0f; + headerInsets.bottom = 10.0f; + self.headerView.layoutMargins = headerInsets; + [self.headerView sizeToFit]; } - (void)resetAfterInitialItemLoad diff --git a/TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m b/TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m index b006eef..da517cf 100644 --- a/TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m +++ b/TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m @@ -136,6 +136,12 @@ - (void)layoutSubviews self.sortControl.frame = CGRectIntegral(frame); } +- (void)layoutMarginsDidChange +{ + [super layoutMarginsDidChange]; + [self setNeedsLayout]; +} + #pragma mark - Search Bar Delegate - - (void)searchBar:(TOSearchBar *)searchBar textDidChange:(NSString *)searchText { From 924917492934ec7f60c0d0f688e69fae34dfdc8f Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Wed, 25 Apr 2018 16:43:48 +0200 Subject: [PATCH 06/10] Remove concurrent enumeration in search filtering --- .../Models/TODocumentPickerItemManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODocumentPickerViewController/Models/TODocumentPickerItemManager.m b/TODocumentPickerViewController/Models/TODocumentPickerItemManager.m index deaa4c9..2a62a4b 100644 --- a/TODocumentPickerViewController/Models/TODocumentPickerItemManager.m +++ b/TODocumentPickerViewController/Models/TODocumentPickerItemManager.m @@ -102,7 +102,7 @@ - (NSArray *)sortedItemsArrayWithArray:(NSArray *)items - (NSArray *)filteredItemsWithItems:(NSArray *)items searchString:(NSString *)searchString { NSMutableArray *filteredItems = [NSMutableArray array]; - [items enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(TODocumentPickerItem *item, NSUInteger i, BOOL *stop) { + [items enumerateObjectsUsingBlock:^(TODocumentPickerItem *item, NSUInteger i, BOOL *stop) { if ([item.fileName rangeOfString:searchString options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)].location != NSNotFound) { [filteredItems addObject:item]; } From b6432828362f65d7fd9a1a16c82d64a5079b5f3e Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Wed, 25 Apr 2018 17:34:16 +0200 Subject: [PATCH 07/10] Stop accessing tintColor on a background thread --- .../TODocumentPickerViewController.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TODocumentPickerViewController/TODocumentPickerViewController.m b/TODocumentPickerViewController/TODocumentPickerViewController.m index 57678bc..fa32d4b 100644 --- a/TODocumentPickerViewController/TODocumentPickerViewController.m +++ b/TODocumentPickerViewController/TODocumentPickerViewController.m @@ -615,6 +615,8 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce // Check if we already have an icon for it if (self.configuration.fileIcons[fileExtension]) { return; } + UIColor *tintColor = self.view.tintColor; + // Kick off a new thread to render the new icon __weak typeof(self) weakSelf = self; dispatch_async(self.mediaQueue, ^{ @@ -625,7 +627,7 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce } if (fileIcon == nil) { - fileIcon = [UIImage TO_documentPickerDefaultFileIconWithExtension:fileExtension tintColor:weakSelf.view.tintColor style:self.configuration.style]; + fileIcon = [UIImage TO_documentPickerDefaultFileIconWithExtension:fileExtension tintColor:tintColor style:self.configuration.style]; } dispatch_async(dispatch_get_main_queue(), ^{ From 642fc03ed1894ca197518ecf4c9429bb076d92c8 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Wed, 27 Jun 2018 02:07:08 +0900 Subject: [PATCH 08/10] Updated project for Xcode 10 --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 TODocumentPickerViewControllerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/TODocumentPickerViewControllerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/TODocumentPickerViewControllerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/TODocumentPickerViewControllerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 65c1d64e274d45c9918b09817a6d578f8aa582f7 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Wed, 6 Feb 2019 01:44:26 +0900 Subject: [PATCH 09/10] Bump podspec --- TODocumentPickerViewController.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODocumentPickerViewController.podspec b/TODocumentPickerViewController.podspec index 1ce567c..0f315d0 100644 --- a/TODocumentPickerViewController.podspec +++ b/TODocumentPickerViewController.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'TODocumentPickerViewController' - spec.version = '0.2.1' + spec.version = '0.2.2' spec.platform = :ios, '9.0' spec.license = { :type => 'MIT', :file => 'LICENSE' } spec.homepage = 'https://github.com/TimOliver/TODocumentPickerViewController' From 848596446c77fe86a1c593fae11ec07c00f507bb Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 18 Oct 2019 01:45:45 +0900 Subject: [PATCH 10/10] Create FUNDING.yml --- .github/FUNDING.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..ebf952d --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: timoliver +custom: https://tim.dev/paypal