Unifies bubble sizes for media bubbles

Media bubbles (for photo, video and animated) sizes are calculated using shared logic. The bubbles are fixed width and their height is calculated based on the aspect ratio of the underlying image (clamped to a reasonable min/max height).

Fixes #1270

// FREEBIE
pull/1/head
Matthew Douglass 9 years ago
parent bbfffdf79f
commit c958c7909c

@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0DD55B166906AF3368995978 /* libPods-Signal.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 80CD5E19DD23200E7926EEA7 /* libPods-Signal.a */; };
30209C98DABCE82064B4EAF5 /* libPods-SignalTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A33D3C7EB4B17BDBD47F0FCC /* libPods-SignalTests.a */; };
341BB7491DB727EE001E2975 /* JSQMediaItem+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 341BB7481DB727EE001E2975 /* JSQMediaItem+OWS.m */; };
450873C31D9D5149006B54F2 /* OWSExpirationTimerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 450873C21D9D5149006B54F2 /* OWSExpirationTimerView.m */; };
450873C41D9D5149006B54F2 /* OWSExpirationTimerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 450873C21D9D5149006B54F2 /* OWSExpirationTimerView.m */; };
450873C71D9D867B006B54F2 /* OWSIncomingMessageCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 450873C61D9D867B006B54F2 /* OWSIncomingMessageCollectionViewCell.m */; };
@ -526,6 +527,8 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
341BB7471DB727EE001E2975 /* JSQMediaItem+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSQMediaItem+OWS.h"; sourceTree = "<group>"; };
341BB7481DB727EE001E2975 /* JSQMediaItem+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSQMediaItem+OWS.m"; sourceTree = "<group>"; };
450873C11D9D5149006B54F2 /* OWSExpirationTimerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSExpirationTimerView.h; sourceTree = "<group>"; };
450873C21D9D5149006B54F2 /* OWSExpirationTimerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSExpirationTimerView.m; sourceTree = "<group>"; };
450873C51D9D867B006B54F2 /* OWSIncomingMessageCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSIncomingMessageCollectionViewCell.h; sourceTree = "<group>"; };
@ -1844,6 +1847,8 @@
B62D53F51A23CCAD009AAF82 /* TSMessageAdapter.h */,
B62D53F61A23CCAD009AAF82 /* TSMessageAdapter.m */,
B6D3CBCE1C1376BE00C039DF /* TSContentAdapters.h */,
341BB7471DB727EE001E2975 /* JSQMediaItem+OWS.h */,
341BB7481DB727EE001E2975 /* JSQMediaItem+OWS.m */,
4526BD481CA61C8D00166BC8 /* OWSMessageEditing.h */,
45666ECE1D995B94008FE134 /* OWSMessageData.h */,
);
@ -2869,6 +2874,7 @@
E197B60E18BBEC1A00F073E5 /* CallAudioManager.m in Sources */,
FCC81A981A44558300DFEC7D /* UIDevice+TSHardwareVersion.m in Sources */,
76EB054018170B33006006FC /* AppDelegate.m in Sources */,
341BB7491DB727EE001E2975 /* JSQMediaItem+OWS.m in Sources */,
76EB05D018170B33006006FC /* ZrtpHandshakeSocket.m in Sources */,
45F2B1941D9C9F48000D2C69 /* OWSOutgoingMessageCollectionViewCell.m in Sources */,
B63761EF19E1FBE8005735D1 /* HttpResponse.m in Sources */,

@ -0,0 +1,15 @@
//
// JSQMediaItem+OWS.h
// Signal
//
// Created by Matthew Douglass on 10/18/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
#import <JSQMessagesViewController/JSQMediaItem.h>
@interface JSQMediaItem (OWS)
- (CGSize)ows_adjustBubbleSize:(CGSize)bubbleSize forImage:(UIImage *)image;
@end

@ -0,0 +1,26 @@
//
// JSQMediaItem+OWS.m
// Signal
//
// Created by Matthew Douglass on 10/18/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
#import "JSQMediaItem+OWS.h"
#import "UIDevice+TSHardwareVersion.h"
#import "NumberUtil.h"
@implementation JSQMediaItem (OWS)
- (CGSize)ows_adjustBubbleSize:(CGSize)bubbleSize forImage:(UIImage *)image {
if ([[UIDevice currentDevice] isiPhoneVersionSixOrMore]) {
bubbleSize.width *= 1.1;
} else {
bubbleSize.width *= 0.7;
}
double aspectRatio = image.size.height / image.size.width;
bubbleSize.height = (CGFloat)(bubbleSize.width * [NumberUtil clamp:aspectRatio toMin:0.5 andMax:1.5]);
return bubbleSize;
}
@end

@ -9,7 +9,7 @@
#import "TSAnimatedAdapter.h"
#import "FLAnimatedImage.h"
#import "TSAttachmentStream.h"
#import "UIDevice+TSHardwareVersion.h"
#import "JSQMediaItem+OWS.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
#import <MobileCoreServices/MobileCoreServices.h>
@ -84,7 +84,7 @@
}
- (CGSize)mediaViewDisplaySize {
return [self getBubbleSizeForImage:self.image];
return [self ows_adjustBubbleSize:[super mediaViewDisplaySize] forImage:self.image];
}
- (BOOL)isImage {
@ -130,41 +130,4 @@
}
}
#pragma mark - Utility
- (CGSize)getBubbleSizeForImage:(UIImage *)image {
CGFloat aspectRatio = image.size.height / image.size.width;
if ([[UIDevice currentDevice] isiPhoneVersionSixOrMore]) {
return [self getLargeSizeForAspectRatio:aspectRatio];
} else {
return [self getSmallSizeForAspectRatio:aspectRatio];
}
}
- (CGSize)getLargeSizeForAspectRatio:(CGFloat)ratio {
return ratio > 1.0f ? [self largePortraitSize] : [self largeLandscapeSize];
}
- (CGSize)getSmallSizeForAspectRatio:(CGFloat)ratio {
return ratio > 1.0f ? [self smallPortraitSize] : [self smallLandscapeSize];
}
- (CGSize)largePortraitSize {
return CGSizeMake(220.0f, 310.0f);
}
- (CGSize)smallPortraitSize {
return CGSizeMake(150.0f, 210.0f);
}
- (CGSize)largeLandscapeSize {
return CGSizeMake(310.0f, 220.0f);
}
- (CGSize)smallLandscapeSize {
return CGSizeMake(210.0f, 150.0f);
}
@end

@ -3,7 +3,7 @@
#import "TSPhotoAdapter.h"
#import "TSAttachmentStream.h"
#import "UIDevice+TSHardwareVersion.h"
#import "JSQMediaItem+OWS.h"
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
@interface TSPhotoAdapter ()
@ -59,7 +59,7 @@
}
- (CGSize)mediaViewDisplaySize {
return [self getBubbleSizeForImage:self.image];
return [self ows_adjustBubbleSize:[super mediaViewDisplaySize] forImage:self.image];
}
- (BOOL)isImage {
@ -106,40 +106,4 @@
DDLogError(@"'%@' action unsupported for %@: attachmentId=%@", actionString, self.class, self.attachmentId);
}
#pragma mark - Utility
- (CGSize)getBubbleSizeForImage:(UIImage *)image {
CGFloat aspectRatio = image.size.height / image.size.width;
if ([[UIDevice currentDevice] isiPhoneVersionSixOrMore]) {
return [self getLargeSizeForAspectRatio:aspectRatio];
} else {
return [self getSmallSizeForAspectRatio:aspectRatio];
}
}
- (CGSize)getLargeSizeForAspectRatio:(CGFloat)ratio {
return ratio > 1.0f ? [self largePortraitSize] : [self largeLandscapeSize];
}
- (CGSize)getSmallSizeForAspectRatio:(CGFloat)ratio {
return ratio > 1.0f ? [self smallPortraitSize] : [self smallLandscapeSize];
}
- (CGSize)largePortraitSize {
return CGSizeMake(220.0f, 310.0f);
}
- (CGSize)smallPortraitSize {
return CGSizeMake(150.0f, 210.0f);
}
- (CGSize)largeLandscapeSize {
return CGSizeMake(310.0f, 220.0f);
}
- (CGSize)smallLandscapeSize {
return CGSizeMake(210.0f, 150.0f);
}
@end

@ -6,6 +6,7 @@
#import "TSAttachmentStream.h"
#import "TSMessagesManager.h"
#import "TSStorageManager+keyingMaterial.h"
#import "JSQMediaItem+OWS.h"
#import <FFCircularProgressView.h>
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
#import <MobileCoreServices/MobileCoreServices.h>
@ -200,6 +201,8 @@
CGSize size = [super mediaViewDisplaySize];
if ([self isAudio]) {
size.height = AUDIO_BAR_HEIGHT;
} else if ([self isVideo]) {
return [self ows_adjustBubbleSize:size forImage:self.image];
}
return size;
}

Loading…
Cancel
Save