Skip to content

Commit f99dcec

Browse files
committed
Fix UI and update
1 parent 999cd8d commit f99dcec

File tree

12 files changed

+232
-151
lines changed

12 files changed

+232
-151
lines changed
+61-38
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import InlineKit
22
import UIKit
3+
34
class MessageReactionView: UIView {
45
// MARK: - Properties
5-
6+
67
private let emoji: String
78
private let count: Int
8-
private let isSelected: Bool
9+
private let byCurrentUser: Bool
910
private let outgoing: Bool
10-
11+
1112
var onTap: ((String) -> Void)?
12-
13+
1314
// MARK: - UI Components
14-
15+
1516
private lazy var containerView: UIView = {
1617
let view = UIView()
17-
view.layer.cornerRadius = 12
18+
UIView.performWithoutAnimation {
19+
view.layer.cornerRadius = 14
20+
}
1821
view.translatesAutoresizingMaskIntoConstraints = false
1922
return view
2023
}()
21-
24+
2225
private lazy var stackView: UIStackView = {
2326
let stack = UIStackView()
2427
stack.axis = .horizontal
@@ -27,89 +30,109 @@ class MessageReactionView: UIView {
2730
stack.translatesAutoresizingMaskIntoConstraints = false
2831
return stack
2932
}()
30-
33+
3134
private lazy var emojiLabel: UILabel = {
3235
let label = UILabel()
33-
label.font = UIFont.systemFont(ofSize: 16)
36+
label.font = UIFont.systemFont(ofSize: 17)
3437
label.text = emoji
3538
return label
3639
}()
37-
40+
3841
private lazy var countLabel: UILabel = {
3942
let label = UILabel()
4043
label.font = UIFont.systemFont(ofSize: 12, weight: .medium)
4144
label.text = "\(count)"
4245
return label
4346
}()
44-
47+
4548
// MARK: - Initialization
46-
47-
init(emoji: String, count: Int, isSelected: Bool, outgoing: Bool) {
49+
50+
init(emoji: String, count: Int, byCurrentUser: Bool, outgoing: Bool) {
4851
self.emoji = emoji
4952
self.count = count
50-
self.isSelected = isSelected
53+
self.byCurrentUser = byCurrentUser
5154
self.outgoing = outgoing
52-
55+
5356
super.init(frame: .zero)
5457
setupView()
5558
}
56-
59+
5760
@available(*, unavailable)
5861
required init?(coder: NSCoder) {
5962
fatalError("init(coder:) has not been implemented")
6063
}
61-
64+
6265
// MARK: - Setup
63-
66+
6467
private func setupView() {
6568
// Configure container appearance
66-
containerView.backgroundColor = isSelected ?
67-
(outgoing ? UIColor.white.withAlphaComponent(0.3) : ColorManager.shared.selectedColor.withAlphaComponent(0.3)) :
68-
(outgoing ? UIColor.white.withAlphaComponent(0.15) : UIColor.systemGray6)
69-
69+
containerView.backgroundColor = byCurrentUser ?
70+
(outgoing ? UIColor.reactionBackgroundOutgoingSelf : UIColor.reactionBackgroundIncomingSelf) :
71+
(outgoing ? UIColor.reactionBackgroundOutgoing : UIColor.reactionBackgroundIncoming)
72+
7073
// Configure text colors
71-
countLabel.textColor = outgoing ? .white.withAlphaComponent(0.9) : .darkGray
72-
74+
countLabel.textColor = outgoing ? .white : .label
75+
7376
// Add subviews
7477
addSubview(containerView)
7578
containerView.addSubview(stackView)
76-
79+
7780
stackView.addArrangedSubview(emojiLabel)
7881
stackView.addArrangedSubview(countLabel)
79-
82+
8083
// Setup constraints
8184
NSLayoutConstraint.activate([
8285
containerView.topAnchor.constraint(equalTo: topAnchor),
8386
containerView.leadingAnchor.constraint(equalTo: leadingAnchor),
8487
containerView.trailingAnchor.constraint(equalTo: trailingAnchor),
8588
containerView.bottomAnchor.constraint(equalTo: bottomAnchor),
86-
89+
8790
stackView.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 4),
88-
stackView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 8),
89-
stackView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -8),
90-
stackView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -4)
91+
stackView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 6),
92+
stackView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -6),
93+
stackView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -4),
9194
])
92-
95+
9396
// Add tap gesture
9497
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
9598
containerView.addGestureRecognizer(tapGesture)
9699
containerView.isUserInteractionEnabled = true
97100
}
98-
101+
99102
// MARK: - Actions
100-
103+
101104
@objc private func handleTap() {
102105
onTap?(emoji)
103106
}
104-
107+
105108
// MARK: - Layout
106-
109+
107110
override var intrinsicContentSize: CGSize {
108111
let stackSize = stackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
109-
return CGSize(width: stackSize.width + 16, height: stackSize.height + 8)
112+
return CGSize(width: stackSize.width + 5, height: stackSize.height + 8)
110113
}
111-
114+
112115
override func sizeThatFits(_ size: CGSize) -> CGSize {
113-
return intrinsicContentSize
116+
intrinsicContentSize
117+
}
118+
}
119+
120+
extension UIColor {
121+
/// Background color for reactions on outgoing messages by others
122+
static let reactionBackgroundOutgoing = UIColor(.white).withAlphaComponent(0.3)
123+
124+
/// Background color for reactions on outgoing messages by the current user
125+
static let reactionBackgroundOutgoingSelf = UIColor(.white).withAlphaComponent(0.4)
126+
127+
/// Background color for reactions on incoming messages by the current user
128+
static let reactionBackgroundIncomingSelf = UIColor { traitCollection in
129+
traitCollection.userInterfaceStyle == .dark ?
130+
UIColor(hex: "#4F4E52")! : UIColor(hex: "#DCDCDC")!
131+
}
132+
133+
/// Background color for reactions on incoming messages by others
134+
static let reactionBackgroundIncoming = UIColor { traitCollection in
135+
traitCollection.userInterfaceStyle == .dark ?
136+
UIColor(hex: "#414044")! : UIColor(hex: "#EBEBEB")!
114137
}
115138
}

apple/InlineIOS/Chat/MessageTimeAndStatus.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MessageTimeAndStatus: UIView {
1212

1313
private let dateLabel: UILabel = {
1414
let label = UILabel()
15-
label.font = .systemFont(ofSize: 11)
15+
label.font = .italicSystemFont(ofSize: 11)
1616
label.translatesAutoresizingMaskIntoConstraints = false
1717
return label
1818
}()

apple/InlineIOS/Chat/MessagesCollectionView.swift

+21-8
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,29 @@ class MessagesCollectionView: UICollectionView {
7373

7474
// Get upcoming messages (next 10-15 messages after visible ones)
7575
let lastVisibleIndex = indexPathsForVisibleItems.map { $0.item }.max() ?? 0
76-
let upcomingRange = (lastVisibleIndex + 1) ..< min(lastVisibleIndex + 15, coordinator.messages.count)
77-
let upcomingMessages = upcomingRange.map { coordinator.messages[$0] }
76+
let nextIndex = lastVisibleIndex + 1
7877

79-
// Combine visible and upcoming messages for prefetching
80-
let messagesToPrefetch = visibleMessages + upcomingMessages
78+
// Check if we have any upcoming messages to prefetch
79+
if nextIndex < coordinator.messages.count {
80+
let upcomingRange = nextIndex ..< min(lastVisibleIndex + 15, coordinator.messages.count)
81+
let upcomingMessages = upcomingRange.map { coordinator.messages[$0] }
8182

82-
// Only prefetch messages with photos
83-
let messagesWithPhotos = messagesToPrefetch.filter { $0.photoInfo != nil }
83+
// Combine visible and upcoming messages for prefetching
84+
let messagesToPrefetch = visibleMessages + upcomingMessages
8485

85-
if !messagesWithPhotos.isEmpty {
86-
ImagePrefetcher.shared.prefetchImages(for: messagesWithPhotos)
86+
// Only prefetch messages with photos
87+
let messagesWithPhotos = messagesToPrefetch.filter { $0.photoInfo != nil }
88+
89+
if !messagesWithPhotos.isEmpty {
90+
ImagePrefetcher.shared.prefetchImages(for: messagesWithPhotos)
91+
}
92+
} else {
93+
// No upcoming messages to prefetch, just handle visible ones
94+
let messagesWithPhotos = visibleMessages.filter { $0.photoInfo != nil }
95+
96+
if !messagesWithPhotos.isEmpty {
97+
ImagePrefetcher.shared.prefetchImages(for: messagesWithPhotos)
98+
}
8799
}
88100
}
89101

@@ -434,6 +446,7 @@ private extension MessagesCollectionView {
434446
case let .updated(newMessages, what, animated):
435447
var snapshot = dataSource.snapshot()
436448
let ids = newMessages.map(\.id)
449+
print("RECONFIGURING IDS \(ids)")
437450
snapshot.reconfigureItems(ids)
438451
dataSource.apply(snapshot, animatingDifferences: animated ?? false)
439452

apple/InlineIOS/Chat/ReactionsFlowView.swift

+35-29
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,109 @@
1+
import Auth
12
import InlineKit
23
import UIKit
4+
35
class ReactionsFlowView: UIView {
46
// MARK: - Properties
5-
7+
68
var horizontalSpacing: CGFloat = 4
79
var verticalSpacing: CGFloat = 4
810
private var outgoing: Bool = false
9-
11+
1012
private var containerStackView: UIStackView!
11-
13+
1214
var onReactionTap: ((String) -> Void)?
13-
15+
1416
// MARK: - Initialization
15-
17+
1618
init(outgoing: Bool) {
1719
self.outgoing = outgoing
1820
super.init(frame: .zero)
1921
setupView()
2022
}
21-
23+
2224
@available(*, unavailable)
2325
required init?(coder: NSCoder) {
2426
fatalError("init(coder:) has not been implemented")
2527
}
26-
28+
2729
private func setupView() {
2830
translatesAutoresizingMaskIntoConstraints = false
2931
backgroundColor = .clear
30-
32+
3133
containerStackView = UIStackView()
3234
containerStackView.axis = .vertical
3335
containerStackView.spacing = verticalSpacing
3436
containerStackView.alignment = .leading
3537
containerStackView.distribution = .fill
3638
containerStackView.translatesAutoresizingMaskIntoConstraints = false
37-
39+
3840
addSubview(containerStackView)
39-
41+
4042
NSLayoutConstraint.activate([
4143
containerStackView.topAnchor.constraint(equalTo: topAnchor),
4244
containerStackView.leadingAnchor.constraint(equalTo: leadingAnchor),
4345
containerStackView.trailingAnchor.constraint(equalTo: trailingAnchor),
44-
containerStackView.bottomAnchor.constraint(equalTo: bottomAnchor)
46+
containerStackView.bottomAnchor.constraint(equalTo: bottomAnchor),
4547
])
4648
}
47-
49+
4850
// MARK: - Public Methods
49-
50-
func configure(with reactions: [(emoji: String, count: Int, userIds: [Int64])], currentUserId: Int64?) {
51+
52+
func configure(with reactions: [(emoji: String, count: Int, userIds: [Int64])]) {
5153
// Clear existing content
5254
containerStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
53-
55+
5456
// Create reaction views
5557
let reactionViews = reactions.map { reaction -> MessageReactionView in
56-
let isSelected = currentUserId != nil && reaction.userIds.contains(currentUserId!)
58+
let byCurrentUser = reaction.userIds.contains(Auth.shared.getCurrentUserId() ?? 0)
5759
let view = MessageReactionView(
5860
emoji: reaction.emoji,
5961
count: reaction.count,
60-
isSelected: isSelected,
62+
byCurrentUser: byCurrentUser,
6163
outgoing: outgoing
6264
)
63-
65+
6466
view.onTap = { [weak self] emoji in
6567
self?.onReactionTap?(emoji)
6668
}
67-
69+
6870
return view
6971
}
70-
72+
print("REACTION VIEWS COUNT \(reactionViews.count)")
73+
7174
// Calculate sizes
72-
let sizes = reactionViews.map { $0.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)) }
73-
75+
let sizes = reactionViews.map { $0.sizeThatFits(CGSize(
76+
width: CGFloat.greatestFiniteMagnitude,
77+
height: CGFloat.greatestFiniteMagnitude
78+
)) }
79+
7480
// Organize into rows
7581
var currentRow = UIStackView()
7682
currentRow.axis = .horizontal
7783
currentRow.spacing = horizontalSpacing
7884
currentRow.alignment = .center
79-
85+
8086
var currentRowWidth: CGFloat = 0
8187
let maxWidth = UIScreen.main.bounds.width * 0.7 // Adjust as needed
82-
88+
8389
for (index, view) in reactionViews.enumerated() {
8490
let viewWidth = sizes[index].width
85-
86-
if currentRowWidth + viewWidth > maxWidth && currentRowWidth > 0 {
91+
92+
if currentRowWidth + viewWidth > maxWidth, currentRowWidth > 0 {
8793
// Add the current row and start a new one
8894
containerStackView.addArrangedSubview(currentRow)
89-
95+
9096
currentRow = UIStackView()
9197
currentRow.axis = .horizontal
9298
currentRow.spacing = horizontalSpacing
9399
currentRow.alignment = .center
94100
currentRowWidth = 0
95101
}
96-
102+
97103
currentRow.addArrangedSubview(view)
98104
currentRowWidth += viewWidth + horizontalSpacing
99105
}
100-
106+
101107
// Add the last row if it has any views
102108
if currentRow.arrangedSubviews.count > 0 {
103109
containerStackView.addArrangedSubview(currentRow)

apple/InlineIOS/Chat/UIMessageView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class UIMessageView: UIView {
285285
}
286286

287287
private func setupReactionsIfNeeded() {
288+
print("SETTING UP REACTIONS \(fullMessage.reactions.count)")
288289
guard !fullMessage.reactions.isEmpty else { return }
289290

290291
// Group reactions by emoji and track count, userIds, and the most recent date
@@ -312,8 +313,7 @@ class UIMessageView: UIView {
312313

313314
// Configure the flow view with the sorted reactions
314315
reactionsFlowView.configure(
315-
with: sortedReactions.map { (emoji: $0.emoji, count: $0.count, userIds: $0.userIds) },
316-
currentUserId: Auth.shared.getCurrentUserId()
316+
with: sortedReactions.map { (emoji: $0.emoji, count: $0.count, userIds: $0.userIds) }
317317
)
318318

319319
// Add to container and set constraints

0 commit comments

Comments
 (0)