FLEXViewControllersViewController.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // FLEXViewControllersViewController.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 2/13/20.
  6. // Copyright © 2020 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXViewControllersViewController.h"
  9. #import "FLEXObjectExplorerFactory.h"
  10. #import "FLEXMutableListSection.h"
  11. #import "FLEXUtility.h"
  12. @interface FLEXViewControllersViewController ()
  13. @property (nonatomic, readonly) FLEXMutableListSection *section;
  14. @property (nonatomic, readonly) NSArray<UIViewController *> *controllers;
  15. @end
  16. @implementation FLEXViewControllersViewController
  17. @dynamic sections, allSections;
  18. #pragma mark - Initialization
  19. + (instancetype)controllersForViews:(NSArray<UIView *> *)views {
  20. return [[self alloc] initWithViews:views];
  21. }
  22. - (id)initWithViews:(NSArray<UIView *> *)views {
  23. NSParameterAssert(views.count);
  24. self = [self initWithStyle:UITableViewStylePlain];
  25. if (self) {
  26. _controllers = [views flex_mapped:^id(UIView *view, NSUInteger idx) {
  27. return [FLEXUtility viewControllerForView:view];
  28. }];
  29. }
  30. return self;
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. self.title = @"View Controllers at Tap";
  35. [self disableToolbar];
  36. }
  37. - (NSArray<FLEXTableViewSection *> *)makeSections {
  38. _section = [FLEXMutableListSection list:self.controllers
  39. cellConfiguration:^(UITableViewCell *cell, UIViewController *controller, NSInteger row) {
  40. cell.textLabel.text = [NSString
  41. stringWithFormat:@"%@ — %p", NSStringFromClass(controller.class), controller
  42. ];
  43. cell.detailTextLabel.text = controller.view.description;
  44. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  45. cell.textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  46. } filterMatcher:^BOOL(NSString *filterText, UIViewController *controller) {
  47. return [NSStringFromClass(controller.class) localizedCaseInsensitiveContainsString:filterText];
  48. }];
  49. self.section.selectionHandler = ^(UIViewController *host, UIViewController *controller) {
  50. [host.navigationController pushViewController:
  51. [FLEXObjectExplorerFactory explorerViewControllerForObject:controller]
  52. animated:YES];
  53. };
  54. self.section.customTitle = @"View Controllers";
  55. return @[self.section];
  56. }
  57. #pragma mark - Private
  58. - (void)dismissAnimated {
  59. [self dismissViewControllerAnimated:YES completion:nil];
  60. }
  61. @end