|
@@ -17,7 +17,7 @@
|
|
|
static const NSInteger kFLEXHierarchyScopeViewsAtTapIndex = 0;
|
|
static const NSInteger kFLEXHierarchyScopeViewsAtTapIndex = 0;
|
|
|
static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
|
|
static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
|
|
|
|
|
|
|
|
-@interface FLEXHierarchyTableViewController () <UISearchBarDelegate>
|
|
|
|
|
|
|
+@interface FLEXHierarchyTableViewController ()
|
|
|
|
|
|
|
|
@property (nonatomic, strong) NSArray<UIView *> *allViews;
|
|
@property (nonatomic, strong) NSArray<UIView *> *allViews;
|
|
|
@property (nonatomic, strong) NSDictionary<NSValue *, NSNumber *> *depthsForViews;
|
|
@property (nonatomic, strong) NSDictionary<NSValue *, NSNumber *> *depthsForViews;
|
|
@@ -25,8 +25,6 @@ static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
|
|
|
@property (nonatomic, strong) UIView *selectedView;
|
|
@property (nonatomic, strong) UIView *selectedView;
|
|
|
@property (nonatomic, strong) NSArray<UIView *> *displayedViews;
|
|
@property (nonatomic, strong) NSArray<UIView *> *displayedViews;
|
|
|
|
|
|
|
|
-@property (nonatomic, strong) UISearchBar *searchBar;
|
|
|
|
|
-
|
|
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
@implementation FLEXHierarchyTableViewController
|
|
@implementation FLEXHierarchyTableViewController
|
|
@@ -60,15 +58,14 @@ static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
|
|
|
// Separator inset clashes with persistent cell selection.
|
|
// Separator inset clashes with persistent cell selection.
|
|
|
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
|
|
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
|
|
|
|
|
|
|
|
- self.searchBar = [[UISearchBar alloc] init];
|
|
|
|
|
- self.searchBar.placeholder = [FLEXUtility searchBarPlaceholderText];
|
|
|
|
|
- self.searchBar.delegate = self;
|
|
|
|
|
|
|
+ self.showsSearchBar = YES;
|
|
|
|
|
+ self.pinSearchBar = YES;
|
|
|
|
|
+ self.searchBarDebounceInterval = kFLEXDebounceInstant;
|
|
|
|
|
+ self.automaticallyShowsSearchBarCancelButton = NO;
|
|
|
if ([self showScopeBar]) {
|
|
if ([self showScopeBar]) {
|
|
|
- self.searchBar.showsScopeBar = YES;
|
|
|
|
|
- self.searchBar.scopeButtonTitles = @[@"Views at Tap", @"Full Hierarchy"];
|
|
|
|
|
|
|
+ self.searchController.searchBar.showsScopeBar = YES;
|
|
|
|
|
+ self.searchController.searchBar.scopeButtonTitles = @[@"Views at Tap", @"Full Hierarchy"];
|
|
|
}
|
|
}
|
|
|
- [self.searchBar sizeToFit];
|
|
|
|
|
- self.tableView.tableHeaderView = self.searchBar;
|
|
|
|
|
|
|
|
|
|
[self updateDisplayedViews];
|
|
[self updateDisplayedViews];
|
|
|
}
|
|
}
|
|
@@ -96,21 +93,21 @@ static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
|
|
|
{
|
|
{
|
|
|
NSArray<UIView *> *candidateViews = nil;
|
|
NSArray<UIView *> *candidateViews = nil;
|
|
|
if ([self showScopeBar]) {
|
|
if ([self showScopeBar]) {
|
|
|
- if (self.searchBar.selectedScopeButtonIndex == kFLEXHierarchyScopeViewsAtTapIndex) {
|
|
|
|
|
|
|
+ if (self.selectedScope == kFLEXHierarchyScopeViewsAtTapIndex) {
|
|
|
candidateViews = self.viewsAtTap;
|
|
candidateViews = self.viewsAtTap;
|
|
|
- } else if (self.searchBar.selectedScopeButtonIndex == kFLEXHierarchyScopeFullHierarchyIndex) {
|
|
|
|
|
|
|
+ } else if (self.selectedScope == kFLEXHierarchyScopeFullHierarchyIndex) {
|
|
|
candidateViews = self.allViews;
|
|
candidateViews = self.allViews;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
candidateViews = self.allViews;
|
|
candidateViews = self.allViews;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ([self.searchBar.text length] > 0) {
|
|
|
|
|
|
|
+ if (self.searchText.length) {
|
|
|
self.displayedViews = [candidateViews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UIView *candidateView, NSDictionary<NSString *, id> *bindings) {
|
|
self.displayedViews = [candidateViews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UIView *candidateView, NSDictionary<NSString *, id> *bindings) {
|
|
|
NSString *title = [FLEXUtility descriptionForView:candidateView includingFrame:NO];
|
|
NSString *title = [FLEXUtility descriptionForView:candidateView includingFrame:NO];
|
|
|
NSString *candidateViewPointerAddress = [NSString stringWithFormat:@"%p", candidateView];
|
|
NSString *candidateViewPointerAddress = [NSString stringWithFormat:@"%p", candidateView];
|
|
|
- BOOL matchedViewPointerAddress = [candidateViewPointerAddress rangeOfString:self.searchBar.text options:NSCaseInsensitiveSearch].location != NSNotFound;
|
|
|
|
|
- BOOL matchedViewTitle = [title rangeOfString:self.searchBar.text options:NSCaseInsensitiveSearch].location != NSNotFound;
|
|
|
|
|
|
|
+ BOOL matchedViewPointerAddress = [candidateViewPointerAddress rangeOfString:self.searchText options:NSCaseInsensitiveSearch].location != NSNotFound;
|
|
|
|
|
+ BOOL matchedViewTitle = [title rangeOfString:self.searchText options:NSCaseInsensitiveSearch].location != NSNotFound;
|
|
|
return matchedViewPointerAddress || matchedViewTitle;
|
|
return matchedViewPointerAddress || matchedViewTitle;
|
|
|
}]];
|
|
}]];
|
|
|
} else {
|
|
} else {
|
|
@@ -120,33 +117,23 @@ static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
|
|
|
[self.tableView reloadData];
|
|
[self.tableView reloadData];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#pragma mark - Search Bar
|
|
|
|
|
+
|
|
|
- (BOOL)showScopeBar
|
|
- (BOOL)showScopeBar
|
|
|
{
|
|
{
|
|
|
return [self.viewsAtTap count] > 0;
|
|
return [self.viewsAtTap count] > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
|
|
|
|
|
|
|
+- (void)updateSearchResults:(NSString *)newText
|
|
|
{
|
|
{
|
|
|
[self updateDisplayedViews];
|
|
[self updateDisplayedViews];
|
|
|
|
|
|
|
|
// If the search bar text field is active, don't scroll on selection because we may want to continue typing.
|
|
// If the search bar text field is active, don't scroll on selection because we may want to continue typing.
|
|
|
// Otherwise, scroll so that the selected cell is visible.
|
|
// Otherwise, scroll so that the selected cell is visible.
|
|
|
- UITableViewScrollPosition scrollPosition = self.searchBar.isFirstResponder ? UITableViewScrollPositionNone : UITableViewScrollPositionMiddle;
|
|
|
|
|
|
|
+ UITableViewScrollPosition scrollPosition = self.searchController.searchBar.isFirstResponder ? UITableViewScrollPositionNone : UITableViewScrollPositionMiddle;
|
|
|
[self trySelectCellForSelectedViewWithScrollPosition:scrollPosition];
|
|
[self trySelectCellForSelectedViewWithScrollPosition:scrollPosition];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
|
|
|
|
|
-{
|
|
|
|
|
- [self updateDisplayedViews];
|
|
|
|
|
- [self trySelectCellForSelectedViewWithScrollPosition:UITableViewScrollPositionNone];
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
|
|
|
|
|
-{
|
|
|
|
|
- [searchBar resignFirstResponder];
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
#pragma mark - Table View Data Source
|
|
#pragma mark - Table View Data Source
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
@@ -212,7 +199,6 @@ static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
|
|
|
[self.navigationController pushViewController:viewExplorer animated:YES];
|
|
[self.navigationController pushViewController:viewExplorer animated:YES];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
#pragma mark - Button Actions
|
|
#pragma mark - Button Actions
|
|
|
|
|
|
|
|
- (void)donePressed:(id)sender
|
|
- (void)donePressed:(id)sender
|