Skip to content

Commit

Permalink
Add FLEXColorExplorerViewController
Browse files Browse the repository at this point in the history
Provides a visual of the color for all UIColor objects.
  • Loading branch information
NSExceptional committed Nov 4, 2018
1 parent 693f57e commit 24d5f3e
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Classes/ObjectExplorers/FLEXColorExplorerViewController.h
@@ -0,0 +1,13 @@
//
// FLEXColorExplorerViewController.h
// Flipboard
//
// Created by Tanner on 10/18/18.
// Copyright © 2018 Flipboard. All rights reserved.
//

#import "FLEXObjectExplorerViewController.h"

@interface FLEXColorExplorerViewController : FLEXObjectExplorerViewController

@end
49 changes: 49 additions & 0 deletions Classes/ObjectExplorers/FLEXColorExplorerViewController.m
@@ -0,0 +1,49 @@
//
// FLEXColorExplorerViewController.m
// Flipboard
//
// Created by Tanner on 10/18/18.
// Copyright © 2018 Flipboard. All rights reserved.
//

#import "FLEXColorExplorerViewController.h"

@interface FLEXColorExplorerViewController ()

@end

@implementation FLEXColorExplorerViewController

- (BOOL)shouldShowDescription
{
return NO;
}

- (NSString *)customSectionTitle
{
return @"Color";
}

- (NSArray *)customSectionRowCookies
{
return @[@0];
}

- (UIView *)customViewForRowCookie:(id)rowCookie
{
CGFloat width = [UIScreen mainScreen].bounds.size.width;
UIView *square = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 44)];
square.backgroundColor = (UIColor *)self.object;
return square;
}

//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
// if (indexPath.section == 0 && indexPath.row == 0) {
// cell.contentView.backgroundColor = (UIColor *)self.object;
// }
//
// return cell;
//}

@end
5 changes: 4 additions & 1 deletion Classes/ObjectExplorers/FLEXObjectExplorerFactory.m
Expand Up @@ -17,6 +17,7 @@
#import "FLEXImageExplorerViewController.h"
#import "FLEXClassExplorerViewController.h"
#import "FLEXLayerExplorerViewController.h"
#import "FLEXColorExplorerViewController.h"
#import <objc/runtime.h>

@implementation FLEXObjectExplorerFactory
Expand All @@ -38,7 +39,9 @@ + (FLEXObjectExplorerViewController *)explorerViewControllerForObject:(id)object
NSStringFromClass([UIViewController class]) : [FLEXViewControllerExplorerViewController class],
NSStringFromClass([UIView class]) : [FLEXViewExplorerViewController class],
NSStringFromClass([UIImage class]) : [FLEXImageExplorerViewController class],
NSStringFromClass([CALayer class]) : [FLEXLayerExplorerViewController class]};
NSStringFromClass([CALayer class]) : [FLEXLayerExplorerViewController class],
NSStringFromClass([UIColor class]) : [FLEXColorExplorerViewController class]
};
});

Class explorerClass = nil;
Expand Down
1 change: 1 addition & 0 deletions Classes/ObjectExplorers/FLEXObjectExplorerViewController.h
Expand Up @@ -33,6 +33,7 @@ typedef NS_ENUM(NSUInteger, FLEXObjectExplorerSection) {
- (NSString *)customSectionSubtitleForRowCookie:(id)rowCookie;
- (BOOL)customSectionCanDrillIntoRowWithCookie:(id)rowCookie;
- (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie;
- (UIView *)customViewForRowCookie:(id)rowCookie;

// More subclass configuration hooks.

Expand Down
28 changes: 26 additions & 2 deletions Classes/ObjectExplorers/FLEXObjectExplorerViewController.m
Expand Up @@ -941,7 +941,8 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FLEXObjectExplorerSection explorerSection = [self explorerSectionAtIndex:indexPath.section];


BOOL isCustomSection = explorerSection == FLEXObjectExplorerSectionCustom;
BOOL useDescriptionCell = explorerSection == FLEXObjectExplorerSectionDescription;
NSString *cellIdentifier = useDescriptionCell ? kFLEXMultilineTableViewCellIdentifier : @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
Expand All @@ -957,7 +958,16 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.detailTextLabel.textColor = [UIColor grayColor];
}
}



UIView *customView;
if (isCustomSection) {
customView = [self customViewForRowCookie:[self customSectionRowCookieForVisibleRow:indexPath.row]];
if (customView) {
[cell.contentView addSubview:customView];
}
}

cell.textLabel.text = [self titleForRow:indexPath.row inExplorerSection:explorerSection];
cell.detailTextLabel.text = [self subtitleForRow:indexPath.row inExplorerSection:explorerSection];
cell.accessoryType = [self canDrillInToRow:indexPath.row inExplorerSection:explorerSection] ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
Expand All @@ -974,7 +984,11 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:@{ NSFontAttributeName : [FLEXUtility defaultTableViewCellLabelFont] }];
CGFloat preferredHeight = [FLEXMultilineTableViewCell preferredHeightWithAttributedText:attributedText inTableViewWidth:self.tableView.frame.size.width style:tableView.style showsAccessory:NO];
height = MAX(height, preferredHeight);
} else if (explorerSection == FLEXObjectExplorerSectionCustom) {
id cookie = [self customSectionRowCookieForVisibleRow:indexPath.row];
height = [self heightForCustomViewRowForRowCookie:cookie];
}

return height;
}

Expand Down Expand Up @@ -1103,6 +1117,16 @@ - (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCook
return nil;
}

- (UIView *)customViewForRowCookie:(id)rowCookie
{
return nil;
}

- (CGFloat)heightForCustomViewRowForRowCookie:(id)rowCookie
{
return self.tableView.rowHeight;
}

- (BOOL)canHaveInstanceState
{
return YES;
Expand Down
8 changes: 8 additions & 0 deletions FLEX.xcodeproj/project.pbxproj
Expand Up @@ -166,6 +166,8 @@
94AAF0381BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 94AAF0361BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h */; settings = {ATTRIBUTES = (Private, ); }; };
94AAF0391BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94AAF0371BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m */; };
94AAF03A1BAF2F0300DE8760 /* FLEXKeyboardShortcutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 942DCD821BAE0AD300DB5DC2 /* FLEXKeyboardShortcutManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
C395D6D921789BD800BEAD4D /* FLEXColorExplorerViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C395D6D721789BD800BEAD4D /* FLEXColorExplorerViewController.h */; };
C395D6DA21789BD800BEAD4D /* FLEXColorExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C395D6D821789BD800BEAD4D /* FLEXColorExplorerViewController.m */; };
C3DB9F642107FC9600B46809 /* FLEXObjectRef.h in Headers */ = {isa = PBXBuildFile; fileRef = C3DB9F622107FC9600B46809 /* FLEXObjectRef.h */; };
C3DB9F652107FC9600B46809 /* FLEXObjectRef.m in Sources */ = {isa = PBXBuildFile; fileRef = C3DB9F632107FC9600B46809 /* FLEXObjectRef.m */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -344,6 +346,8 @@
94A515241C4CA2080063292F /* FLEXToolbarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FLEXToolbarItem.m; path = Classes/Toolbar/FLEXToolbarItem.m; sourceTree = SOURCE_ROOT; };
94AAF0361BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXKeyboardHelpViewController.h; sourceTree = "<group>"; };
94AAF0371BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXKeyboardHelpViewController.m; sourceTree = "<group>"; };
C395D6D721789BD800BEAD4D /* FLEXColorExplorerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXColorExplorerViewController.h; sourceTree = "<group>"; };
C395D6D821789BD800BEAD4D /* FLEXColorExplorerViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXColorExplorerViewController.m; sourceTree = "<group>"; };
C3DB9F622107FC9600B46809 /* FLEXObjectRef.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXObjectRef.h; sourceTree = "<group>"; };
C3DB9F632107FC9600B46809 /* FLEXObjectRef.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXObjectRef.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -452,6 +456,8 @@
3A4C94511B5B21410088C3F2 /* FLEXViewControllerExplorerViewController.m */,
3A4C94521B5B21410088C3F2 /* FLEXViewExplorerViewController.h */,
3A4C94531B5B21410088C3F2 /* FLEXViewExplorerViewController.m */,
C395D6D721789BD800BEAD4D /* FLEXColorExplorerViewController.h */,
C395D6D821789BD800BEAD4D /* FLEXColorExplorerViewController.m */,
);
path = ObjectExplorers;
sourceTree = "<group>";
Expand Down Expand Up @@ -769,6 +775,7 @@
3A4C95241B5B21410088C3F2 /* FLEXFileBrowserTableViewController.h in Headers */,
94AAF0381BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h in Headers */,
94AAF03A1BAF2F0300DE8760 /* FLEXKeyboardShortcutManager.h in Headers */,
C395D6D921789BD800BEAD4D /* FLEXColorExplorerViewController.h in Headers */,
94A515181C4CA1D70063292F /* FLEXManager+Private.h in Headers */,
3A4C94E11B5B21410088C3F2 /* FLEXResources.h in Headers */,
779B1ED81C0C4D7C001F5E49 /* FLEXTableLeftCell.h in Headers */,
Expand Down Expand Up @@ -939,6 +946,7 @@
94A515261C4CA2080063292F /* FLEXExplorerToolbar.m in Sources */,
3A4C94FA1B5B21410088C3F2 /* FLEXArgumentInputNumberView.m in Sources */,
779B1ED71C0C4D7C001F5E49 /* FLEXTableContentViewController.m in Sources */,
C395D6DA21789BD800BEAD4D /* FLEXColorExplorerViewController.m in Sources */,
3A4C95001B5B21410088C3F2 /* FLEXArgumentInputSwitchView.m in Sources */,
3A4C94CC1B5B21410088C3F2 /* FLEXDictionaryExplorerViewController.m in Sources */,
3A4C953F1B5B21410088C3F2 /* FLEXNetworkTransactionDetailTableViewController.m in Sources */,
Expand Down

4 comments on commit 24d5f3e

@revolter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this presented?

@NSExceptional
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When viewing a color object (so, not when you tap on a mutable color property)

Looks like this

@revolter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how do you get to a color object if not through a view's property?

@NSExceptional
Copy link
Collaborator Author

@NSExceptional NSExceptional commented on 24d5f3e Nov 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all properties are readwrite 😉 Calling methods and using the heap explorer could also take you here.

Please sign in to comment.