Skip to content
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: timoliver
custom: https://tim.dev/paypal
2 changes: 1 addition & 1 deletion TODocumentPickerViewController.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIBarButtonItem *> *toolbarLeftItems;

/* When not in 'Select' mode, the bar button items on the right hand side of the toolbar */
@property (nonatomic, strong) NSArray<UIBarButtonItem *> *toolbarRightItems;

/* File formats that may be selected by this controller. (If nil, all files may be selected) */
@property (nonatomic, strong, nullable) NSArray *allowedFileExtensions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
88 changes: 65 additions & 23 deletions TODocumentPickerViewController/TODocumentPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -195,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
Expand Down Expand Up @@ -229,16 +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) {
if (self.doneButton == nil) {
self.doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil)
style:UIBarButtonItemStyleDone
target:self
action:@selector(doneButtonTapped)];

NSMutableArray *barItems = [NSMutableArray array];

/* Configure left side of toolbar */
if (self.configuration.toolbarLeftItems) {
[barItems addObjectsFromArray:self.configuration.toolbarLeftItems];
}

self.nonEditingToolbarItems = @[self.doneButton, spaceItemLeft, labelItem, spaceItemRight];
else {
/* 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 */
Expand All @@ -262,15 +290,17 @@ - (void)configureToolbar
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

/* 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];

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

/* Set-up the toolbar */
[self configureToolbar];

/* Add the header view to the table view */
UIView *tableHeaderView = [[UIView alloc] initWithFrame:self.headerView.bounds];
Expand Down Expand Up @@ -309,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
Expand Down Expand Up @@ -576,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, ^{
Expand All @@ -586,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(), ^{
Expand Down Expand Up @@ -674,6 +715,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];
}

Expand Down Expand Up @@ -823,7 +865,7 @@ - (BOOL)allCellsSelected

- (id<TODocumentPickerViewControllerDataSource>)dataSource
{
if (_dataSource == nil) {
if (_dataSource == nil && self != self.rootViewController) {
return self.rootViewController.dataSource;
}

Expand Down
15 changes: 11 additions & 4 deletions TODocumentPickerViewController/Views/TODocumentPickerHeaderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "TOSearchBar.h"

static const CGFloat kTODocumentPickerHeaderViewPadding = 5.0f;
static const CGFloat kTODocumentPickerHeaderMaxWidth = 640.0f;

@interface TODocumentPickerHeaderView () <TOSearchBarDelegate>

Expand Down Expand Up @@ -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;
Expand All @@ -135,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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>