TUIReplyPreviewBar.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // TUIInputPreviewBar.m
  3. // TUIChat
  4. //
  5. // Created by harvy on 2021/11/9.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIReplyPreviewBar.h"
  9. #import <TIMCommon/NSString+TUIEmoji.h>
  10. #import <TIMCommon/TIMDefine.h>
  11. #import <TUICore/TUIDarkModel.h>
  12. #import <TUICore/TUIThemeManager.h>
  13. @implementation TUIReplyPreviewBar
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. if (self = [super initWithFrame:frame]) {
  16. [self setupViews];
  17. }
  18. return self;
  19. }
  20. - (void)setupViews {
  21. self.backgroundColor = TUIChatDynamicColor(@"chat_input_controller_bg_color", @"#EBF0F6");
  22. [self addSubview:self.titleLabel];
  23. [self addSubview:self.closeButton];
  24. }
  25. - (void)layoutSubviews {
  26. [super layoutSubviews];
  27. self.closeButton.mm_width(16).mm_height(16);
  28. self.closeButton.mm_centerY = self.mm_centerY;
  29. self.closeButton.mm_right(16.0);
  30. self.titleLabel.mm_x = 16.0;
  31. self.titleLabel.mm_y = 10;
  32. self.titleLabel.mm_w = self.closeButton.mm_x - 10 - 16;
  33. self.titleLabel.mm_h = self.mm_h - 20;
  34. }
  35. - (void)onClose:(UIButton *)closeButton {
  36. if (self.onClose) {
  37. self.onClose();
  38. }
  39. }
  40. - (void)setPreviewData:(TUIReplyPreviewData *)previewData {
  41. _previewData = previewData;
  42. NSString *abstract = [TUIReplyPreviewData displayAbstract:previewData.type abstract:previewData.msgAbstract withFileName:YES isRisk:NO];
  43. _titleLabel.text = [[NSString stringWithFormat:@"%@: %@", previewData.sender, abstract] getLocalizableStringWithFaceContent];
  44. _titleLabel.lineBreakMode = previewData.type == (NSInteger)V2TIM_ELEM_TYPE_FILE ? NSLineBreakByTruncatingMiddle : NSLineBreakByTruncatingTail;
  45. }
  46. - (void)setPreviewReferenceData:(TUIReferencePreviewData *)previewReferenceData {
  47. _previewReferenceData = previewReferenceData;
  48. NSString *abstract = [TUIReferencePreviewData displayAbstract:previewReferenceData.type
  49. abstract:previewReferenceData.msgAbstract
  50. withFileName:YES
  51. isRisk:NO];
  52. _titleLabel.text = [[NSString stringWithFormat:@"%@: %@", previewReferenceData.sender, abstract] getLocalizableStringWithFaceContent];
  53. _titleLabel.lineBreakMode = previewReferenceData.type == (NSInteger)V2TIM_ELEM_TYPE_FILE ? NSLineBreakByTruncatingMiddle : NSLineBreakByTruncatingTail;
  54. }
  55. - (UILabel *)titleLabel {
  56. if (_titleLabel == nil) {
  57. _titleLabel = [[UILabel alloc] init];
  58. _titleLabel.font = [UIFont systemFontOfSize:16];
  59. _titleLabel.textColor = [UIColor colorWithRed:143 / 255.0 green:150 / 255.0 blue:160 / 255.0 alpha:1 / 1.0];
  60. }
  61. return _titleLabel;
  62. }
  63. - (UIButton *)closeButton {
  64. if (_closeButton == nil) {
  65. _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  66. [_closeButton setImage:TUIChatCommonBundleImage(@"icon_close") forState:UIControlStateNormal];
  67. [_closeButton addTarget:self action:@selector(onClose:) forControlEvents:UIControlEventTouchUpInside];
  68. [_closeButton sizeToFit];
  69. }
  70. return _closeButton;
  71. }
  72. @end
  73. @implementation TUIReferencePreviewBar
  74. - (void)layoutSubviews {
  75. [super layoutSubviews];
  76. self.closeButton.mm_right(16.0);
  77. self.closeButton.frame = CGRectMake(self.closeButton.frame.origin.x, (self.frame.size.height - 16) * 0.5, 16, 16);
  78. self.titleLabel.mm_x = 16.0;
  79. self.titleLabel.mm_y = 10;
  80. self.titleLabel.mm_w = self.closeButton.mm_x - 10 - 16;
  81. self.titleLabel.mm_h = self.mm_h - 20;
  82. }
  83. @end