FLEXTableViewSection.m 3.3 KB

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