mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
chat bubbles size calculated based on notification view size
This commit is contained in:
parent
feb2a9a461
commit
1753ddc032
4 changed files with 64 additions and 8 deletions
|
|
@ -1256,9 +1256,6 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, LinphoneAut
|
|||
const char *filename = linphone_content_get_name(file);
|
||||
[msgData setObject:[NSString stringWithUTF8String:filename] forKey:@"msg"];
|
||||
} else {
|
||||
CGSize msgSize = [UIChatBubbleTextCell ViewSizeForMessage:msg withWidth:375];
|
||||
[msgData setObject:[NSNumber numberWithFloat:msgSize.width] forKey:@"width"];
|
||||
[msgData setObject:[NSNumber numberWithFloat:msgSize.height] forKey:@"height"];
|
||||
[msgData setObject:[UIChatBubbleTextCell TextMessageForChat:msg] forKey:@"msg"];
|
||||
}
|
||||
[msgData setObject:[NSNumber numberWithBool:isOutgoing] forKey:@"isOutgoing"];
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
@interface NotificationTableViewCell : UITableViewCell
|
||||
@property (weak, nonatomic) IBOutlet UIImageView *contactImage;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *nameDate;
|
||||
@property (weak, nonatomic) IBOutlet UITextView *msgText;
|
||||
@property (strong, nonatomic) IBOutlet UITextView *msgText;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *imdm;
|
||||
@property (weak, nonatomic) IBOutlet UIImageView *background;
|
||||
@property (weak, nonatomic) IBOutlet UIImageView *bottomBarColor;
|
||||
|
|
@ -19,4 +19,7 @@
|
|||
@property float width;
|
||||
@property float height;
|
||||
|
||||
- (CGSize)ViewSizeForMessage:(NSString *)chat withWidth:(int)width;
|
||||
- (CGSize)ViewHeightForMessage:(NSString *)messageText withWidth:(int)width;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -39,4 +39,56 @@
|
|||
_msgText.textContainer.lineFragmentPadding = 0;
|
||||
}
|
||||
|
||||
#pragma mark - Bubble size computing
|
||||
|
||||
- (CGSize)computeBoundingBox:(NSString *)text size:(CGSize)size font:(UIFont *)font {
|
||||
if (!text || text.length == 0)
|
||||
return CGSizeMake(0, 0);
|
||||
|
||||
return [text boundingRectWithSize:size
|
||||
options:(NSStringDrawingUsesLineFragmentOrigin |
|
||||
NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading)
|
||||
attributes:@{
|
||||
NSFontAttributeName : font
|
||||
}
|
||||
context:nil].size;
|
||||
}
|
||||
|
||||
static const CGFloat CELL_MIN_HEIGHT = 60.0f;
|
||||
static const CGFloat CELL_MIN_WIDTH = 190.0f;
|
||||
static const CGFloat CELL_MESSAGE_X_MARGIN = 78 + 10.0f;
|
||||
static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44;
|
||||
|
||||
- (CGSize)ViewHeightForMessage:(NSString *)messageText withWidth:(int)width {
|
||||
static UIFont *messageFont = nil;
|
||||
|
||||
if (!messageFont) {
|
||||
messageFont = _msgText.font;
|
||||
}
|
||||
CGSize size;
|
||||
size = [self computeBoundingBox:messageText
|
||||
size:CGSizeMake(width - CELL_MESSAGE_X_MARGIN - 4, CGFLOAT_MAX)
|
||||
font:messageFont];
|
||||
|
||||
size.width = MAX(size.width + CELL_MESSAGE_X_MARGIN, CELL_MIN_WIDTH);
|
||||
size.height = MAX(size.height + CELL_MESSAGE_Y_MARGIN, CELL_MIN_HEIGHT);
|
||||
return size;
|
||||
}
|
||||
- (CGSize)ViewSizeForMessage:(NSString *)chat withWidth:(int)width {
|
||||
static UIFont *dateFont = nil;
|
||||
static CGSize dateViewSize;
|
||||
|
||||
if (!dateFont) {
|
||||
dateFont = _nameDate.font;
|
||||
dateViewSize = _nameDate.frame.size;
|
||||
dateViewSize.width = CGFLOAT_MAX;
|
||||
}
|
||||
|
||||
CGSize messageSize = [self ViewHeightForMessage:chat withWidth:width];
|
||||
CGSize dateSize = [self computeBoundingBox:_nameDate.text size:dateViewSize font:dateFont];
|
||||
messageSize.width = MAX(MAX(messageSize.width, MIN(dateSize.width + CELL_MESSAGE_X_MARGIN, width)), CELL_MIN_WIDTH);
|
||||
|
||||
return messageSize;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
NSLog(@"Content length : %f", self.tableView.contentSize.height);
|
||||
NSLog(@"Number of rows : %d", (unsigned int)[self tableView:self.tableView numberOfRowsInSection:0]);
|
||||
[self.view.superview bringSubviewToFront:self.tableView];
|
||||
self.tableView.bounds = CGRectMake(self.tableView.bounds.origin.x, self.tableView.bounds.origin.y, self.tableView.contentSize.width, self.tableView.contentSize.height);
|
||||
NSLog(@"View length : %f", self.tableView.bounds.size.height);
|
||||
}
|
||||
|
||||
|
|
@ -68,8 +67,9 @@
|
|||
cell.nameDate.text = display;
|
||||
cell.msgText.text = msgText;
|
||||
cell.isOutgoing = isOutgoing;
|
||||
cell.width = ((NSNumber *)[msgs[indexPath.row] objectForKey:@"width"]).floatValue;
|
||||
cell.height = ((NSNumber *)[msgs[indexPath.row] objectForKey:@"height"]).floatValue;
|
||||
CGSize size = [cell ViewSizeForMessage:msgText withWidth:self.view.bounds.size.width - 10];
|
||||
cell.width = size.width;
|
||||
cell.height = size.height;
|
||||
cell.nameDate.textColor = [UIColor colorWithPatternImage:cell.background.image];
|
||||
cell.msgText.textColor = [UIColor darkGrayColor];
|
||||
if (!isOutgoing) {
|
||||
|
|
@ -94,7 +94,11 @@
|
|||
#pragma mark - UITableViewDelegate Functions
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
return ((NSNumber *)[msgs[indexPath.row] objectForKey:@"height"]).floatValue + 5;
|
||||
NotificationTableViewCell *cell = [[NotificationTableViewCell alloc] init];
|
||||
cell.msgText = [[UITextView alloc] init];
|
||||
cell.msgText.text = ((NSString *)[msgs[indexPath.row] objectForKey:@"msg"]);
|
||||
cell.msgText.font = [UIFont systemFontOfSize:17];
|
||||
return [cell ViewHeightForMessage:cell.msgText.text withWidth:self.view.bounds.size.width - 10].height + 5;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue