diff --git a/Riot/Modules/Room/CellData/RoomBubbleCellData.m b/Riot/Modules/Room/CellData/RoomBubbleCellData.m index 7bca5c723..a1c8e02cc 100644 --- a/Riot/Modules/Room/CellData/RoomBubbleCellData.m +++ b/Riot/Modules/Room/CellData/RoomBubbleCellData.m @@ -21,7 +21,7 @@ #import "AvatarGenerator.h" #import "Tools.h" -#import "BubbleReactionsViewSizer.h" +#import "RoomReactionsViewSizer.h" #import "GeneratedInterface-Swift.h" @@ -754,18 +754,18 @@ NSString *const URLPreviewDidUpdateNotification = @"URLPreviewDidUpdateNotificat if (reactionCount) { - CGFloat bubbleReactionsViewWidth = self.maxTextViewWidth - 4; + CGFloat reactionsViewWidth = self.maxTextViewWidth - 4; - static BubbleReactionsViewSizer *bubbleReactionsViewSizer; + static RoomReactionsViewSizer *reactionsViewSizer; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - bubbleReactionsViewSizer = [BubbleReactionsViewSizer new]; + reactionsViewSizer = [RoomReactionsViewSizer new]; }); BOOL showAllReactions = [self.eventsToShowAllReactions containsObject:eventId]; - BubbleReactionsViewModel *viewModel = [[BubbleReactionsViewModel alloc] initWithAggregatedReactions:aggregatedReactions eventId:eventId showAll:showAllReactions]; - height = [bubbleReactionsViewSizer heightForViewModel:viewModel fittingWidth:bubbleReactionsViewWidth] + PlainRoomCellLayoutConstants.reactionsViewTopMargin; + RoomReactionsViewModel *viewModel = [[RoomReactionsViewModel alloc] initWithAggregatedReactions:aggregatedReactions eventId:eventId showAll:showAllReactions]; + height = [reactionsViewSizer heightForViewModel:viewModel fittingWidth:reactionsViewWidth] + PlainRoomCellLayoutConstants.reactionsViewTopMargin; } return height; diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index b24e57181..16276b1ff 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -29,7 +29,7 @@ const CGFloat kTypingCellHeight = 24; -@interface RoomDataSource() +@interface RoomDataSource() { // Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change. id kThemeServiceDidChangeThemeNotificationObserver; @@ -431,21 +431,21 @@ const CGFloat kTypingCellHeight = 24; MXAggregatedReactions* reactions = cellData.reactions[componentEventId].aggregatedReactionsWithNonZeroCount; - BubbleReactionsView *reactionsView; + RoomReactionsView *reactionsView; if (!component.event.isRedactedEvent && reactions && !isCollapsableCellCollapsed) { BOOL showAllReactions = [cellData showAllReactionsForEvent:componentEventId]; - BubbleReactionsViewModel *bubbleReactionsViewModel = [[BubbleReactionsViewModel alloc] initWithAggregatedReactions:reactions + RoomReactionsViewModel *roomReactionsViewModel = [[RoomReactionsViewModel alloc] initWithAggregatedReactions:reactions eventId:componentEventId showAll:showAllReactions]; - reactionsView = [BubbleReactionsView new]; - reactionsView.viewModel = bubbleReactionsViewModel; + reactionsView = [RoomReactionsView new]; + reactionsView.viewModel = roomReactionsViewModel; reactionsView.tag = index; [reactionsView updateWithTheme:ThemeService.shared.theme]; - bubbleReactionsViewModel.viewModelDelegate = self; + roomReactionsViewModel.viewModelDelegate = self; [temporaryViews addObject:reactionsView]; [cellDecorator addReactionView:reactionsView toCell:bubbleCell @@ -989,9 +989,9 @@ const CGFloat kTypingCellHeight = 24; } } -#pragma mark - BubbleReactionsViewModelDelegate +#pragma mark - RoomReactionsViewModelDelegate -- (void)bubbleReactionsViewModel:(BubbleReactionsViewModel *)viewModel didAddReaction:(MXReactionCount *)reactionCount forEventId:(NSString *)eventId +- (void)roomReactionsViewModel:(RoomReactionsViewModel *)viewModel didAddReaction:(MXReactionCount *)reactionCount forEventId:(NSString *)eventId { [self addReaction:reactionCount.reaction forEventId:eventId success:^{ @@ -1000,7 +1000,7 @@ const CGFloat kTypingCellHeight = 24; }]; } -- (void)bubbleReactionsViewModel:(BubbleReactionsViewModel *)viewModel didRemoveReaction:(MXReactionCount * _Nonnull)reactionCount forEventId:(NSString * _Nonnull)eventId +- (void)roomReactionsViewModel:(RoomReactionsViewModel *)viewModel didRemoveReaction:(MXReactionCount * _Nonnull)reactionCount forEventId:(NSString * _Nonnull)eventId { [self removeReaction:reactionCount.reaction forEventId:eventId success:^{ @@ -1009,12 +1009,12 @@ const CGFloat kTypingCellHeight = 24; }]; } -- (void)bubbleReactionsViewModel:(BubbleReactionsViewModel *)viewModel didShowAllTappedForEventId:(NSString * _Nonnull)eventId +- (void)roomReactionsViewModel:(RoomReactionsViewModel *)viewModel didShowAllTappedForEventId:(NSString * _Nonnull)eventId { [self setShowAllReactions:YES forEvent:eventId]; } -- (void)bubbleReactionsViewModel:(BubbleReactionsViewModel *)viewModel didShowLessTappedForEventId:(NSString * _Nonnull)eventId +- (void)roomReactionsViewModel:(RoomReactionsViewModel *)viewModel didShowLessTappedForEventId:(NSString * _Nonnull)eventId { [self setShowAllReactions:NO forEvent:eventId]; } @@ -1033,7 +1033,7 @@ const CGFloat kTypingCellHeight = 24; } } -- (void)bubbleReactionsViewModel:(BubbleReactionsViewModel *)viewModel didLongPressForEventId:(NSString *)eventId +- (void)roomReactionsViewModel:(RoomReactionsViewModel *)viewModel didLongPressForEventId:(NSString *)eventId { [self.delegate dataSource:self didRecognizeAction:kMXKRoomBubbleCellLongPressOnReactionView inCell:nil userInfo:@{ kMXKRoomBubbleCellEventIdKey: eventId }]; } diff --git a/Riot/Modules/Room/TimelineCells/BaseRoomCell/RoomCellContentView.swift b/Riot/Modules/Room/TimelineCells/BaseRoomCell/RoomCellContentView.swift index e8cc17639..4f8996725 100644 --- a/Riot/Modules/Room/TimelineCells/BaseRoomCell/RoomCellContentView.swift +++ b/Riot/Modules/Room/TimelineCells/BaseRoomCell/RoomCellContentView.swift @@ -212,9 +212,9 @@ extension RoomCellContentView: RoomCellReactionsDisplayable { self.reactionsContentView.vc_removeAllSubviews() // Update reactions alignment according to current decoration alignment - if let bubbleReactionsView = reactionsView as? BubbleReactionsView { + if let reactionsView = reactionsView as? RoomReactionsView { - let reactionsAlignment: BubbleReactionsViewAlignment + let reactionsAlignment: RoomReactionsViewAlignment switch self.decorationViewsAlignment { case .left: @@ -223,7 +223,7 @@ extension RoomCellContentView: RoomCellReactionsDisplayable { reactionsAlignment = .right } - bubbleReactionsView.alignment = reactionsAlignment + reactionsView.alignment = reactionsAlignment } self.reactionsContentView.vc_addSubViewMatchingParent(reactionsView) diff --git a/Riot/Modules/Room/TimelineCells/SizableCell/SizableBaseRoomCell.swift b/Riot/Modules/Room/TimelineCells/SizableCell/SizableBaseRoomCell.swift index 98eb9caa3..5aa5f10e5 100644 --- a/Riot/Modules/Room/TimelineCells/SizableCell/SizableBaseRoomCell.swift +++ b/Riot/Modules/Room/TimelineCells/SizableCell/SizableBaseRoomCell.swift @@ -29,10 +29,10 @@ class SizableBaseRoomCell: BaseRoomCell, SizableBaseRoomCellType { private static let sizingViewHeightStore = SizingViewHeightStore() private static var sizingViews: [String: SizableBaseRoomCell] = [:] - private static let sizingReactionsView = BubbleReactionsView() + private static let sizingReactionsView = RoomReactionsView() - private static let reactionsViewSizer = BubbleReactionsViewSizer() - private static let reactionsViewModelBuilder = BubbleReactionsViewModelBuilder() + private static let reactionsViewSizer = RoomReactionsViewSizer() + private static let reactionsViewModelBuilder = RoomReactionsViewModelBuilder() private static let urlPreviewViewSizer = URLPreviewViewSizer() @@ -126,11 +126,11 @@ class SizableBaseRoomCell: BaseRoomCell, SizableBaseRoomCellType { // Add reactions view height if needed if sizingView is RoomCellReactionsDisplayable, let roomBubbleCellData = cellData as? RoomBubbleCellData, - let bubbleReactionsViewModel = self.reactionsViewModelBuilder.buildForFirstVisibleComponent(of: roomBubbleCellData) { + let reactionsViewModel = self.reactionsViewModelBuilder.buildForFirstVisibleComponent(of: roomBubbleCellData) { let reactionWidth = sizingView.roomCellContentView?.reactionsContentView.frame.width ?? roomBubbleCellData.maxTextViewWidth - let reactionsHeight = self.reactionsViewSizer.height(for: bubbleReactionsViewModel, fittingWidth: reactionWidth) + let reactionsHeight = self.reactionsViewSizer.height(for: reactionsViewModel, fittingWidth: reactionWidth) height+=reactionsHeight } diff --git a/Riot/Modules/Room/TimelineCells/Styles/Bubble/BubbleRoomTimelineCellDecorator.swift b/Riot/Modules/Room/TimelineCells/Styles/Bubble/BubbleRoomTimelineCellDecorator.swift index d04932376..df25796d1 100644 --- a/Riot/Modules/Room/TimelineCells/Styles/Bubble/BubbleRoomTimelineCellDecorator.swift +++ b/Riot/Modules/Room/TimelineCells/Styles/Bubble/BubbleRoomTimelineCellDecorator.swift @@ -90,7 +90,7 @@ class BubbleRoomTimelineCellDecorator: PlainRoomTimelineCellDecorator { } } - override func addReactionView(_ reactionsView: BubbleReactionsView, + override func addReactionView(_ reactionsView: RoomReactionsView, toCell cell: MXKRoomBubbleTableViewCell, cellData: RoomBubbleCellData, contentViewPositionY: CGFloat, upperDecorationView: UIView?) { if let reactionsDisplayable = cell as? RoomCellReactionsDisplayable { diff --git a/Riot/Modules/Room/TimelineCells/Styles/Plain/PlainRoomTimelineCellDecorator.swift b/Riot/Modules/Room/TimelineCells/Styles/Plain/PlainRoomTimelineCellDecorator.swift index d081a24fa..0dd54623a 100644 --- a/Riot/Modules/Room/TimelineCells/Styles/Plain/PlainRoomTimelineCellDecorator.swift +++ b/Riot/Modules/Room/TimelineCells/Styles/Plain/PlainRoomTimelineCellDecorator.swift @@ -68,7 +68,7 @@ class PlainRoomTimelineCellDecorator: RoomTimelineCellDecorator { ]) } - func addReactionView(_ reactionsView: BubbleReactionsView, + func addReactionView(_ reactionsView: RoomReactionsView, toCell cell: MXKRoomBubbleTableViewCell, cellData: RoomBubbleCellData, contentViewPositionY: CGFloat, diff --git a/Riot/Modules/Room/TimelineCells/Styles/RoomTimelineCellDecorator.swift b/Riot/Modules/Room/TimelineCells/Styles/RoomTimelineCellDecorator.swift index 5e383dc94..fd488294c 100644 --- a/Riot/Modules/Room/TimelineCells/Styles/RoomTimelineCellDecorator.swift +++ b/Riot/Modules/Room/TimelineCells/Styles/RoomTimelineCellDecorator.swift @@ -30,7 +30,7 @@ protocol RoomTimelineCellDecorator { cellData: RoomBubbleCellData, contentViewPositionY: CGFloat) - func addReactionView(_ reactionsView: BubbleReactionsView, + func addReactionView(_ reactionsView: RoomReactionsView, toCell cell: MXKRoomBubbleTableViewCell, cellData: RoomBubbleCellData, contentViewPositionY: CGFloat, diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModelType.swift b/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModelType.swift deleted file mode 100644 index 77cab862e..000000000 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModelType.swift +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright 2019 New Vector Ltd - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -import Foundation - -enum BubbleReactionsViewAction { - case loadData - case tapReaction(index: Int) - case addNewReaction - case tapShowAction(action: ShowAction) - case longPress - - enum ShowAction { - case showAll - case showLess - } -} - -enum BubbleReactionsViewState { - case loaded(reactionsViewData: [BubbleReactionViewData], showAllButtonState: ShowAllButtonState) - - enum ShowAllButtonState { - case none - case showAll - case showLess - } -} - -@objc protocol BubbleReactionsViewModelDelegate: AnyObject { - func bubbleReactionsViewModel(_ viewModel: BubbleReactionsViewModel, didAddReaction reactionCount: MXReactionCount, forEventId eventId: String) - func bubbleReactionsViewModel(_ viewModel: BubbleReactionsViewModel, didRemoveReaction reactionCount: MXReactionCount, forEventId eventId: String) - func bubbleReactionsViewModel(_ viewModel: BubbleReactionsViewModel, didShowAllTappedForEventId eventId: String) - func bubbleReactionsViewModel(_ viewModel: BubbleReactionsViewModel, didShowLessTappedForEventId eventId: String) - func bubbleReactionsViewModel(_ viewModel: BubbleReactionsViewModel, didLongPressForEventId eventId: String) -} - -protocol BubbleReactionsViewModelViewDelegate: AnyObject { - func bubbleReactionsViewModel(_ viewModel: BubbleReactionsViewModel, didUpdateViewState viewState: BubbleReactionsViewState) -} - -protocol BubbleReactionsViewModelType { - var viewModelDelegate: BubbleReactionsViewModelDelegate? { get set } - var viewDelegate: BubbleReactionsViewModelViewDelegate? { get set } - - func process(viewAction: BubbleReactionsViewAction) -} diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionActionViewCell.swift b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionActionViewCell.swift similarity index 96% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionActionViewCell.swift rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionActionViewCell.swift index 27e387913..b8d12de13 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionActionViewCell.swift +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionActionViewCell.swift @@ -17,7 +17,7 @@ import UIKit import Reusable -final class BubbleReactionActionViewCell: UICollectionViewCell, NibReusable, Themable { +final class RoomReactionActionViewCell: UICollectionViewCell, NibReusable, Themable { // MARK: - Constants diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionActionViewCell.xib b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionActionViewCell.xib similarity index 91% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionActionViewCell.xib rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionActionViewCell.xib index fa3e5bdb7..806ba5586 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionActionViewCell.xib +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionActionViewCell.xib @@ -1,18 +1,16 @@ - - - - + + - + - + @@ -39,13 +37,13 @@ + - diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewCell.swift b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewCell.swift similarity index 96% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewCell.swift rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewCell.swift index da84b002b..7e509e923 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewCell.swift +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewCell.swift @@ -17,7 +17,7 @@ import UIKit import Reusable -final class BubbleReactionViewCell: UICollectionViewCell, NibReusable, Themable { +final class RoomReactionViewCell: UICollectionViewCell, NibReusable, Themable { // MARK: - Constants @@ -70,7 +70,7 @@ final class BubbleReactionViewCell: UICollectionViewCell, NibReusable, Themable // MARK: - Public - func fill(viewData: BubbleReactionViewData) { + func fill(viewData: RoomReactionViewData) { self.emojiLabel.text = viewData.emoji self.countLabel.text = viewData.countString self.isReactionSelected = viewData.isCurrentUserReacted diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewCell.xib b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewCell.xib similarity index 93% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewCell.xib rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewCell.xib index 17552af69..3b5fc34ec 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewCell.xib +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewCell.xib @@ -1,18 +1,16 @@ - - - - + + - + - + @@ -53,13 +51,13 @@ + - diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewData.swift b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewData.swift similarity index 95% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewData.swift rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewData.swift index 316f9c34b..e5f859254 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionViewData.swift +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionViewData.swift @@ -16,7 +16,7 @@ import Foundation -struct BubbleReactionViewData { +struct RoomReactionViewData { let emoji: String let countString: String let isCurrentUserReacted: Bool diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsView.swift b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsView.swift similarity index 80% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsView.swift rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsView.swift index 362f9b71c..3f926e29f 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsView.swift +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsView.swift @@ -21,14 +21,14 @@ import DGCollectionViewLeftAlignFlowLayout import UIKit import UICollectionViewRightAlignedLayout -/// BubbleReactionsView items alignment -enum BubbleReactionsViewAlignment { +/// RoomReactionsView items alignment +enum RoomReactionsViewAlignment { case left case right } @objcMembers -final class BubbleReactionsView: UIView, NibOwnerLoadable { +final class RoomReactionsView: UIView, NibOwnerLoadable { // MARK: - Constants @@ -45,21 +45,21 @@ final class BubbleReactionsView: UIView, NibOwnerLoadable { // MARK: Private - private var reactionsViewData: [BubbleReactionViewData] = [] - private var showAllButtonState: BubbleReactionsViewState.ShowAllButtonState = .none + private var reactionsViewData: [RoomReactionViewData] = [] + private var showAllButtonState: RoomReactionsViewState.ShowAllButtonState = .none private var theme: Theme? // MARK: Public - // Do not use `BubbleReactionsViewModelType` here due to Objective-C incompatibily - var viewModel: BubbleReactionsViewModel? { + // Do not use `RoomReactionsViewModelType` here due to Objective-C incompatibily + var viewModel: RoomReactionsViewModel? { didSet { self.viewModel?.viewDelegate = self self.viewModel?.process(viewAction: .loadData) } } - var alignment: BubbleReactionsViewAlignment = .left { + var alignment: RoomReactionsViewAlignment = .left { didSet { self.updateCollectionViewLayout(for: alignment) } @@ -103,12 +103,12 @@ final class BubbleReactionsView: UIView, NibOwnerLoadable { self.collectionView.dataSource = self self.alignment = .left - self.collectionView.register(cellType: BubbleReactionViewCell.self) - self.collectionView.register(cellType: BubbleReactionActionViewCell.self) + self.collectionView.register(cellType: RoomReactionViewCell.self) + self.collectionView.register(cellType: RoomReactionActionViewCell.self) self.collectionView.reloadData() } - private func updateCollectionViewLayout(for alignment: BubbleReactionsViewAlignment) { + private func updateCollectionViewLayout(for alignment: RoomReactionsViewAlignment) { let collectionViewLayout = self.collectionViewLayout(for: alignment) @@ -124,7 +124,7 @@ final class BubbleReactionsView: UIView, NibOwnerLoadable { self.collectionView.collectionViewLayout.invalidateLayout() } - private func collectionViewLayout(for alignment: BubbleReactionsViewAlignment) -> UICollectionViewLayout { + private func collectionViewLayout(for alignment: RoomReactionsViewAlignment) -> UICollectionViewLayout { let collectionViewLayout: UICollectionViewLayout @@ -151,7 +151,7 @@ final class BubbleReactionsView: UIView, NibOwnerLoadable { self.viewModel?.process(viewAction: .longPress) } - private func fill(reactionsViewData: [BubbleReactionViewData], showAllButtonState: BubbleReactionsViewState.ShowAllButtonState) { + private func fill(reactionsViewData: [RoomReactionViewData], showAllButtonState: RoomReactionsViewState.ShowAllButtonState) { self.reactionsViewData = reactionsViewData self.showAllButtonState = showAllButtonState self.collectionView.reloadData() @@ -174,7 +174,7 @@ final class BubbleReactionsView: UIView, NibOwnerLoadable { } // MARK: - UICollectionViewDataSource -extension BubbleReactionsView: UICollectionViewDataSource { +extension RoomReactionsView: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { // "Show all" or "Show less" is a cell in the same section as reactions cells @@ -185,7 +185,7 @@ extension BubbleReactionsView: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { if indexPath.row < self.reactionsViewData.count { - let cell: BubbleReactionViewCell = collectionView.dequeueReusableCell(for: indexPath) + let cell: RoomReactionViewCell = collectionView.dequeueReusableCell(for: indexPath) if let theme = self.theme { cell.update(theme: theme) @@ -196,7 +196,7 @@ extension BubbleReactionsView: UICollectionViewDataSource { return cell } else { - let cell: BubbleReactionActionViewCell = collectionView.dequeueReusableCell(for: indexPath) + let cell: RoomReactionActionViewCell = collectionView.dequeueReusableCell(for: indexPath) if let theme = self.theme { cell.update(theme: theme) @@ -211,7 +211,7 @@ extension BubbleReactionsView: UICollectionViewDataSource { } // MARK: - UICollectionViewDelegate -extension BubbleReactionsView: UICollectionViewDelegate { +extension RoomReactionsView: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { if indexPath.row < self.reactionsViewData.count { @@ -229,10 +229,10 @@ extension BubbleReactionsView: UICollectionViewDelegate { } } -// MARK: - BubbleReactionsViewModelViewDelegate -extension BubbleReactionsView: BubbleReactionsViewModelViewDelegate { +// MARK: - RoomReactionsViewModelViewDelegate +extension RoomReactionsView: RoomReactionsViewModelViewDelegate { - func bubbleReactionsViewModel(_ viewModel: BubbleReactionsViewModel, didUpdateViewState viewState: BubbleReactionsViewState) { + func roomReactionsViewModel(_ viewModel: RoomReactionsViewModel, didUpdateViewState viewState: RoomReactionsViewState) { switch viewState { case .loaded(reactionsViewData: let reactionsViewData, showAllButtonState: let showAllButtonState): self.fill(reactionsViewData: reactionsViewData, showAllButtonState: showAllButtonState) diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsView.xib b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsView.xib similarity index 88% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsView.xib rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsView.xib index 7c5cedb2a..f7ec783fb 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsView.xib +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsView.xib @@ -1,15 +1,13 @@ - - - - + + - + - + diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModel.swift b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModel.swift similarity index 66% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModel.swift rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModel.swift index 1c7418133..dec9db080 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModel.swift +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModel.swift @@ -16,7 +16,7 @@ import Foundation -@objc final class BubbleReactionsViewModel: NSObject, BubbleReactionsViewModelType { +@objc final class RoomReactionsViewModel: NSObject, RoomReactionsViewModelType { // MARK: - Constants @@ -34,8 +34,8 @@ import Foundation // MARK: Public - @objc weak var viewModelDelegate: BubbleReactionsViewModelDelegate? - weak var viewDelegate: BubbleReactionsViewModelViewDelegate? + @objc weak var viewModelDelegate: RoomReactionsViewModelDelegate? + weak var viewDelegate: RoomReactionsViewModelViewDelegate? // MARK: - Setup @@ -49,7 +49,7 @@ import Foundation // MARK: - Public - func process(viewAction: BubbleReactionsViewAction) { + func process(viewAction: RoomReactionsViewAction) { switch viewAction { case .loadData: self.loadData() @@ -59,24 +59,24 @@ import Foundation } let reactionCount = self.aggregatedReactions.reactions[index] if reactionCount.myUserHasReacted { - self.viewModelDelegate?.bubbleReactionsViewModel(self, didRemoveReaction: reactionCount, forEventId: self.eventId) + self.viewModelDelegate?.roomReactionsViewModel(self, didRemoveReaction: reactionCount, forEventId: self.eventId) } else { - self.viewModelDelegate?.bubbleReactionsViewModel(self, didAddReaction: reactionCount, forEventId: self.eventId) + self.viewModelDelegate?.roomReactionsViewModel(self, didAddReaction: reactionCount, forEventId: self.eventId) } case .addNewReaction: break case .tapShowAction(.showAll): - self.viewModelDelegate?.bubbleReactionsViewModel(self, didShowAllTappedForEventId: self.eventId) + self.viewModelDelegate?.roomReactionsViewModel(self, didShowAllTappedForEventId: self.eventId) case .tapShowAction(.showLess): - self.viewModelDelegate?.bubbleReactionsViewModel(self, didShowLessTappedForEventId: self.eventId) + self.viewModelDelegate?.roomReactionsViewModel(self, didShowLessTappedForEventId: self.eventId) case .longPress: - self.viewModelDelegate?.bubbleReactionsViewModel(self, didLongPressForEventId: self.eventId) + self.viewModelDelegate?.roomReactionsViewModel(self, didLongPressForEventId: self.eventId) } } func loadData() { var reactions = self.aggregatedReactions.reactions - var showAllButtonState: BubbleReactionsViewState.ShowAllButtonState = .none + var showAllButtonState: RoomReactionsViewState.ShowAllButtonState = .none // Limit displayed reactions if required if reactions.count > Constants.maxItemsWhenLimited { @@ -88,11 +88,11 @@ import Foundation } } - let reactionsViewData = reactions.map { (reactionCount) -> BubbleReactionViewData in - return BubbleReactionViewData(emoji: reactionCount.reaction, countString: "\(reactionCount.count)", isCurrentUserReacted: reactionCount.myUserHasReacted) + let reactionsViewData = reactions.map { (reactionCount) -> RoomReactionViewData in + return RoomReactionViewData(emoji: reactionCount.reaction, countString: "\(reactionCount.count)", isCurrentUserReacted: reactionCount.myUserHasReacted) } - self.viewDelegate?.bubbleReactionsViewModel(self, didUpdateViewState: .loaded(reactionsViewData: reactionsViewData, showAllButtonState: showAllButtonState)) + self.viewDelegate?.roomReactionsViewModel(self, didUpdateViewState: .loaded(reactionsViewData: reactionsViewData, showAllButtonState: showAllButtonState)) } // MARK: - Hashable diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModelBuilder.swift b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModelBuilder.swift similarity index 85% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModelBuilder.swift rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModelBuilder.swift index 46b244e06..ac48286fd 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewModelBuilder.swift +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModelBuilder.swift @@ -16,11 +16,11 @@ limitations under the License. import Foundation -/// `BubbleReactionsViewModelBuilder` enables to build a BubbleReactionsViewModel for a given `RoomBubbleCellData` and `MXKRoomBubbleComponent` index. +/// `RoomReactionsViewModelBuilder` enables to build a RoomReactionsViewModel for a given `RoomBubbleCellData` and `MXKRoomBubbleComponent` index. @objcMembers -final class BubbleReactionsViewModelBuilder: NSObject { +final class RoomReactionsViewModelBuilder: NSObject { - func buildForFirstVisibleComponent(of roomBubbleCellData: RoomBubbleCellData) -> BubbleReactionsViewModel? { + func buildForFirstVisibleComponent(of roomBubbleCellData: RoomBubbleCellData) -> RoomReactionsViewModel? { guard roomBubbleCellData.firstVisibleComponentIndex() != NSNotFound else { return nil @@ -29,7 +29,7 @@ final class BubbleReactionsViewModelBuilder: NSObject { return self.build(from: roomBubbleCellData, componentIndex: roomBubbleCellData.firstVisibleComponentIndex()) } - func build(from roomBubbleCellData: RoomBubbleCellData, componentIndex: Int) -> BubbleReactionsViewModel? { + func build(from roomBubbleCellData: RoomBubbleCellData, componentIndex: Int) -> RoomReactionsViewModel? { let isCollapsableCellCollapsed = roomBubbleCellData.collapsable && roomBubbleCellData.collapsed @@ -53,7 +53,7 @@ final class BubbleReactionsViewModelBuilder: NSObject { } let showAllReactions = roomBubbleCellData.showAllReactions(forEvent: componentEventId) - return BubbleReactionsViewModel(aggregatedReactions: aggregatedReactions, + return RoomReactionsViewModel(aggregatedReactions: aggregatedReactions, eventId: componentEventId, showAll: showAllReactions) } diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModelType.swift b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModelType.swift new file mode 100644 index 000000000..441ce3eb0 --- /dev/null +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewModelType.swift @@ -0,0 +1,59 @@ +/* + Copyright 2019 New Vector Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +import Foundation + +enum RoomReactionsViewAction { + case loadData + case tapReaction(index: Int) + case addNewReaction + case tapShowAction(action: ShowAction) + case longPress + + enum ShowAction { + case showAll + case showLess + } +} + +enum RoomReactionsViewState { + case loaded(reactionsViewData: [RoomReactionViewData], showAllButtonState: ShowAllButtonState) + + enum ShowAllButtonState { + case none + case showAll + case showLess + } +} + +@objc protocol RoomReactionsViewModelDelegate: AnyObject { + func roomReactionsViewModel(_ viewModel: RoomReactionsViewModel, didAddReaction reactionCount: MXReactionCount, forEventId eventId: String) + func roomReactionsViewModel(_ viewModel: RoomReactionsViewModel, didRemoveReaction reactionCount: MXReactionCount, forEventId eventId: String) + func roomReactionsViewModel(_ viewModel: RoomReactionsViewModel, didShowAllTappedForEventId eventId: String) + func roomReactionsViewModel(_ viewModel: RoomReactionsViewModel, didShowLessTappedForEventId eventId: String) + func roomReactionsViewModel(_ viewModel: RoomReactionsViewModel, didLongPressForEventId eventId: String) +} + +protocol RoomReactionsViewModelViewDelegate: AnyObject { + func roomReactionsViewModel(_ viewModel: RoomReactionsViewModel, didUpdateViewState viewState: RoomReactionsViewState) +} + +protocol RoomReactionsViewModelType { + var viewModelDelegate: RoomReactionsViewModelDelegate? { get set } + var viewDelegate: RoomReactionsViewModelViewDelegate? { get set } + + func process(viewAction: RoomReactionsViewAction) +} diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewSizer.h b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewSizer.h similarity index 77% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewSizer.h rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewSizer.h index 5234e4ba2..677feda90 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewSizer.h +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewSizer.h @@ -17,15 +17,15 @@ limitations under the License. #import #import -@class BubbleReactionsViewModel; +@class RoomReactionsViewModel; NS_ASSUME_NONNULL_BEGIN -// `BubbleReactionsViewSizer` allows to determine reactions view height for a given viewModel and width. -@interface BubbleReactionsViewSizer : NSObject +// `RoomReactionsViewSizer` allows to determine reactions view height for a given viewModel and width. +@interface RoomReactionsViewSizer : NSObject // Use Objective-C as workaround as there is an issue affecting UICollectionView sizing. See https://developer.apple.com/forums/thread/105523 for more information. -- (CGFloat)heightForViewModel:(BubbleReactionsViewModel*)viewModel +- (CGFloat)heightForViewModel:(RoomReactionsViewModel*)viewModel fittingWidth:(CGFloat)fittingWidth; @end diff --git a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewSizer.m b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewSizer.m similarity index 58% rename from Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewSizer.m rename to Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewSizer.m index a2c40fd6d..8cb2ad3e0 100644 --- a/Riot/Modules/Room/TimelineDecorations/Reactions/BubbleReactionsViewSizer.m +++ b/Riot/Modules/Room/TimelineDecorations/Reactions/RoomReactionsViewSizer.m @@ -14,33 +14,33 @@ See the License for the specific language governing permissions and limitations under the License. */ -#import "BubbleReactionsViewSizer.h" +#import "RoomReactionsViewSizer.h" #import #import "GeneratedInterface-Swift.h" -@implementation BubbleReactionsViewSizer +@implementation RoomReactionsViewSizer -- (CGFloat)heightForViewModel:(BubbleReactionsViewModel*)viewModel +- (CGFloat)heightForViewModel:(RoomReactionsViewModel*)viewModel fittingWidth:(CGFloat)fittingWidth { CGSize fittingSize = UILayoutFittingCompressedSize; fittingSize.width = fittingWidth; - static BubbleReactionsView *bubbleReactionsView; + static RoomReactionsView *reactionsView; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - bubbleReactionsView = [BubbleReactionsView new]; + reactionsView = [RoomReactionsView new]; }); - bubbleReactionsView.frame = CGRectMake(0, 0, fittingWidth, 1.0); - bubbleReactionsView.viewModel = viewModel; - [bubbleReactionsView setNeedsLayout]; - [bubbleReactionsView layoutIfNeeded]; + reactionsView.frame = CGRectMake(0, 0, fittingWidth, 1.0); + reactionsView.viewModel = viewModel; + [reactionsView setNeedsLayout]; + [reactionsView layoutIfNeeded]; - return [bubbleReactionsView systemLayoutSizeFittingSize:fittingSize withHorizontalFittingPriority:UILayoutPriorityRequired verticalFittingPriority:UILayoutPriorityFittingSizeLevel].height; + return [reactionsView systemLayoutSizeFittingSize:fittingSize withHorizontalFittingPriority:UILayoutPriorityRequired verticalFittingPriority:UILayoutPriorityFittingSizeLevel].height; } @end diff --git a/Riot/SupportingFiles/Riot-Bridging-Header.h b/Riot/SupportingFiles/Riot-Bridging-Header.h index 4b517a310..6530d005d 100644 --- a/Riot/SupportingFiles/Riot-Bridging-Header.h +++ b/Riot/SupportingFiles/Riot-Bridging-Header.h @@ -18,7 +18,7 @@ #import "RoomBubbleCellData.h" #import "MXKRoomBubbleTableViewCell+Riot.h" #import "UserEncryptionTrustLevel.h" -#import "BubbleReactionsViewSizer.h" +#import "RoomReactionsViewSizer.h" #import "RoomEncryptedDataBubbleCell.h" #import "LegacyAppDelegate.h" #import "DirectoryServerPickerViewController.h"