display images in the conversation page: improve performance and bug fix
- the app is now fluid when scrolling a conversation with images
- fix app bug that didn't display correctly images
Change-Id: I80f679b42f242f192e9d9454afb54f7602b872ad
diff --git a/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCell.swift b/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCell.swift
index 5800aba..315a7c6 100644
--- a/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCell.swift
+++ b/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCell.swift
@@ -389,7 +389,7 @@
if let image = message.getTransferedImage(maxSize: maxDimsion, conversationID: conversationID) {
self.transferImageView.image = image
let newSize = self.transferImageView.image?.getNewSize(of: defaultSize)
- let xOriginImageSend = self.bubble.bounds.size.width - (newSize?.width)!
+ let xOriginImageSend = screenWidth - 112 - (newSize?.width)!
if message.bubblePosition() == .sent {
self.transferImageView.frame = CGRect(x: xOriginImageSend, y: 0, width: ((newSize?.width ?? 200)), height: ((newSize?.height ?? 200)))
} else if message.bubblePosition() == .received {
diff --git a/Ring/Ring/Services/DataTransferService.swift b/Ring/Ring/Services/DataTransferService.swift
index 0123f99..b85ec1a 100644
--- a/Ring/Ring/Services/DataTransferService.swift
+++ b/Ring/Ring/Services/DataTransferService.swift
@@ -178,7 +178,8 @@
guard let asset = PHAsset.fetchAssets(withLocalIdentifiers: [identifier], options: PHFetchOptions()).firstObject else {
return photo
}
- imageManager.requestImage(for: asset, targetSize: CGSize(width: maxSize, height: maxSize * 2), contentMode: .aspectFit, options: requestOptions, resultHandler: {(result, _) -> Void in
+ imageManager.requestImage(for: asset, targetSize: CGSize(width: maxSize, height: maxSize), contentMode: .aspectFit, options: requestOptions, resultHandler: {(result, _) -> Void in
+ self.transferedImages[identifier] = (true, result!)
photo = result!
})
return photo
@@ -201,10 +202,10 @@
if fileExtension as String == "gif" {
let image = UIImage.gifImageWithUrl(pathUrl)
return image
- } else {
- let image = UIImage(contentsOfFile: pathUrl.path)
- return image
}
+ let image = UIImage(contentsOfFile: pathUrl.path)
+ self.transferedImages[conversationID + name] = (true, image)
+ return image
}
} else {
self.transferedImages[conversationID + name] = (false, nil)