TUIChatPopContextExtionView.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // TUIChatPopContextExtionView.m
  3. // TUIEmojiPlugin
  4. //
  5. // Created by wyl on 2023/12/1.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIChatPopContextExtionView.h"
  9. #import <TIMCommon/NSString+TUIEmoji.h>
  10. #import <TIMCommon/TIMCommonModel.h>
  11. #import <TIMCommon/TIMDefine.h>
  12. #import <TIMCommon/TUIFitButton.h>
  13. #import <TIMCommon/TIMCommonMediator.h>
  14. #import <TIMCommon/TUIEmojiMeditorProtocol.h>
  15. @implementation TUIChatPopContextExtionItem
  16. - (instancetype)initWithTitle:(NSString *)title markIcon:(UIImage *)markIcon weight:(NSInteger)weight withActionHandler:(void (^)(id action))actionHandler {
  17. self = [super init];
  18. if (self) {
  19. _title = title;
  20. _markIcon = markIcon;
  21. _weight = weight;
  22. _actionHandler = actionHandler;
  23. }
  24. return self;
  25. }
  26. @end
  27. @interface TUIChatPopContextExtionItemView : UIView
  28. @property(nonatomic, strong) TUIChatPopContextExtionItem *item;
  29. @property(nonatomic, strong) UIImageView *icon;
  30. @property(nonatomic, strong) UILabel *l;
  31. - (void)configBaseUIWithItem:(TUIChatPopContextExtionItem *)item;
  32. @end
  33. @implementation TUIChatPopContextExtionItemView
  34. - (void)configBaseUIWithItem:(TUIChatPopContextExtionItem *)item {
  35. self.item = item;
  36. CGFloat itemWidth = self.frame.size.width;
  37. CGFloat padding = kScale390(16);
  38. CGFloat itemHeight = self.frame.size.height;
  39. UIImageView *icon = [[UIImageView alloc] init];
  40. [self addSubview:icon];
  41. icon.frame = CGRectMake(itemWidth - padding - kScale390(18), itemHeight * 0.5 - kScale390(18) * 0.5, kScale390(18), kScale390(18));
  42. icon.image = self.item.markIcon;
  43. UILabel *l = [[UILabel alloc] init];
  44. l.frame = CGRectMake(padding, 0, itemWidth * 0.5, itemHeight);
  45. l.text = self.item.title;
  46. l.font = item.titleFont ?: [UIFont systemFontOfSize:kScale390(16)];
  47. l.textAlignment = isRTL()? NSTextAlignmentRight:NSTextAlignmentLeft;
  48. l.textColor = item.titleColor ?: [UIColor blackColor];
  49. l.userInteractionEnabled = false;
  50. [self addSubview:l];
  51. UIButton *backButton = [UIButton buttonWithType:UIButtonTypeSystem];
  52. [backButton addTarget:self action:@selector(buttonclick) forControlEvents:UIControlEventTouchUpInside];
  53. backButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
  54. backButton.frame = CGRectMake(0, 0, itemWidth, itemHeight);
  55. [self addSubview:backButton];
  56. if (item.needBottomLine) {
  57. UIView *line = [UIView new];
  58. line.backgroundColor = [UIColor tui_colorWithHex:@"DDDDDD"];
  59. line.frame = CGRectMake(0, itemHeight - kScale390(0.5), itemWidth, kScale390(0.5));
  60. [self addSubview:line];
  61. }
  62. self.layer.masksToBounds = YES;
  63. if (isRTL()) {
  64. for (UIView *subview in self.subviews) {
  65. [subview resetFrameToFitRTL];
  66. }
  67. }
  68. }
  69. - (void)buttonclick {
  70. if (self.item.actionHandler) {
  71. self.item.actionHandler(self.item);
  72. }
  73. }
  74. @end
  75. @interface TUIChatPopContextExtionView ()
  76. @property(nonatomic, strong) NSMutableArray<TUIChatPopContextExtionItem *> *items;
  77. @end
  78. @implementation TUIChatPopContextExtionView
  79. - (void)configUIWithItems:(NSMutableArray<TUIChatPopContextExtionItem *> *)items topBottomMargin:(CGFloat)topBottomMargin {
  80. if (self.subviews.count > 0) {
  81. for (UIView *subview in self.subviews) {
  82. if (subview) {
  83. [subview removeFromSuperview];
  84. }
  85. }
  86. }
  87. int i = 0;
  88. for (TUIChatPopContextExtionItem *item in items) {
  89. TUIChatPopContextExtionItemView *itemView = [[TUIChatPopContextExtionItemView alloc] init];
  90. itemView.frame = CGRectMake(0, (kScale390(40)) * i + topBottomMargin, kScale390(180), kScale390(40));
  91. [itemView configBaseUIWithItem:item];
  92. [self addSubview:itemView];
  93. i++;
  94. }
  95. }
  96. @end