aligned chat bubbles & width and height of bubbles depend on message length

This commit is contained in:
David Idmansour 2018-06-27 17:06:46 +02:00
parent 9d2226c7db
commit 59d81cd2ef
5 changed files with 43 additions and 13 deletions

View file

@ -1256,6 +1256,9 @@ 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"];

View file

@ -26,25 +26,25 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="OXj-8D-5BS">
<rect key="frame" x="60" y="10" width="305" height="80"/>
<rect key="frame" x="60" y="10" width="305" height="90"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WZa-ow-o0L">
<rect key="frame" x="0.0" y="0.0" width="305" height="17"/>
<constraints>
<constraint firstAttribute="height" constant="17" id="tvJ-aj-CIf"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="Lorem ipsum " textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="3tK-2u-Ixe">
<rect key="frame" x="0.0" y="17" width="305" height="42.5"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<rect key="frame" x="0.0" y="17" width="305" height="59.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gv1-l8-gh3">
<rect key="frame" x="0.0" y="59.5" width="305" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<rect key="frame" x="0.0" y="76.5" width="305" height="13.5"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
@ -87,8 +87,8 @@
<constraint firstItem="SKQ-W1-Lmw" firstAttribute="leading" secondItem="Q3t-C0-U1O" secondAttribute="leading" constant="10" id="ZPR-9n-0E4"/>
<constraint firstItem="FHB-G3-atz" firstAttribute="leading" secondItem="Q3t-C0-U1O" secondAttribute="leading" id="d7N-zS-IjG"/>
<constraint firstItem="OXj-8D-5BS" firstAttribute="leading" secondItem="Q3t-C0-U1O" secondAttribute="leading" constant="60" id="e0Q-na-hor"/>
<constraint firstItem="Wh2-bk-96C" firstAttribute="leading" secondItem="Q3t-C0-U1O" secondAttribute="trailing" constant="-375" id="hOW-4m-Ke6"/>
<constraint firstAttribute="bottom" secondItem="OXj-8D-5BS" secondAttribute="bottom" constant="10" id="mVA-WG-D1q"/>
<constraint firstItem="Wh2-bk-96C" firstAttribute="leading" secondItem="Q3t-C0-U1O" secondAttribute="leading" id="hOW-4m-Ke6"/>
<constraint firstAttribute="bottom" secondItem="OXj-8D-5BS" secondAttribute="bottom" id="mVA-WG-D1q"/>
<constraint firstAttribute="bottom" secondItem="Wh2-bk-96C" secondAttribute="bottom" id="scj-em-N61"/>
</constraints>
</tableViewCellContentView>

View file

@ -14,5 +14,8 @@
@property (weak, nonatomic) IBOutlet UILabel *imdm;
@property (weak, nonatomic) IBOutlet UIImageView *background;
@property (weak, nonatomic) IBOutlet UIImageView *bottomBarColor;
@property BOOL isOutgoing;
@property float width;
@property float height;
@end

View file

@ -23,4 +23,20 @@
// Configure the view for the selected state
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect bubbleFrame = self.contentView.frame;
int origin_x;
bubbleFrame.size = CGSizeMake(_width, _height);
origin_x = (_isOutgoing ? self.frame.size.width - bubbleFrame.size.width - 5 : 5);
bubbleFrame.origin.x = origin_x;
self.contentView.frame = bubbleFrame;
_msgText.textContainerInset = UIEdgeInsetsZero;
_msgText.textContainer.lineFragmentPadding = 0;
}
@end

View file

@ -37,7 +37,6 @@
animated:YES];
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];
}
#pragma mark - UITableViewDataSource Functions
@ -65,21 +64,30 @@
cell.contactImage.image = [UIImage imageWithData:imageData];
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;
cell.nameDate.textColor = [UIColor colorWithPatternImage:cell.background.image];
cell.msgText.textColor = [UIColor darkGrayColor];
if (!isOutgoing)
cell.imdm.hidden = YES;
if ([imdm isEqualToString:@"LinphoneChatMessageStateDelivered"])
if ([imdm isEqualToString:@"LinphoneChatMessageStateDelivered"]) {
cell.imdm.text = NSLocalizedString(@"Delivered", nil);
else if ([imdm isEqualToString:@"LinphoneChatMessageStateDisplayed"])
cell.imdm.textColor = [UIColor grayColor];
} else if ([imdm isEqualToString:@"LinphoneChatMessageStateDisplayed"]) {
cell.imdm.text = NSLocalizedString(@"Read", nil);
else
cell.imdm.textColor = [UIColor colorWithRed:(24 / 255.0) green:(167 / 255.0) blue:(175 / 255.0) alpha:1.0];
} else
cell.imdm.text = imdm;
printf("Taille label : %f\n", cell.nameDate.font.pointSize);
printf("Taille field : %f\n", cell.msgText.font.pointSize);
return cell;
}
#pragma mark - UITableViewDelegate Functions
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
return ((NSNumber *)[msgs[indexPath.row] objectForKey:@"height"]).floatValue + 5;
}
@end