dark mode support

This commit is contained in:
Vlada Radchenko
2019-10-01 18:30:48 +03:00
parent b60a1a1067
commit db27093302
13 changed files with 113 additions and 19 deletions
+4
View File
@@ -53,6 +53,7 @@
50FF34572237FE6A0004DCD7 /* UIImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FF34562237FE6A0004DCD7 /* UIImage+Extension.swift */; };
50FF34592237FE850004DCD7 /* ContactMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FF34582237FE840004DCD7 /* ContactMessageCell.swift */; };
50FF345B2237FE9C0004DCD7 /* ContactMessageSizeCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50FF345A2237FE9C0004DCD7 /* ContactMessageSizeCalculator.swift */; };
797AD26423422BDB00E63579 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 797AD26323422BDB00E63579 /* UIColor.swift */; };
88916B2D1CF0DF2F00469F91 /* MessageKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88916B221CF0DF2F00469F91 /* MessageKit.framework */; };
8962AC8A1F87AB7D0030B058 /* MessagesCollectionViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC831F87AB230030B058 /* MessagesCollectionViewTests.swift */; };
8962AC8C1F87AB7D0030B058 /* AvatarViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8962AC851F87AB230030B058 /* AvatarViewTests.swift */; };
@@ -166,6 +167,7 @@
50FF34562237FE6A0004DCD7 /* UIImage+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Extension.swift"; sourceTree = "<group>"; };
50FF34582237FE840004DCD7 /* ContactMessageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactMessageCell.swift; sourceTree = "<group>"; };
50FF345A2237FE9C0004DCD7 /* ContactMessageSizeCalculator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactMessageSizeCalculator.swift; sourceTree = "<group>"; };
797AD26323422BDB00E63579 /* UIColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
88916B221CF0DF2F00469F91 /* MessageKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MessageKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
88916B2C1CF0DF2F00469F91 /* MessageKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MessageKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
8962AC741F87AB230030B058 /* MessageKitDateFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageKitDateFormatterTests.swift; sourceTree = "<group>"; };
@@ -406,6 +408,7 @@
B7A03F651F8669EB006AEF79 /* UIColor+Extensions.swift */,
B7A03F661F8669EB006AEF79 /* UIView+Extensions.swift */,
1FCA6D2F201C1CC900BC3480 /* UIEdgeInsets+Extensions.swift */,
797AD26323422BDB00E63579 /* UIColor.swift */,
);
path = Extensions;
sourceTree = "<group>";
@@ -643,6 +646,7 @@
38F8063321740D9E00CDB9DB /* BubbleCircle.swift in Sources */,
B7A03F5C1F8669CA006AEF79 /* MessageCellDelegate.swift in Sources */,
5073C11D2175BEC60040EAD5 /* AudioMessageSizeCalculator.swift in Sources */,
797AD26423422BDB00E63579 /* UIColor.swift in Sources */,
1FF377A420087C82004FD648 /* MessageKitError.swift in Sources */,
1F6C040E206A2AF4007BDE44 /* MessageReusableView.swift in Sources */,
388119462253EC30004B26AF /* TypingIndicatorCellSizeCalculator.swift in Sources */,
@@ -146,9 +146,10 @@ UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
private func setupDefaults() {
extendedLayoutIncludesOpaqueBars = true
automaticallyAdjustsScrollViewInsets = false
view.backgroundColor = .white
view.backgroundColor = .backgroundColor
messagesCollectionView.keyboardDismissMode = .interactive
messagesCollectionView.alwaysBounceVertical = true
messagesCollectionView.backgroundColor = .backgroundColor
}
private func setupDelegates() {
+35 -6
View File
@@ -26,14 +26,43 @@ import Foundation
internal extension UIColor {
static let incomingGray = UIColor(red: 230/255, green: 230/255, blue: 235/255, alpha: 1.0)
static var incomingGray: UIColor {
if #available(iOS 13, *) {
return UIColor.systemGray5
} else {
return UIColor(red: 230/255, green: 230/255, blue: 235/255, alpha: 1.0)
}
}
static let outgoingGreen = UIColor(red: 69/255, green: 214/255, blue: 93/255, alpha: 1.0)
static var outgoingGreen: UIColor {
if #available(iOS 13, *) {
return UIColor.systemGreen
} else {
return UIColor(red: 69/255, green: 214/255, blue: 93/255, alpha: 1.0)
}
}
static let inputBarGray = UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1.0)
static var inputBarGray: UIColor {
if #available(iOS 13, *) {
return UIColor.systemGray2
} else {
return UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1.0)
}
}
static let playButtonLightGray = UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1.0)
static let sendButtonBlue = UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
static var playButtonLightGray: UIColor {
if #available(iOS 13, *) {
return UIColor.systemGray6
} else {
return UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1.0)
}
}
static var sendButtonBlue: UIColor {
if #available(iOS 13, *) {
return UIColor.systemBlue
} else {
return UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
}
}
}
+60
View File
@@ -0,0 +1,60 @@
//
// UIColor.swift
// MessageKit
//
// Created by Vlada Radchenko on 9/30/19.
// Copyright © 2019 MessageKit. All rights reserved.
//
import Foundation
extension UIColor {
static var backgroundColor: UIColor {
if #available(iOS 13, *) {
return systemBackground
} else {
return white
}
}
static var labelColor: UIColor {
if #available(iOS 13, *) {
return label
} else {
return black
}
}
static var placeholderTextColor: UIColor {
if #available(iOS 13, *) {
return placeholderText
} else {
return .darkGray
}
}
static var grayColor: UIColor {
if #available(iOS 13, *) {
return .systemGray
} else {
return gray
}
}
static var darkTextColor: UIColor {
if #available(iOS 13, *) {
return .systemGray
} else {
return darkText
}
}
static var lightGrayColor: UIColor {
if #available(iOS 13, *) {
return .systemGray5
} else {
return .lightGray
}
}
}
@@ -229,7 +229,7 @@ public extension MessagesDisplayDelegate {
case .emoji:
return .clear
default:
guard let dataSource = messagesCollectionView.messagesDataSource else { return .white }
guard let dataSource = messagesCollectionView.messagesDataSource else { return .backgroundColor }
return dataSource.isFromCurrentSender(message: message) ? .outgoingGreen : .incomingGray
}
}
@@ -254,7 +254,7 @@ public extension MessagesDisplayDelegate {
guard let dataSource = messagesCollectionView.messagesDataSource else {
fatalError(MessageKitError.nilMessagesDataSource)
}
return dataSource.isFromCurrentSender(message: message) ? .white : .darkText
return dataSource.isFromCurrentSender(message: message) ? .backgroundColor : .labelColor
}
func enabledDetectors(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> [DetectorType] {
+1 -1
View File
@@ -161,7 +161,7 @@ open class AvatarView: UIImageView {
// MARK: - Internal methods
internal func prepareView() {
backgroundColor = .gray
backgroundColor = .grayColor
contentMode = .scaleAspectFill
layer.masksToBounds = true
clipsToBounds = true
+2 -2
View File
@@ -34,7 +34,7 @@ open class ContactMessageCell: MessageContentCell {
/// The view container that holds contact initials
public lazy var initialsContainerView: UIView = {
let initialsContainer = UIView(frame: CGRect.zero)
initialsContainer.backgroundColor = .white
initialsContainer.backgroundColor = .backgroundColor
return initialsContainer
}()
@@ -42,7 +42,7 @@ open class ContactMessageCell: MessageContentCell {
public lazy var initialsLabel: UILabel = {
let initialsLabel = UILabel(frame: CGRect.zero)
initialsLabel.textAlignment = .center
initialsLabel.textColor = .darkText
initialsLabel.textColor = .labelColor
initialsLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
return initialsLabel
}()
+2 -2
View File
@@ -126,9 +126,9 @@ open class MessageLabel: UILabel {
public static var defaultAttributes: [NSAttributedString.Key: Any] = {
return [
NSAttributedString.Key.foregroundColor: UIColor.darkText,
NSAttributedString.Key.foregroundColor: UIColor.darkTextColor,
NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue,
NSAttributedString.Key.underlineColor: UIColor.darkText
NSAttributedString.Key.underlineColor: UIColor.darkTextColor
]
}()
+1 -1
View File
@@ -57,7 +57,7 @@ open class MessagesCollectionView: UICollectionView {
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
backgroundColor = .white
backgroundColor = .backgroundColor
registerReusableViews()
setupGestureRecognizers()
}
+1 -1
View File
@@ -33,7 +33,7 @@ open class TypingIndicator: UIView {
public var bounceOffset: CGFloat = 2.5
/// A convenience accessor for the `backgroundColor` of each dot
open var dotColor: UIColor = UIColor.lightGray {
open var dotColor: UIColor = UIColor.lightGrayColor {
didSet {
dots.forEach { $0.backgroundColor = dotColor }
}
@@ -70,7 +70,7 @@ final class MessagesViewControllerSpec: QuickSpec {
expect(controller.extendedLayoutIncludesOpaqueBars).to(beTrue())
}
it("sets the background color to be white") {
expect(controller.view.backgroundColor).to(be(UIColor.white))
expect(controller.view.backgroundColor).to(be(UIColor.backgroundColor))
}
it("sets keyboardDismissMode to .interactive") {
let dismissMode = controller.messagesCollectionView.keyboardDismissMode
@@ -105,7 +105,7 @@ class MessagesViewControllerTests: XCTestCase {
func testCellForItemWithAttributedTextData_returnsTextMessageCell() {
let messagesDataSource = MockMessagesDataSource()
sut.messagesCollectionView.messagesDataSource = messagesDataSource
let attributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
let attributes = [NSAttributedString.Key.foregroundColor: UIColor.labelColor]
let attriutedString = NSAttributedString(string: "Test", attributes: attributes)
messagesDataSource.messages.append(MockMessage(attributedText: attriutedString,
user: messagesDataSource.senders[0],
@@ -44,7 +44,7 @@ class MessagesCollectionViewTests: XCTestCase {
func testInit() {
XCTAssertEqual(messagesCollectionView.frame, rect)
XCTAssertEqual(messagesCollectionView.collectionViewLayout, layout)
XCTAssertEqual(messagesCollectionView.backgroundColor, .white)
XCTAssertEqual(messagesCollectionView.backgroundColor, .backgroundColor)
}
}