Commit 0b7d5add authored by Pierre SAGASPE's avatar Pierre SAGASPE

VLCLibraryViewController: for iOS 11 add the searchController searchBar to the...

VLCLibraryViewController: for iOS 11 add the searchController searchBar to the navigationItem searchController
parent aa62c532
...@@ -131,13 +131,14 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -131,13 +131,14 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
_tableView.separatorColor = [UIColor VLCDarkBackgroundColor]; _tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
_tableView.delegate = self; _tableView.delegate = self;
_tableView.dataSource = self; _tableView.dataSource = self;
_tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
_tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
if (@available(iOS 11.0, *)) { if (@available(iOS 11.0, *)) {
_tableView.dragDelegate = ((VLCDragAndDropManager *)dragAndDropManager); _tableView.dragDelegate = ((VLCDragAndDropManager *)dragAndDropManager);
_tableView.dropDelegate = ((VLCDragAndDropManager *)dragAndDropManager); _tableView.dropDelegate = ((VLCDragAndDropManager *)dragAndDropManager);
} else {
_tableView.tableHeaderView = _searchController.searchBar;
} }
_tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
_tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_tableView.tableHeaderView = _searchController.searchBar;
UINib *nib = [UINib nibWithNibName:@"VLCPlaylistTableViewCell" bundle:nil]; UINib *nib = [UINib nibWithNibName:@"VLCPlaylistTableViewCell" bundle:nil];
[_tableView registerNib:nib forCellReuseIdentifier:kPlaylistCellIdentifier]; [_tableView registerNib:nib forCellReuseIdentifier:kPlaylistCellIdentifier];
} }
...@@ -166,9 +167,13 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -166,9 +167,13 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
[_collectionView reloadData]; [_collectionView reloadData];
if (self.usingTableViewToShowData) { if (self.usingTableViewToShowData) {
[contentView addSubview:_tableView]; [contentView addSubview:_tableView];
if (@available(iOS 11.0, *))
[self setSearchBar:YES resetContent:NO];
} else { } else {
[contentView addSubview:_collectionView]; [contentView addSubview:_collectionView];
[_searchController setActive:NO]; [_searchController setActive:NO];
if (@available(iOS 11.0, *))
[self setSearchBar:NO resetContent:NO];
} }
self.view = contentView; self.view = contentView;
} }
...@@ -422,11 +427,29 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData"; ...@@ -422,11 +427,29 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (void)setSearchBar:(BOOL)enable resetContent:(BOOL)resetContent - (void)setSearchBar:(BOOL)enable resetContent:(BOOL)resetContent
{ {
_tableView.tableHeaderView = enable ? _searchController.searchBar : nil; if (@available(iOS 11.0, *)) {
if (resetContent) { _searchController.dimsBackgroundDuringPresentation = NO;
CGPoint contentOffset = _tableView.contentOffset; [_searchController.searchBar sizeToFit];
contentOffset.y += CGRectGetHeight(_tableView.tableHeaderView.frame);
_tableView.contentOffset = contentOffset; // search bar text field background color
UITextField *searchTextField = [_searchController.searchBar valueForKey:@"searchField"];
UIView *backgroundView = searchTextField.subviews.firstObject;
backgroundView.backgroundColor = UIColor.whiteColor;
backgroundView.layer.cornerRadius = 10;
backgroundView.clipsToBounds = YES;
_searchController.hidesNavigationBarDuringPresentation = NO;
_searchController.obscuresBackgroundDuringPresentation = NO;
self.navigationItem.hidesSearchBarWhenScrolling = YES;
self.navigationItem.searchController = enable ? _searchController : nil;
self.definesPresentationContext = YES;
} else {
_tableView.tableHeaderView = enable ? _searchController.searchBar : nil;
if (resetContent) {
CGPoint contentOffset = _tableView.contentOffset;
contentOffset.y += CGRectGetHeight(_tableView.tableHeaderView.frame);
_tableView.contentOffset = contentOffset;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment