FLEXExplorerSection.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // FLEXExplorerSection.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/28/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXExplorerSection.h"
  9. #import "FLEXTableView.h"
  10. #import "UIMenu+FLEX.h"
  11. #pragma clang diagnostic push
  12. #pragma clang diagnostic ignored "-Wincomplete-implementation"
  13. @implementation FLEXExplorerSection
  14. - (void)reloadData { }
  15. - (NSDictionary<NSString *,Class> *)cellRegistrationMapping {
  16. return nil;
  17. }
  18. - (BOOL)canSelectRow:(NSInteger)row { return NO; }
  19. - (void (^)(UIViewController *))didSelectRowAction:(NSInteger)row {
  20. UIViewController *toPush = [self viewControllerToPushForRow:row];
  21. if (toPush) {
  22. return ^(UIViewController *host) {
  23. [host.navigationController pushViewController:toPush animated:YES];
  24. };
  25. }
  26. return nil;
  27. }
  28. - (UIViewController *)viewControllerToPushForRow:(NSInteger)row {
  29. return nil;
  30. }
  31. - (void (^)(UIViewController *))didPressInfoButtonAction:(NSInteger)row {
  32. return nil;
  33. }
  34. - (NSString *)reuseIdentifierForRow:(NSInteger)row {
  35. return kFLEXDefaultCell;
  36. }
  37. #if FLEX_AT_LEAST_IOS13_SDK
  38. - (NSString *)menuTitleForRow:(NSInteger)row {
  39. NSString *title = [self titleForRow:row];
  40. NSString *subtitle = [self menuSubtitleForRow:row];
  41. if (subtitle.length) {
  42. return [NSString stringWithFormat:@"%@\n\n%@", title, subtitle];
  43. }
  44. return title;
  45. }
  46. - (NSString *)menuSubtitleForRow:(NSInteger)row {
  47. return @"";
  48. }
  49. - (NSArray<UIMenuElement *> *)menuItemsForRow:(NSInteger)row sender:(UIViewController *)sender {
  50. NSArray<NSString *> *copyItems = [self copyMenuItemsForRow:row];
  51. NSAssert(copyItems.count % 2 == 0, @"copyMenuItemsForRow: should return an even list");
  52. if (copyItems.count) {
  53. NSInteger numberOfActions = copyItems.count / 2;
  54. BOOL collapseMenu = numberOfActions > 4;
  55. UIImage *copyIcon = [UIImage systemImageNamed:@"doc.on.doc"];
  56. NSMutableArray *actions = [NSMutableArray new];
  57. for (NSInteger i = 0; i < copyItems.count; i += 2) {
  58. NSString *key = copyItems[i], *value = copyItems[i+1];
  59. NSString *title = collapseMenu ? key : [@"Copy " stringByAppendingString:key];
  60. UIAction *copy = [UIAction
  61. actionWithTitle:title
  62. image:copyIcon
  63. identifier:nil
  64. handler:^(__kindof UIAction *action) {
  65. UIPasteboard.generalPasteboard.string = value;
  66. }
  67. ];
  68. if (!value.length) {
  69. copy.attributes = UIMenuElementAttributesDisabled;
  70. }
  71. [actions addObject:copy];
  72. }
  73. UIMenu *copyMenu = [UIMenu
  74. inlineMenuWithTitle:@"Copy…"
  75. image:copyIcon
  76. children:actions
  77. ];
  78. if (collapseMenu) {
  79. return @[[copyMenu collapsed]];
  80. } else {
  81. return @[copyMenu];
  82. }
  83. }
  84. return @[];
  85. }
  86. #endif
  87. - (NSArray<NSString *> *)copyMenuItemsForRow:(NSInteger)row {
  88. return nil;
  89. }
  90. - (NSString *)titleForRow:(NSInteger)row { return nil; }
  91. - (NSString *)subtitleForRow:(NSInteger)row { return nil; }
  92. @end
  93. #pragma clang diagnostic pop