1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-04 10:27:46 +01:00
Telegram/Watch/Extension/TGNeoTextMessageViewModel.m

64 lines
2.3 KiB
Mathematica
Raw Normal View History

2015-10-01 18:19:52 +02:00
#import "TGNeoTextMessageViewModel.h"
#import "TGNeoLabelViewModel.h"
2016-02-25 01:03:51 +01:00
#import "TGMessageViewModel.h"
2015-10-01 18:19:52 +02:00
#import "TGBridgeMessage.h"
@interface TGNeoTextMessageViewModel ()
{
TGNeoLabelViewModel *_textModel;
}
@end
@implementation TGNeoTextMessageViewModel
2016-02-25 01:03:51 +01:00
- (instancetype)initWithMessage:(TGBridgeMessage *)message type:(TGNeoMessageType)type users:(NSDictionary *)users context:(TGBridgeContext *)context
2015-10-01 18:19:52 +02:00
{
2016-02-25 01:03:51 +01:00
self = [super initWithMessage:message type:type users:users context:context];
2015-10-01 18:19:52 +02:00
if (self != nil)
{
NSString *text = [message.text stringByReplacingOccurrencesOfString:@"/" withString:@"/\u2060"];
2016-02-25 01:03:51 +01:00
CGFloat fontSize = [TGNeoBubbleMessageViewModel bodyTextFontSize];
UIColor *textColor = [self normalColorForMessage:message];
if (message.textCheckingResults.count > 0)
{
_textModel = [[TGNeoLabelViewModel alloc] initWithAttributedText:[TGMessageViewModel attributedTextForMessage:message fontSize:fontSize textColor:textColor]];
}
else
{
_textModel = [[TGNeoLabelViewModel alloc] initWithText:text font:[UIFont systemFontOfSize:fontSize] color:textColor attributes:nil];
}
_textModel.multiline = true;
2015-10-01 18:19:52 +02:00
[self addSubmodel:_textModel];
}
return self;
}
2016-02-25 01:03:51 +01:00
2015-10-01 18:19:52 +02:00
- (CGSize)layoutWithContainerSize:(CGSize)containerSize
{
CGSize contentContainerSize = [self contentContainerSizeWithContainerSize:containerSize];
CGSize headerSize = [self layoutHeaderModelsWithContainerSize:contentContainerSize];
CGFloat maxContentWidth = headerSize.width;
CGFloat textTopOffset = headerSize.height;
CGSize textSize = [_textModel contentSizeWithContainerSize:contentContainerSize];
_textModel.frame = CGRectMake(TGNeoBubbleMessageViewModelInsets.left, textTopOffset, textSize.width, textSize.height);
if (textSize.width > maxContentWidth)
maxContentWidth = textSize.width;
CGSize contentSize = CGSizeZero;
contentSize.width = maxContentWidth + TGNeoBubbleMessageViewModelInsets.left + TGNeoBubbleMessageViewModelInsets.right;
contentSize.height = CGRectGetMaxY(_textModel.frame) + TGNeoBubbleMessageViewModelInsets.bottom;
[super layoutWithContainerSize:contentSize];
return contentSize;
}
@end