TUITextReplyQuoteView.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // TUITextReplyQuoteView.m
  3. // TUIChat
  4. //
  5. // Created by harvy on 2021/11/25.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUITextReplyQuoteView.h"
  9. #import <TIMCommon/NSString+TUIEmoji.h>
  10. #import <TUICore/TUIThemeManager.h>
  11. #import "TUITextReplyQuoteViewData.h"
  12. @implementation TUITextReplyQuoteView
  13. - (instancetype)initWithFrame:(CGRect)frame {
  14. if (self = [super initWithFrame:frame]) {
  15. _textLabel = [[UILabel alloc] init];
  16. _textLabel.font = [UIFont systemFontOfSize:10.0];
  17. _textLabel.textColor = TUIChatDynamicColor(@"chat_reply_message_sender_text_color", @"888888");
  18. _textLabel.numberOfLines = 2;
  19. [self addSubview:_textLabel];
  20. }
  21. return self;
  22. }
  23. + (BOOL)requiresConstraintBasedLayout {
  24. return YES;
  25. }
  26. // this is Apple's recommended place for adding/updating constraints
  27. - (void)updateConstraints {
  28. [super updateConstraints];
  29. [self.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  30. make.edges.mas_equalTo(self);
  31. }];
  32. }
  33. - (void)fillWithData:(TUIReplyQuoteViewData *)data {
  34. [super fillWithData:data];
  35. if (![data isKindOfClass:TUITextReplyQuoteViewData.class]) {
  36. return;
  37. }
  38. TUITextReplyQuoteViewData *myData = (TUITextReplyQuoteViewData *)data;
  39. BOOL showRevokeStr = data.originCellData.innerMessage.status == V2TIM_MSG_STATUS_LOCAL_REVOKED &&
  40. !data.showRevokedOriginMessage;
  41. if (showRevokeStr) {
  42. NSString* revokeStr = data.supportForReply ?
  43. TIMCommonLocalizableString(TUIKitRepliesOriginMessageRevoke) :
  44. TIMCommonLocalizableString(TUIKitReferenceOriginMessageRevoke);
  45. self.textLabel.attributedText = [revokeStr getFormatEmojiStringWithFont:self.textLabel.font emojiLocations:nil];
  46. }
  47. else {
  48. self.textLabel.attributedText = [myData.text getFormatEmojiStringWithFont:self.textLabel.font emojiLocations:nil];
  49. }
  50. // tell constraints they need updating
  51. [self setNeedsUpdateConstraints];
  52. // update constraints now so we can animate the change
  53. [self updateConstraintsIfNeeded];
  54. [self layoutIfNeeded];
  55. }
  56. - (void)reset {
  57. self.textLabel.text = @"";
  58. }
  59. @end