From fa1bbecf26d0edf6311ab8298ad2f85a10dabce0 Mon Sep 17 00:00:00 2001 From: Doug Date: Wed, 14 Jul 2021 10:15:50 +0100 Subject: [PATCH 1/2] Always update the path of the attachmentView's mask to handle reuse. --- CHANGES.rst | 1 + Riot/Modules/Room/DataSources/RoomDataSource.m | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index bc28f2c30..4f9ab91a1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,7 @@ Changes to be released in next version * Use different title for scan button for self verification (#4525). * it's easy for the back button to trigger a leftpanel reveal (#4438). * Show / hide reset button in secrets recovery screen (#4546). + * Timeline: Fix incorrect crop of media thumbnails. ⚠️ API Changes * diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index 230d313ce..6ab7ec1bf 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -1039,10 +1039,21 @@ const CGFloat kTypingCellHeight = 24; - (void)applyMaskToAttachmentViewOfBubbleCell:(MXKRoomBubbleTableViewCell *)cell { - if (cell.attachmentView && !cell.attachmentView.layer.mask) + if (cell.attachmentView) { UIBezierPath *myClippingPath = [UIBezierPath bezierPathWithRoundedRect:cell.attachmentView.bounds cornerRadius:6]; - CAShapeLayer *mask = [CAShapeLayer layer]; + CAShapeLayer *mask; + + // check for an existing mask in case the cell is being reused, otherwise create a new one + if ([cell.attachmentView.layer.mask isKindOfClass:[CAShapeLayer class]]) + { + mask = (CAShapeLayer*)cell.attachmentView.layer.mask; + } + else + { + mask = [CAShapeLayer layer]; + } + mask.path = myClippingPath.CGPath; cell.attachmentView.layer.mask = mask; } From 445db8ba78128f91436c9efc5ee44b62708559a3 Mon Sep 17 00:00:00 2001 From: Doug Date: Wed, 14 Jul 2021 10:37:54 +0100 Subject: [PATCH 2/2] Use the layer's corner radius rather than a custom mask. This will ensure the mask bounds always match the view's size. --- Riot/Modules/Room/DataSources/RoomDataSource.m | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index 6ab7ec1bf..434aee6ac 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -1041,21 +1041,8 @@ const CGFloat kTypingCellHeight = 24; { if (cell.attachmentView) { - UIBezierPath *myClippingPath = [UIBezierPath bezierPathWithRoundedRect:cell.attachmentView.bounds cornerRadius:6]; - CAShapeLayer *mask; - - // check for an existing mask in case the cell is being reused, otherwise create a new one - if ([cell.attachmentView.layer.mask isKindOfClass:[CAShapeLayer class]]) - { - mask = (CAShapeLayer*)cell.attachmentView.layer.mask; - } - else - { - mask = [CAShapeLayer layer]; - } - - mask.path = myClippingPath.CGPath; - cell.attachmentView.layer.mask = mask; + cell.attachmentView.layer.cornerRadius = 6; + cell.attachmentView.layer.masksToBounds = YES; } }