TUIImageReplyQuoteView.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // TUIImageReplyQuoteView.m
  3. // TUIChat
  4. //
  5. // Created by harvy on 2021/11/25.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIImageReplyQuoteView.h"
  9. #import "TUIImageReplyQuoteViewData.h"
  10. @implementation TUIImageReplyQuoteView
  11. - (instancetype)initWithFrame:(CGRect)frame {
  12. if (self = [super initWithFrame:frame]) {
  13. _imageView = [[UIImageView alloc] init];
  14. _imageView.frame = CGRectMake(0, 0, 60, 60);
  15. [self addSubview:_imageView];
  16. }
  17. return self;
  18. }
  19. - (void)fillWithData:(TUIReplyQuoteViewData *)data {
  20. [super fillWithData:data];
  21. if (![data isKindOfClass:TUIImageReplyQuoteViewData.class]) {
  22. return;
  23. }
  24. TUIImageReplyQuoteViewData *myData = (TUIImageReplyQuoteViewData *)data;
  25. self.imageView.image = myData.image;
  26. if (myData.image == nil && myData.imageStatus != TUIImageReplyQuoteStatusDownloading) {
  27. [myData downloadImage];
  28. }
  29. // tell constraints they need updating
  30. [self setNeedsUpdateConstraints];
  31. // update constraints now so we can animate the change
  32. [self updateConstraintsIfNeeded];
  33. [self layoutIfNeeded];
  34. }
  35. + (BOOL)requiresConstraintBasedLayout {
  36. return YES;
  37. }
  38. // this is Apple's recommended place for adding/updating constraints
  39. - (void)updateConstraints {
  40. [super updateConstraints];
  41. TUIImageReplyQuoteViewData *myData = (TUIImageReplyQuoteViewData *)self.data;
  42. [self.imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  43. make.leading.mas_equalTo(self);
  44. make.top.mas_equalTo(self);
  45. make.size.mas_equalTo(myData.imageSize);
  46. }];
  47. }
  48. - (void)reset {
  49. [super reset];
  50. self.imageView.image = nil;
  51. self.imageView.frame = CGRectMake(self.imageView.frame.origin.x, self.imageView.frame.origin.y, 60, 60);
  52. }
  53. @end