Skip to content

Commit 2de1eb5

Browse files
committed
Improve bubbles color
1 parent e98df90 commit 2de1eb5

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

apple/InlineIOS/Chat/UIMessageView.swift

+26-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class UIMessageView: UIView {
9393
}
9494

9595
private var bubbleColor: UIColor {
96-
outgoing ? ColorManager.shared.selectedColor : UIColor.systemGray5.withAlphaComponent(0.5)
96+
outgoing ? ColorManager.shared.selectedColor : ColorManager.shared.secondaryColor
9797
}
9898

9999
private var textColor: UIColor {
@@ -114,7 +114,7 @@ class UIMessageView: UIView {
114114
}
115115

116116
guard let text = message.text else { return false }
117-
return text.count > 24 || text.contains("\n") || !fullMessage.reactions.isEmpty
117+
return text.count > 24 || text.contains("\n") || !fullMessage.reactions.isEmpty || text.containsEmoji
118118
}
119119

120120
private let labelVerticalPadding: CGFloat = 9.0
@@ -333,8 +333,11 @@ class UIMessageView: UIView {
333333
var items: [String] = []
334334
let nsString = message as NSString
335335

336-
regex.enumerateMatches(in: message, options: [], range: NSRange(location: 0, length: message.utf16.count)) { match, _, _ in
337-
guard let match = match, match.numberOfRanges > 1 else { return }
336+
regex.enumerateMatches(in: message, options: [], range: NSRange(
337+
location: 0,
338+
length: message.utf16.count
339+
)) { match, _, _ in
340+
guard let match, match.numberOfRanges > 1 else { return }
338341

339342
let contentRange = match.range(at: 1)
340343
if contentRange.location != NSNotFound {
@@ -553,3 +556,22 @@ extension NSLayoutConstraint {
553556
return self
554557
}
555558
}
559+
560+
extension Character {
561+
/// A simple emoji is one scalar and presented to the user as an Emoji
562+
var isSimpleEmoji: Bool {
563+
guard let firstScalar = unicodeScalars.first else { return false }
564+
return firstScalar.properties.isEmoji && firstScalar.value > 0x238C
565+
}
566+
567+
/// Checks if the scalars will be merged into an emoji
568+
var isCombinedIntoEmoji: Bool { unicodeScalars.count > 1 && unicodeScalars.first?.properties.isEmoji ?? false }
569+
570+
var isEmoji: Bool { isSimpleEmoji || isCombinedIntoEmoji }
571+
}
572+
573+
extension String {
574+
var containsEmoji: Bool {
575+
contains { $0.isEmoji }
576+
}
577+
}

apple/InlineIOS/UI/ColorManager.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,20 @@ class ColorManager {
7474
// Reset to default color
7575
func resetToDefault() {
7676
defaults.removeObject(forKey: colorKey)
77-
defaults.removeObject(forKey: secondaryColorKey)
7877
}
7978

8079
// Convert UIColor to Color for SwiftUI views
8180
var swiftUIColor: Color {
8281
Color(uiColor: selectedColor)
8382
}
83+
84+
var secondaryColor: UIColor {
85+
UIColor(dynamicProvider: { trait in
86+
if trait.userInterfaceStyle == .dark {
87+
UIColor(hex: "#27262B")!
88+
} else {
89+
UIColor(hex: "#F2F2F2")!
90+
}
91+
})
92+
}
8493
}

0 commit comments

Comments
 (0)