chat: fix text bubble size

This commit is contained in:
Gautier Pelloux-Prayer 2015-10-13 13:10:01 +02:00
parent 1606420a24
commit 7a572129b2
3 changed files with 36 additions and 52 deletions

View file

@ -25,12 +25,11 @@
@interface UIChatBubbleTextCell : UITableViewCell
@property(nonatomic, weak) IBOutlet UIImageView *backgroundColor;
@property(nonatomic, weak) IBOutlet UIImageView *backgroundColorImage;
@property(nonatomic, weak) IBOutlet UIRoundedImageView *avatarImage;
@property(nonatomic, weak) IBOutlet UILabel *contactDateLabel;
@property(nonatomic, weak) IBOutlet UIImageView *statusImage;
@property(nonatomic, weak) IBOutlet UITextViewNoDefine *messageText;
@property(nonatomic, weak) IBOutlet UIButton *deleteButton;
@property(weak, nonatomic) IBOutlet UIImageView *bottomBarColor;
@property(nonatomic, strong) id<ChatConversationDelegate> chatRoomDelegate;
@property(strong, nonatomic) IBOutlet UIView *bubbleView;

View file

@ -105,8 +105,7 @@
LinphoneChatMessageState state = linphone_chat_message_get_state(message);
BOOL outgoing = linphone_chat_message_is_outgoing(message);
// _backgroundColor.image = _bottomBarColor.image = [UIImage imageNamed:outgoing ? @"color_A" : @"color_F"];
_backgroundColorImage.image = _bottomBarColor.image = [UIImage imageNamed:(outgoing ? @"color_A" : @"color_D")];
if (!outgoing) {
_statusImage.accessibilityValue = @"incoming";
_statusImage.hidden = TRUE; // not useful for incoming chats..
@ -142,14 +141,6 @@
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
_messageText.userInteractionEnabled = !editing;
if (animated) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
}
_deleteButton.hidden = !editing;
if (animated) {
[UIView commitAnimations];
}
}
#pragma mark - Action Functions
@ -209,15 +200,16 @@ static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState st
#pragma mark - Bubble size computing
- (CGSize)viewSizeWithWidth:(int)width {
static const CGFloat TEXT_MIN_HEIGHT = 50.0f;
static const CGFloat TEXT_MIN_HEIGHT = 32.;
static const CGFloat TEXT_MIN_WIDTH = 150.0f;
static const CGFloat MARGIN_WIDTH = 47 + 10;
static const CGFloat MARGIN_HEIGHT = 12 + 10;
static const CGFloat IMAGE_HEIGHT = 100.0f; // TODO: move that in bubblephpto
static const CGFloat MARGIN_WIDTH = 60;
static const CGFloat MARGIN_HEIGHT = 19 + 16 /*this 16 is because textview add some top&bottom padding*/;
static const CGFloat IMAGE_HEIGHT = 100.0f; // TODO: move that in bubblephoto
static const CGFloat IMAGE_WIDTH = 100.0f;
static const CGFloat CHECK_BOX_WIDTH = 40;
CGSize messageSize, dateSize;
int messageAvailableWidth = width - MARGIN_WIDTH;
int messageAvailableWidth = width - MARGIN_WIDTH - CHECK_BOX_WIDTH;
const char *url = linphone_chat_message_get_external_body_url(message);
if (url == nil && linphone_chat_message_get_file_transfer_information(message) == NULL) {
@ -227,15 +219,15 @@ static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState st
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7) {
messageSize =
[text boundingRectWithSize:CGSizeMake(messageAvailableWidth, CGFLOAT_MAX)
options:(NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading)
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
attributes:@{
NSFontAttributeName : _messageText.font
} context:nil]
}
context:nil]
.size;
dateSize = [_contactDateLabel.text boundingRectWithSize:_contactDateLabel.frame.size
options:(NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingTruncatesLastVisibleLine |
NSStringDrawingUsesFontLeading)
attributes:@{
NSFontAttributeName : _contactDateLabel.font
@ -246,25 +238,22 @@ static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState st
#endif
{
messageSize = [text sizeWithFont:_messageText.font
constrainedToSize:CGSizeMake(messageAvailableWidth, 10000.0f)
lineBreakMode:NSLineBreakByTruncatingTail];
dateSize = [text sizeWithFont:_contactDateLabel.font
constrainedToSize:_contactDateLabel.frame.size
lineBreakMode:NSLineBreakByTruncatingTail];
constrainedToSize:CGSizeMake(messageAvailableWidth, CGFLOAT_MAX)
lineBreakMode:NSLineBreakByCharWrapping];
dateSize = [_contactDateLabel.text sizeWithFont:_contactDateLabel.font
constrainedToSize:_contactDateLabel.frame.size
lineBreakMode:NSLineBreakByCharWrapping];
}
} else {
messageSize = CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT);
}
messageSize.width = MAX(TEXT_MIN_WIDTH, ceil(messageSize.width));
messageSize.height = MAX(TEXT_MIN_HEIGHT, ceil(messageSize.height));
messageSize.width = MAX(TEXT_MIN_WIDTH, messageSize.width);
messageSize.height = MAX(TEXT_MIN_HEIGHT, messageSize.height);
CGSize bubbleSize;
bubbleSize.width = MAX(messageSize.width, dateSize.width + _statusImage.frame.size.width + 5) + MARGIN_WIDTH;
bubbleSize.height = messageSize.height + MARGIN_HEIGHT;
CGSize bubbleSize = messageSize;
bubbleSize.width = MAX(messageSize.width, dateSize.width) + MARGIN_WIDTH;
bubbleSize.height += MARGIN_HEIGHT;
LOGE(@"%d %fx%f for %@", width, bubbleSize.width, bubbleSize.height,
[UIChatBubbleTextCell TextMessageForChat:message]);
return bubbleSize;
}
@ -275,7 +264,6 @@ static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState st
BOOL is_outgoing = linphone_chat_message_is_outgoing(message);
CGRect bubbleFrame = _bubbleView.frame;
bubbleFrame.size = [self viewSizeWithWidth:self.frame.size.width];
bubbleFrame.size.width += 10;
bubbleFrame.origin.x =
tableView.isEditing ? 0 : (is_outgoing ? self.frame.size.width - bubbleFrame.size.width : 0);
_bubbleView.frame = bubbleFrame;

View file

@ -8,7 +8,7 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="UIChatBubbleTextCell">
<connections>
<outlet property="avatarImage" destination="P1c-sD-eOv" id="h5P-hl-jbX"/>
<outlet property="backgroundColor" destination="q2R-Zv-e5a" id="35T-Du-1AF"/>
<outlet property="backgroundColorImage" destination="ZIO-Cb-28G" id="asA-a1-Rko"/>
<outlet property="bottomBarColor" destination="mlr-pl-B6T" id="4Lk-Vn-E8h"/>
<outlet property="bubbleView" destination="ucH-2r-rar" id="XWU-yi-1z8"/>
<outlet property="contactDateLabel" destination="GRe-ur-aSb" id="DQA-v4-IjX"/>
@ -23,19 +23,19 @@
</connections>
</tapGestureRecognizer>
<view contentMode="scaleToFill" id="ucH-2r-rar">
<rect key="frame" x="0.0" y="0.0" width="357" height="199"/>
<rect key="frame" x="0.0" y="0.0" width="334" height="171"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<subviews>
<view clipsSubviews="YES" contentMode="scaleToFill" id="vdk-RV-QRU" userLabel="innerView">
<rect key="frame" x="6" y="5" width="345" height="189"/>
<rect key="frame" x="6" y="5" width="322" height="161"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" alpha="0.19999999999999968" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="color_A.png" id="q2R-Zv-e5a" userLabel="backgroundColor">
<rect key="frame" x="0.0" y="0.0" width="345" height="189"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<imageView userInteractionEnabled="NO" alpha="0.20000000000000001" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="color_A.png" id="ZIO-Cb-28G" userLabel="backgroundColorImage">
<rect key="frame" x="0.0" y="0.0" width="322" height="161"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="avatar.png" id="P1c-sD-eOv" userLabel="avatarImage" customClass="UIRoundedImageView">
<rect key="frame" x="8" y="2" width="40" height="40"/>
<rect key="frame" x="7" y="2" width="40" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<accessibility key="accessibilityConfiguration" label="Contact avatar">
<accessibilityTraits key="traits" none="YES" image="YES" notEnabled="YES"/>
@ -65,22 +65,19 @@
<nil key="highlightedColor"/>
</label>
<textView clipsSubviews="YES" contentMode="scaleToFill" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" editable="NO" id="CYa-If-oB4" userLabel="messageText" customClass="UITextViewNoDefine">
<rect key="frame" x="48" y="10" width="299" height="168"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<string key="text">static const CGFloat CELL_MESSAGE_WIDTH_MARGIN = 26.0f + 10.0f + 48;
static const CGFloat CELL_MESSAGE_HEIGHT_MARGIN = 10.0f + 10;
static const CGFloat CELL_IMAGE_HEIGHT = 100.0f;
static const CGFloat CELL_IMAGE_WIDTH = 100.0f;</string>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<rect key="frame" x="48" y="9" width="268" height="152"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
<string key="text">https://beta.itunes.apple.com/v1/invite/deb3eac7cecf43c7a33cfd2300e480f0a1a5f645a88240e8b0fe9951b7f1eae215762a66?ct=Z2V957B3D6&amp;pt=2003</string>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
<dataDetectorType key="dataDetectorTypes" link="YES"/>
</textView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="chat_message_inprogress.png" id="nLy-JO-TyL" userLabel="statusImage">
<rect key="frame" x="330" y="0.0" width="15" height="15"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<rect key="frame" x="307" y="0.0" width="15" height="15"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="color_A.png" id="mlr-pl-B6T" userLabel="bottomBarColor">
<rect key="frame" x="0.0" y="188" width="345" height="1"/>
<rect key="frame" x="0.0" y="160" width="322" height="1"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
</imageView>
</subviews>