FLEXTableViewSection.m 3.3 KB

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