mirror of
https://github.com/SoPat712/YTLitePlus.git
synced 2025-10-30 04:20:37 -04:00
added files via upload
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// FLEXHierarchyTableViewCell.h
|
||||
// Flipboard
|
||||
//
|
||||
// Created by Ryan Olson on 2014-05-02.
|
||||
// Copyright (c) 2020 FLEX Team. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface FLEXHierarchyTableViewCell : UITableViewCell
|
||||
|
||||
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier;
|
||||
|
||||
@property (nonatomic) NSInteger viewDepth;
|
||||
@property (nonatomic) UIColor *randomColorTag;
|
||||
@property (nonatomic) UIColor *indicatedViewColor;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,169 @@
|
||||
//
|
||||
// FLEXHierarchyTableViewCell.m
|
||||
// Flipboard
|
||||
//
|
||||
// Created by Ryan Olson on 2014-05-02.
|
||||
// Copyright (c) 2020 FLEX Team. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FLEXHierarchyTableViewCell.h"
|
||||
#import "FLEXUtility.h"
|
||||
#import "FLEXResources.h"
|
||||
#import "FLEXColor.h"
|
||||
|
||||
@interface FLEXHierarchyTableViewCell ()
|
||||
|
||||
/// Indicates how deep the view is in the hierarchy
|
||||
@property (nonatomic) UIView *depthIndicatorView;
|
||||
/// Holds the color that visually distinguishes views from one another
|
||||
@property (nonatomic) UIImageView *colorCircleImageView;
|
||||
/// A checker-patterned view, used to help show the color of a view, like a photoshop canvas
|
||||
@property (nonatomic) UIView *backgroundColorCheckerPatternView;
|
||||
/// The subview of the checker pattern view which holds the actual color of the view
|
||||
@property (nonatomic) UIView *viewBackgroundColorView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FLEXHierarchyTableViewCell
|
||||
|
||||
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier {
|
||||
return [self initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
|
||||
}
|
||||
|
||||
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
||||
if (self) {
|
||||
self.depthIndicatorView = [UIView new];
|
||||
self.depthIndicatorView.backgroundColor = FLEXUtility.hierarchyIndentPatternColor;
|
||||
[self.contentView addSubview:self.depthIndicatorView];
|
||||
|
||||
UIImage *defaultCircleImage = [FLEXUtility circularImageWithColor:UIColor.blackColor radius:5];
|
||||
self.colorCircleImageView = [[UIImageView alloc] initWithImage:defaultCircleImage];
|
||||
[self.contentView addSubview:self.colorCircleImageView];
|
||||
|
||||
self.textLabel.font = UIFont.flex_defaultTableCellFont;
|
||||
self.detailTextLabel.font = UIFont.flex_defaultTableCellFont;
|
||||
self.accessoryType = UITableViewCellAccessoryDetailButton;
|
||||
|
||||
// Use a pattern-based color to simplify application of the checker pattern
|
||||
static UIColor *checkerPatternColor = nil;
|
||||
static dispatch_once_t once;
|
||||
dispatch_once(&once, ^{
|
||||
checkerPatternColor = [UIColor colorWithPatternImage:FLEXResources.checkerPattern];
|
||||
});
|
||||
|
||||
self.backgroundColorCheckerPatternView = [UIView new];
|
||||
self.backgroundColorCheckerPatternView.clipsToBounds = YES;
|
||||
self.backgroundColorCheckerPatternView.layer.borderColor = FLEXColor.tertiaryBackgroundColor.CGColor;
|
||||
self.backgroundColorCheckerPatternView.layer.borderWidth = 2.f / UIScreen.mainScreen.scale;
|
||||
self.backgroundColorCheckerPatternView.backgroundColor = checkerPatternColor;
|
||||
[self.contentView addSubview:self.backgroundColorCheckerPatternView];
|
||||
self.viewBackgroundColorView = [UIView new];
|
||||
[self.backgroundColorCheckerPatternView addSubview:self.viewBackgroundColorView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
|
||||
UIColor *originalColour = self.viewBackgroundColorView.backgroundColor;
|
||||
[super setHighlighted:highlighted animated:animated];
|
||||
|
||||
// UITableViewCell changes all subviews in the contentView to backgroundColor = clearColor.
|
||||
// We want to preserve the hierarchy background color when highlighted.
|
||||
self.depthIndicatorView.backgroundColor = FLEXUtility.hierarchyIndentPatternColor;
|
||||
|
||||
self.viewBackgroundColorView.backgroundColor = originalColour;
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
||||
UIColor *originalColour = self.viewBackgroundColorView.backgroundColor;
|
||||
[super setSelected:selected animated:animated];
|
||||
|
||||
// See setHighlighted above.
|
||||
self.depthIndicatorView.backgroundColor = FLEXUtility.hierarchyIndentPatternColor;
|
||||
|
||||
self.viewBackgroundColorView.backgroundColor = originalColour;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
|
||||
const CGFloat kContentPadding = 6;
|
||||
const CGFloat kDepthIndicatorWidthMultiplier = 4;
|
||||
const CGFloat kViewColorIndicatorSize = 22;
|
||||
|
||||
const CGRect bounds = self.contentView.bounds;
|
||||
const CGFloat centerY = CGRectGetMidY(bounds);
|
||||
const CGFloat textLabelCenterY = CGRectGetMidY(self.textLabel.frame);
|
||||
|
||||
BOOL hideCheckerView = self.backgroundColorCheckerPatternView.hidden;
|
||||
CGFloat maxWidth = CGRectGetMaxX(bounds);
|
||||
maxWidth -= (hideCheckerView ? kContentPadding : (kViewColorIndicatorSize + kContentPadding * 2));
|
||||
|
||||
CGRect depthIndicatorFrame = self.depthIndicatorView.frame = CGRectMake(
|
||||
kContentPadding, 0, self.viewDepth * kDepthIndicatorWidthMultiplier, CGRectGetHeight(bounds)
|
||||
);
|
||||
|
||||
// Circle goes after depth, and its center Y = textLabel's center Y
|
||||
CGRect circleFrame = self.colorCircleImageView.frame;
|
||||
circleFrame.origin.x = CGRectGetMaxX(depthIndicatorFrame) + kContentPadding;
|
||||
circleFrame.origin.y = FLEXFloor(textLabelCenterY - CGRectGetHeight(circleFrame) / 2.f);
|
||||
self.colorCircleImageView.frame = circleFrame;
|
||||
|
||||
// Text label goes after random color circle, width extends to the edge
|
||||
// of the contentView or to the padding before the color indicator view
|
||||
CGRect textLabelFrame = self.textLabel.frame;
|
||||
CGFloat textOriginX = CGRectGetMaxX(circleFrame) + kContentPadding;
|
||||
textLabelFrame.origin.x = textOriginX;
|
||||
textLabelFrame.size.width = maxWidth - textOriginX;
|
||||
self.textLabel.frame = textLabelFrame;
|
||||
|
||||
// detailTextLabel leading edge lines up with the circle, and the
|
||||
// width extends to the same max X as the same max X as the textLabel
|
||||
CGRect detailTextLabelFrame = self.detailTextLabel.frame;
|
||||
CGFloat detailOriginX = circleFrame.origin.x;
|
||||
detailTextLabelFrame.origin.x = detailOriginX;
|
||||
detailTextLabelFrame.size.width = maxWidth - detailOriginX;
|
||||
self.detailTextLabel.frame = detailTextLabelFrame;
|
||||
|
||||
// Checker pattern view starts after the padding after the max X of textLabel,
|
||||
// and is centered vertically within the entire contentView
|
||||
self.backgroundColorCheckerPatternView.frame = CGRectMake(
|
||||
CGRectGetMaxX(self.textLabel.frame) + kContentPadding,
|
||||
centerY - kViewColorIndicatorSize / 2.f,
|
||||
kViewColorIndicatorSize,
|
||||
kViewColorIndicatorSize
|
||||
);
|
||||
|
||||
// Background color view fills it's superview
|
||||
self.viewBackgroundColorView.frame = self.backgroundColorCheckerPatternView.bounds;
|
||||
self.backgroundColorCheckerPatternView.layer.cornerRadius = kViewColorIndicatorSize / 2.f;
|
||||
}
|
||||
|
||||
- (void)setRandomColorTag:(UIColor *)randomColorTag {
|
||||
if (![_randomColorTag isEqual:randomColorTag]) {
|
||||
_randomColorTag = randomColorTag;
|
||||
self.colorCircleImageView.image = [FLEXUtility circularImageWithColor:randomColorTag radius:6];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setViewDepth:(NSInteger)viewDepth {
|
||||
if (_viewDepth != viewDepth) {
|
||||
_viewDepth = viewDepth;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
}
|
||||
|
||||
- (UIColor *)indicatedViewColor {
|
||||
return self.viewBackgroundColorView.backgroundColor;
|
||||
}
|
||||
|
||||
- (void)setIndicatedViewColor:(UIColor *)color {
|
||||
self.viewBackgroundColorView.backgroundColor = color;
|
||||
|
||||
// Hide the checker pattern view if there is no background color
|
||||
self.backgroundColorCheckerPatternView.hidden = color == nil;
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// FLEXHierarchyTableViewController.h
|
||||
// Flipboard
|
||||
//
|
||||
// Created by Ryan Olson on 2014-05-01.
|
||||
// Copyright (c) 2020 FLEX Team. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FLEXTableViewController.h"
|
||||
|
||||
@interface FLEXHierarchyTableViewController : FLEXTableViewController
|
||||
|
||||
+ (instancetype)windows:(NSArray<UIWindow *> *)allWindows
|
||||
viewsAtTap:(NSArray<UIView *> *)viewsAtTap
|
||||
selectedView:(UIView *)selectedView;
|
||||
|
||||
@property (nonatomic) UIView *selectedView;
|
||||
@property (nonatomic) void(^didSelectRowAction)(UIView *selectedView);
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,253 @@
|
||||
//
|
||||
// FLEXHierarchyTableViewController.m
|
||||
// Flipboard
|
||||
//
|
||||
// Created by Ryan Olson on 2014-05-01.
|
||||
// Copyright (c) 2020 FLEX Team. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FLEXColor.h"
|
||||
#import "FLEXHierarchyTableViewController.h"
|
||||
#import "NSMapTable+FLEX_Subscripting.h"
|
||||
#import "FLEXUtility.h"
|
||||
#import "FLEXHierarchyTableViewCell.h"
|
||||
#import "FLEXObjectExplorerViewController.h"
|
||||
#import "FLEXObjectExplorerFactory.h"
|
||||
#import "FLEXResources.h"
|
||||
#import "FLEXWindow.h"
|
||||
|
||||
typedef NS_ENUM(NSUInteger, FLEXHierarchyScope) {
|
||||
FLEXHierarchyScopeFullHierarchy,
|
||||
FLEXHierarchyScopeViewsAtTap
|
||||
};
|
||||
|
||||
@interface FLEXHierarchyTableViewController ()
|
||||
|
||||
@property (nonatomic) NSArray<UIView *> *allViews;
|
||||
@property (nonatomic) NSMapTable<UIView *, NSNumber *> *depthsForViews;
|
||||
@property (nonatomic) NSArray<UIView *> *viewsAtTap;
|
||||
@property (nonatomic) NSArray<UIView *> *displayedViews;
|
||||
@property (nonatomic, readonly) BOOL showScopeBar;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FLEXHierarchyTableViewController
|
||||
|
||||
+ (instancetype)windows:(NSArray<UIWindow *> *)allWindows
|
||||
viewsAtTap:(NSArray<UIView *> *)viewsAtTap
|
||||
selectedView:(UIView *)selected {
|
||||
NSParameterAssert(allWindows.count);
|
||||
|
||||
NSArray *allViews = [self allViewsInHierarchy:allWindows];
|
||||
NSMapTable *depths = [self hierarchyDepthsForViews:allViews];
|
||||
return [[self alloc] initWithViews:allViews viewsAtTap:viewsAtTap selectedView:selected depths:depths];
|
||||
}
|
||||
|
||||
- (instancetype)initWithViews:(NSArray<UIView *> *)allViews
|
||||
viewsAtTap:(NSArray<UIView *> *)viewsAtTap
|
||||
selectedView:(UIView *)selectedView
|
||||
depths:(NSMapTable<UIView *, NSNumber *> *)depthsForViews {
|
||||
NSParameterAssert(allViews);
|
||||
NSParameterAssert(depthsForViews.count == allViews.count);
|
||||
|
||||
self = [super initWithStyle:UITableViewStylePlain];
|
||||
if (self) {
|
||||
self.allViews = allViews;
|
||||
self.depthsForViews = depthsForViews;
|
||||
self.viewsAtTap = viewsAtTap;
|
||||
self.selectedView = selectedView;
|
||||
|
||||
self.title = @"View Hierarchy Tree";
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
// Preserve selection between presentations
|
||||
self.clearsSelectionOnViewWillAppear = NO;
|
||||
|
||||
// A little more breathing room
|
||||
self.tableView.rowHeight = 50.0;
|
||||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
// Separator inset clashes with persistent cell selection
|
||||
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
|
||||
|
||||
self.showsSearchBar = YES;
|
||||
self.showSearchBarInitially = YES;
|
||||
// Using pinSearchBar on this screen causes a weird visual
|
||||
// thing on the next view controller that gets pushed.
|
||||
//
|
||||
// self.pinSearchBar = YES;
|
||||
self.searchBarDebounceInterval = kFLEXDebounceInstant;
|
||||
self.automaticallyShowsSearchBarCancelButton = NO;
|
||||
if (self.showScopeBar) {
|
||||
self.searchController.searchBar.showsScopeBar = YES;
|
||||
self.searchController.searchBar.scopeButtonTitles = @[@"Full Hierarchy", @"Views at Tap"];
|
||||
self.selectedScope = FLEXHierarchyScopeViewsAtTap;
|
||||
}
|
||||
|
||||
[self updateDisplayedViews];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[self disableToolbar];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
|
||||
[self trySelectCellForSelectedView];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Hierarchy helpers
|
||||
|
||||
+ (NSArray<UIView *> *)allViewsInHierarchy:(NSArray<UIWindow *> *)windows {
|
||||
return [windows flex_flatmapped:^id(UIWindow *window, NSUInteger idx) {
|
||||
if (![window isKindOfClass:[FLEXWindow class]]) {
|
||||
return [self viewWithRecursiveSubviews:window];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}];
|
||||
}
|
||||
|
||||
+ (NSArray<UIView *> *)viewWithRecursiveSubviews:(UIView *)view {
|
||||
NSMutableArray<UIView *> *subviews = [NSMutableArray arrayWithObject:view];
|
||||
for (UIView *subview in view.subviews) {
|
||||
[subviews addObjectsFromArray:[self viewWithRecursiveSubviews:subview]];
|
||||
}
|
||||
|
||||
return subviews;
|
||||
}
|
||||
|
||||
+ (NSMapTable<UIView *, NSNumber *> *)hierarchyDepthsForViews:(NSArray<UIView *> *)views {
|
||||
NSMapTable<UIView *, NSNumber *> *depths = [NSMapTable strongToStrongObjectsMapTable];
|
||||
for (UIView *view in views) {
|
||||
NSInteger depth = 0;
|
||||
UIView *tryView = view;
|
||||
while (tryView.superview) {
|
||||
tryView = tryView.superview;
|
||||
depth++;
|
||||
}
|
||||
depths[(id)view] = @(depth);
|
||||
}
|
||||
|
||||
return depths;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Selection and Filtering Helpers
|
||||
|
||||
- (void)trySelectCellForSelectedView {
|
||||
NSUInteger selectedViewIndex = [self.displayedViews indexOfObject:self.selectedView];
|
||||
if (selectedViewIndex != NSNotFound) {
|
||||
UITableViewScrollPosition scrollPosition = UITableViewScrollPositionMiddle;
|
||||
NSIndexPath *selectedViewIndexPath = [NSIndexPath indexPathForRow:selectedViewIndex inSection:0];
|
||||
[self.tableView selectRowAtIndexPath:selectedViewIndexPath animated:YES scrollPosition:scrollPosition];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateDisplayedViews {
|
||||
NSArray<UIView *> *candidateViews = nil;
|
||||
if (self.showScopeBar) {
|
||||
if (self.selectedScope == FLEXHierarchyScopeViewsAtTap) {
|
||||
candidateViews = self.viewsAtTap;
|
||||
} else if (self.selectedScope == FLEXHierarchyScopeFullHierarchy) {
|
||||
candidateViews = self.allViews;
|
||||
}
|
||||
} else {
|
||||
candidateViews = self.allViews;
|
||||
}
|
||||
|
||||
if (self.searchText.length) {
|
||||
self.displayedViews = [candidateViews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UIView *candidateView, NSDictionary<NSString *, id> *bindings) {
|
||||
NSString *title = [FLEXUtility descriptionForView:candidateView includingFrame:NO];
|
||||
NSString *candidateViewPointerAddress = [NSString stringWithFormat:@"%p", candidateView];
|
||||
BOOL matchedViewPointerAddress = [candidateViewPointerAddress rangeOfString:self.searchText options:NSCaseInsensitiveSearch].location != NSNotFound;
|
||||
BOOL matchedViewTitle = [title rangeOfString:self.searchText options:NSCaseInsensitiveSearch].location != NSNotFound;
|
||||
return matchedViewPointerAddress || matchedViewTitle;
|
||||
}]];
|
||||
} else {
|
||||
self.displayedViews = candidateViews;
|
||||
}
|
||||
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
- (void)setSelectedView:(UIView *)selectedView {
|
||||
_selectedView = selectedView;
|
||||
if (self.isViewLoaded) {
|
||||
[self trySelectCellForSelectedView];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Search Bar / Scope Bar
|
||||
|
||||
- (BOOL)showScopeBar {
|
||||
return self.viewsAtTap.count > 0;
|
||||
}
|
||||
|
||||
- (void)updateSearchResults:(NSString *)newText {
|
||||
[self updateDisplayedViews];
|
||||
|
||||
// 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.
|
||||
if (!self.searchController.searchBar.isFirstResponder) {
|
||||
[self trySelectCellForSelectedView];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Table View Data Source
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return self.displayedViews.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
static NSString *CellIdentifier = @"Cell";
|
||||
FLEXHierarchyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
||||
if (!cell) {
|
||||
cell = [[FLEXHierarchyTableViewCell alloc] initWithReuseIdentifier:CellIdentifier];
|
||||
}
|
||||
|
||||
UIView *view = self.displayedViews[indexPath.row];
|
||||
|
||||
cell.textLabel.text = [FLEXUtility descriptionForView:view includingFrame:NO];
|
||||
cell.detailTextLabel.text = [FLEXUtility detailDescriptionForView:view];
|
||||
cell.randomColorTag = [FLEXUtility consistentRandomColorForObject:view];
|
||||
cell.viewDepth = self.depthsForViews[view].integerValue;
|
||||
cell.indicatedViewColor = view.backgroundColor;
|
||||
|
||||
if (view.isHidden || view.alpha < 0.01) {
|
||||
cell.textLabel.textColor = FLEXColor.deemphasizedTextColor;
|
||||
cell.detailTextLabel.textColor = FLEXColor.deemphasizedTextColor;
|
||||
} else {
|
||||
cell.textLabel.textColor = FLEXColor.primaryTextColor;
|
||||
cell.detailTextLabel.textColor = FLEXColor.primaryTextColor;
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
_selectedView = self.displayedViews[indexPath.row]; // Don't scroll, avoid setter
|
||||
if (self.didSelectRowAction) {
|
||||
self.didSelectRowAction(_selectedView);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
|
||||
UIView *drillInView = self.displayedViews[indexPath.row];
|
||||
FLEXObjectExplorerViewController *viewExplorer = [FLEXObjectExplorerFactory explorerViewControllerForObject:drillInView];
|
||||
[self.navigationController pushViewController:viewExplorer animated:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user