mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Timeline decorations: Refactor reaction class names.
This commit is contained in:
parent
3516129b02
commit
2f61195e75
21 changed files with 159 additions and 165 deletions
|
@ -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;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
const CGFloat kTypingCellHeight = 24;
|
||||
|
||||
@interface RoomDataSource() <BubbleReactionsViewModelDelegate, URLPreviewViewDelegate, ThreadSummaryViewDelegate, MXThreadingServiceDelegate>
|
||||
@interface RoomDataSource() <RoomReactionsViewModelDelegate, URLPreviewViewDelegate, ThreadSummaryViewDelegate, MXThreadingServiceDelegate>
|
||||
{
|
||||
// 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 }];
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -68,7 +68,7 @@ class PlainRoomTimelineCellDecorator: RoomTimelineCellDecorator {
|
|||
])
|
||||
}
|
||||
|
||||
func addReactionView(_ reactionsView: BubbleReactionsView,
|
||||
func addReactionView(_ reactionsView: RoomReactionsView,
|
||||
toCell cell: MXKRoomBubbleTableViewCell,
|
||||
cellData: RoomBubbleCellData,
|
||||
contentViewPositionY: CGFloat,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
import UIKit
|
||||
import Reusable
|
||||
|
||||
final class BubbleReactionActionViewCell: UICollectionViewCell, NibReusable, Themable {
|
||||
final class RoomReactionActionViewCell: UICollectionViewCell, NibReusable, Themable {
|
||||
|
||||
// MARK: - Constants
|
||||
|
|
@ -1,18 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="BubbleReactionActionViewCell" customModule="Riot" customModuleProvider="target">
|
||||
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="RoomReactionActionViewCell" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="66" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
|
||||
|
@ -39,13 +37,13 @@
|
|||
</view>
|
||||
</subviews>
|
||||
</view>
|
||||
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
|
||||
<constraints>
|
||||
<constraint firstItem="jjn-uq-kYN" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" constant="1" id="E5H-9a-us9"/>
|
||||
<constraint firstAttribute="bottom" secondItem="jjn-uq-kYN" secondAttribute="bottom" constant="1" id="Ggm-1f-3EB"/>
|
||||
<constraint firstItem="jjn-uq-kYN" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" constant="1" id="iT6-rk-qd6"/>
|
||||
<constraint firstAttribute="trailing" secondItem="jjn-uq-kYN" secondAttribute="trailing" constant="1" id="ztM-7J-Dnf"/>
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
|
||||
<size key="customSize" width="443" height="170"/>
|
||||
<connections>
|
||||
<outlet property="actionLabel" destination="gyn-ux-gmi" id="qme-DX-UAc"/>
|
|
@ -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
|
|
@ -1,18 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="BubbleReactionViewCell" customModule="Riot" customModuleProvider="target">
|
||||
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="RoomReactionViewCell" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="36" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
|
||||
|
@ -53,13 +51,13 @@
|
|||
</view>
|
||||
</subviews>
|
||||
</view>
|
||||
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
|
||||
<constraints>
|
||||
<constraint firstItem="jjn-uq-kYN" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" constant="1" id="E5H-9a-us9"/>
|
||||
<constraint firstAttribute="bottom" secondItem="jjn-uq-kYN" secondAttribute="bottom" constant="1" id="Ggm-1f-3EB"/>
|
||||
<constraint firstItem="jjn-uq-kYN" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" constant="1" id="iT6-rk-qd6"/>
|
||||
<constraint firstAttribute="trailing" secondItem="jjn-uq-kYN" secondAttribute="trailing" constant="1" id="ztM-7J-Dnf"/>
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
|
||||
<size key="customSize" width="413" height="170"/>
|
||||
<connections>
|
||||
<outlet property="countLabel" destination="DQc-oh-Wus" id="GZt-aS-umB"/>
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
struct BubbleReactionViewData {
|
||||
struct RoomReactionViewData {
|
||||
let emoji: String
|
||||
let countString: String
|
||||
let isCurrentUserReacted: Bool
|
|
@ -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)
|
|
@ -1,15 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="BubbleReactionsView" customModule="Riot" customModuleProvider="target">
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="RoomReactionsView" customModule="Riot" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="collectionView" destination="uTe-bw-bWE" id="EGc-ca-YSM"/>
|
||||
</connections>
|
|
@ -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
|
|
@ -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)
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -17,15 +17,15 @@ limitations under the License.
|
|||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@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
|
|
@ -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 <MatrixSDK/MatrixSDK.h>
|
||||
|
||||
#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
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue