Просмотр исходного кода

Add FLEXColorExplorerViewController

Provides a visual of the color for all UIColor objects.
Tanner Bennett лет назад: 7
Родитель
Сommit
24d5f3e9b2

+ 13 - 0
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 - 0
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

+ 4 - 1
Classes/ObjectExplorers/FLEXObjectExplorerFactory.m

@@ -17,6 +17,7 @@
 #import "FLEXImageExplorerViewController.h"
 #import "FLEXClassExplorerViewController.h"
 #import "FLEXLayerExplorerViewController.h"
+#import "FLEXColorExplorerViewController.h"
 #import <objc/runtime.h>
 
 @implementation FLEXObjectExplorerFactory
@@ -38,7 +39,9 @@
                                                    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;

+ 1 - 0
Classes/ObjectExplorers/FLEXObjectExplorerViewController.h

@@ -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.
 

+ 26 - 2
Classes/ObjectExplorers/FLEXObjectExplorerViewController.m

@@ -941,7 +941,8 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
 - (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];
@@ -957,7 +958,16 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
             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;
@@ -974,7 +984,11 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
         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;
 }
 
@@ -1103,6 +1117,16 @@ typedef NS_ENUM(NSUInteger, FLEXMetadataKind) {
     return nil;
 }
 
+- (UIView *)customViewForRowCookie:(id)rowCookie
+{
+    return nil;
+}
+
+- (CGFloat)heightForCustomViewRowForRowCookie:(id)rowCookie
+{
+    return self.tableView.rowHeight;
+}
+
 - (BOOL)canHaveInstanceState
 {
     return YES;

+ 8 - 0
FLEX.xcodeproj/project.pbxproj

@@ -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 */
@@ -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 */
@@ -452,6 +456,8 @@
 				3A4C94511B5B21410088C3F2 /* FLEXViewControllerExplorerViewController.m */,
 				3A4C94521B5B21410088C3F2 /* FLEXViewExplorerViewController.h */,
 				3A4C94531B5B21410088C3F2 /* FLEXViewExplorerViewController.m */,
+				C395D6D721789BD800BEAD4D /* FLEXColorExplorerViewController.h */,
+				C395D6D821789BD800BEAD4D /* FLEXColorExplorerViewController.m */,
 			);
 			path = ObjectExplorers;
 			sourceTree = "<group>";
@@ -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 */,
@@ -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 */,