Skip to content

Commit

Permalink
Merge pull request #142 from nathantannar4/iOS-13--fix-iOS-13-semanti…
Browse files Browse the repository at this point in the history
…c-colors-in-Example

Fix iOS 13+ dark mode for example app
  • Loading branch information
Kaspik authored Aug 27, 2020
2 parents ae0402a + 99925bb commit 4c2d1e4
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 36 deletions.
26 changes: 20 additions & 6 deletions Example/Example/CommonTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ class CommonTableViewController: UIViewController, UITableViewDataSource, UITabl
let tableView = UITableView()

let conversation: SampleData.Conversation


private let mentionTextAttributes: [NSAttributedString.Key : Any] = [
.font: UIFont.preferredFont(forTextStyle: .body),
.foregroundColor: UIColor.systemBlue,
.backgroundColor: UIColor.systemBlue.withAlphaComponent(0.1)
]

/// The object that manages attachments
open lazy var attachmentManager: AttachmentManager = { [unowned self] in
let manager = AttachmentManager()
Expand Down Expand Up @@ -56,12 +62,16 @@ class CommonTableViewController: UIViewController, UITableViewDataSource, UITabl
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .white
if #available(iOS 13, *) {
view.backgroundColor = .systemBackground
} else {
view.backgroundColor = .white
}
view.addSubview(tableView)
tableView.delegate = self
tableView.dataSource = self
tableView.keyboardDismissMode = .interactive
tableView.register(ConversationCell.self, forCellReuseIdentifier: "cell")
tableView.register(ConversationCell.self, forCellReuseIdentifier: "\(ConversationCell.self)")
tableView.tableFooterView = UIView()
tableView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
Expand All @@ -75,7 +85,7 @@ class CommonTableViewController: UIViewController, UITableViewDataSource, UITabl
inputBar.inputTextView.keyboardType = .twitter

// Configure AutocompleteManager
autocompleteManager.register(prefix: "@", with: [.font: UIFont.preferredFont(forTextStyle: .body),.foregroundColor: UIColor(red: 0, green: 122/255, blue: 1, alpha: 1),.backgroundColor: UIColor(red: 0, green: 122/255, blue: 1, alpha: 0.1)])
autocompleteManager.register(prefix: "@", with: mentionTextAttributes)
autocompleteManager.register(prefix: "#")
autocompleteManager.maxSpaceCountDuringCompletion = 1 // Allow for autocompletes with a space

Expand All @@ -93,14 +103,18 @@ class CommonTableViewController: UIViewController, UITableViewDataSource, UITabl
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: "\(ConversationCell.self)", for: indexPath)
cell.imageView?.image = conversation.messages[indexPath.row].user.image
cell.imageView?.layer.cornerRadius = 5
cell.imageView?.clipsToBounds = true
cell.textLabel?.text = conversation.messages[indexPath.row].user.name
cell.textLabel?.font = .boldSystemFont(ofSize: 15)
cell.textLabel?.numberOfLines = 0
cell.detailTextLabel?.textColor = .darkGray
if #available(iOS 13, *) {
cell.detailTextLabel?.textColor = .secondaryLabel
} else {
cell.detailTextLabel?.textColor = .darkGray
}
cell.detailTextLabel?.font = .systemFont(ofSize: 14)
cell.detailTextLabel?.text = conversation.messages[indexPath.row].text
cell.detailTextLabel?.numberOfLines = 0
Expand Down
12 changes: 7 additions & 5 deletions Example/Example/InputBarExamples/FacebookInputBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit
import InputBarAccessoryView

class FacebookInputBar: InputBarAccessoryView {
final class FacebookInputBar: InputBarAccessoryView {

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -32,12 +32,14 @@ class FacebookInputBar: InputBarAccessoryView {
button.setSize(CGSize(width: 36, height: 36), animated: false)
button.setImage(#imageLiteral(resourceName: "ic_plus").withRenderingMode(.alwaysTemplate), for: .normal)
button.imageView?.contentMode = .scaleAspectFit
button.tintColor = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1)
inputTextView.backgroundColor = UIColor(red: 245/255, green: 245/255, blue: 245/255, alpha: 1)
inputTextView.placeholderTextColor = UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 1)
button.tintColor = .systemBlue
inputTextView.textContainerInset = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16)
inputTextView.placeholderLabelInsets = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20)
inputTextView.layer.borderColor = UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 1).cgColor
if #available(iOS 13, *) {
inputTextView.layer.borderColor = UIColor.systemGray2.cgColor
} else {
inputTextView.layer.borderColor = UIColor.lightGray.cgColor
}
inputTextView.layer.borderWidth = 1.0
inputTextView.layer.cornerRadius = 16.0
inputTextView.layer.masksToBounds = true
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/InputBarExamples/GitHawkInputBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit
import InputBarAccessoryView

class GitHawkInputBar: InputBarAccessoryView {
final class GitHawkInputBar: InputBarAccessoryView {

private let githawkImages: [UIImage] = [#imageLiteral(resourceName: "ic_eye"), #imageLiteral(resourceName: "ic_bold"), #imageLiteral(resourceName: "ic_italic"), #imageLiteral(resourceName: "ic_at"), #imageLiteral(resourceName: "ic_list"), #imageLiteral(resourceName: "ic_code"), #imageLiteral(resourceName: "ic_link"), #imageLiteral(resourceName: "ic_hashtag"), #imageLiteral(resourceName: "ic_upload")]

Expand Down
4 changes: 2 additions & 2 deletions Example/Example/InputBarExamples/NoTextViewInputBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import UIKit
import InputBarAccessoryView

class NoTextViewInputBar: InputBarAccessoryView {
final class NoTextViewInputBar: InputBarAccessoryView {

let joinButton: UIButton = {
let button = UIButton()
button.setTitle("Join Chat", for: .normal)
button.setTitleColor(.white, for: .normal)
button.layer.cornerRadius = 10
button.backgroundColor = UIColor(red: 0/255, green: 122/255, blue: 1, alpha: 1)
button.backgroundColor = .systemBlue
return button
}()

Expand Down
16 changes: 8 additions & 8 deletions Example/Example/InputBarExamples/SlackInputBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit
import InputBarAccessoryView

class SlackInputBar: InputBarAccessoryView {
final class SlackInputBar: InputBarAccessoryView {

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -25,20 +25,20 @@ class SlackInputBar: InputBarAccessoryView {
makeButton(named: "ic_camera").onTextViewDidChange { button, textView in
button.isEnabled = textView.text.isEmpty
}.onSelected {
$0.tintColor = UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
$0.tintColor = .systemBlue
},
makeButton(named: "ic_at").onSelected {
self.inputPlugins.forEach { _ = $0.handleInput(of: "@" as AnyObject) }
$0.tintColor = UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
$0.tintColor = .systemBlue
},
makeButton(named: "ic_hashtag").onSelected {
self.inputPlugins.forEach { _ = $0.handleInput(of: "#" as AnyObject) }
$0.tintColor = UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
$0.tintColor = .systemBlue
},
.flexibleSpace,
makeButton(named: "ic_library")
.onSelected {
$0.tintColor = UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
$0.tintColor = .systemBlue
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .photoLibrary
Expand All @@ -54,9 +54,9 @@ class SlackInputBar: InputBarAccessoryView {
$0.setSize(CGSize(width: 52, height: 30), animated: false)
}.onDisabled {
$0.layer.borderColor = $0.titleColor(for: .disabled)?.cgColor
$0.backgroundColor = .white
$0.backgroundColor = .clear
}.onEnabled {
$0.backgroundColor = UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
$0.backgroundColor = .systemBlue
$0.layer.borderColor = UIColor.clear.cgColor
}.onSelected {
// We use a transform becuase changing the size would cause the other views to relayout
Expand Down Expand Up @@ -100,7 +100,7 @@ class SlackInputBar: InputBarAccessoryView {
$0.image = UIImage(named: named)?.withRenderingMode(.alwaysTemplate)
$0.setSize(CGSize(width: 30, height: 30), animated: false)
}.onSelected {
$0.tintColor = UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
$0.tintColor = .systemBlue
}.onDeselected {
$0.tintColor = UIColor.lightGray
}.onTouchUpInside { _ in
Expand Down
10 changes: 6 additions & 4 deletions Example/Example/InputBarExamples/iMessageInputBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit
import InputBarAccessoryView

class iMessageInputBar: InputBarAccessoryView {
final class iMessageInputBar: InputBarAccessoryView {

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -21,11 +21,13 @@ class iMessageInputBar: InputBarAccessoryView {
}

func configure() {
inputTextView.backgroundColor = UIColor(red: 250/255, green: 250/255, blue: 250/255, alpha: 1)
inputTextView.placeholderTextColor = UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 1)
inputTextView.textContainerInset = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 36)
inputTextView.placeholderLabelInsets = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 36)
inputTextView.layer.borderColor = UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 1).cgColor
if #available(iOS 13, *) {
inputTextView.layer.borderColor = UIColor.systemGray2.cgColor
} else {
inputTextView.layer.borderColor = UIColor.lightGray.cgColor
}
inputTextView.layer.borderWidth = 1.0
inputTextView.layer.cornerRadius = 16.0
inputTextView.layer.masksToBounds = true
Expand Down
11 changes: 8 additions & 3 deletions Example/Example/InputBarStyleSelectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ class InputBarStyleSelectionController: UITableViewController {
tableView.tableFooterView = UIView()
title = "InputBarAccessoryView"
navigationItem.backBarButtonItem = UIBarButtonItem(title: "Styles", style: .plain, target: nil, action: nil)
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.barTintColor = UIColor(red: 0/255, green: 122/255, blue: 1, alpha: 1)
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
if #available(iOS 13, *) {
navigationController?.navigationBar.tintColor = .systemBackground
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.systemBackground]
} else {
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
navigationController?.navigationBar.barTintColor = .systemBlue
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
Expand Down
6 changes: 3 additions & 3 deletions Example/Example/READMEPreviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ final class READMEPreviewViewController: InputBarViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1)
view.backgroundColor = .systemBlue
inputBar.inputTextView.autocorrectionType = .no
inputBar.inputTextView.autocapitalizationType = .none
inputBar.inputTextView.keyboardType = .twitter
let size = UIFont.preferredFont(forTextStyle: .body).pointSize
autocompleteManager.register(prefix: "@", with: [.font: UIFont.preferredFont(forTextStyle: .body),.foregroundColor: UIColor(red: 0, green: 122/255, blue: 1, alpha: 1),.backgroundColor: UIColor(red: 0, green: 122/255, blue: 1, alpha: 0.1)])
autocompleteManager.register(prefix: "@", with: [.font: UIFont.preferredFont(forTextStyle: .body),.foregroundColor: UIColor.systemBlue,.backgroundColor: UIColor.systemBlue.withAlphaComponent(0.1)])
autocompleteManager.register(prefix: "#", with: [.font: UIFont.boldSystemFont(ofSize: size)])
inputBar.inputPlugins = [autocompleteManager]
}
Expand Down Expand Up @@ -83,7 +83,7 @@ extension READMEPreviewViewController: AutocompleteManagerDelegate, Autocomplete
cell.imageViewEdgeInsets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4)
cell.imageView?.layer.cornerRadius = 8
cell.imageView?.layer.borderWidth = 1
cell.imageView?.layer.borderColor = UIColor(red: 0, green: 122/255, blue: 1, alpha: 1).cgColor
cell.imageView?.layer.borderColor = UIColor.systemBlue.cgColor
cell.imageView?.layer.masksToBounds = true
}
cell.textLabel?.attributedText = manager.attributedText(matching: session, fontSize: 15, keepPrefix: session.prefix == "#" )
Expand Down
36 changes: 36 additions & 0 deletions InputBarAccessoryView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
38F0C1FB20C8971500FF8DD3 /* InputBarAccessoryView+Availability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38F0C1FA20C8971500FF8DD3 /* InputBarAccessoryView+Availability.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
51E04F4224F7DCD0004D7452 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 51E04F3E24F7DCD0004D7452 /* Example.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 383B83991F47897800027965;
remoteInfo = Example;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
381042221F85FD1300B1E61A /* SeparatorLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorLine.swift; sourceTree = "<group>"; };
381042241F87F34900B1E61A /* InputStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputStackView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -83,6 +93,7 @@
38F0C1F120C7807D00FF8DD3 /* AutocompleteSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutocompleteSession.swift; sourceTree = "<group>"; };
38F0C1F320C7808F00FF8DD3 /* AutocompleteCompletion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutocompleteCompletion.swift; sourceTree = "<group>"; };
38F0C1FA20C8971500FF8DD3 /* InputBarAccessoryView+Availability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "InputBarAccessoryView+Availability.swift"; sourceTree = "<group>"; };
51E04F3E24F7DCD0004D7452 /* Example.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Example.xcodeproj; path = Example/Example.xcodeproj; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -112,6 +123,7 @@
38447E1C22A31BE70002649D /* RxInputBarAccessoryView */,
38C867701F50A6AD00811974 /* Sources */,
383B83841F4787E200027965 /* Products */,
51E04F3E24F7DCD0004D7452 /* Example.xcodeproj */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -292,6 +304,14 @@
path = Protocols;
sourceTree = "<group>";
};
51E04F3F24F7DCD0004D7452 /* Products */ = {
isa = PBXGroup;
children = (
51E04F4324F7DCD0004D7452 /* Example.app */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -352,13 +372,29 @@
mainGroup = 383B83791F4787E200027965;
productRefGroup = 383B83841F4787E200027965 /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 51E04F3F24F7DCD0004D7452 /* Products */;
ProjectRef = 51E04F3E24F7DCD0004D7452 /* Example.xcodeproj */;
},
);
projectRoot = "";
targets = (
383B83821F4787E200027965 /* InputBarAccessoryView */,
);
};
/* End PBXProject section */

/* Begin PBXReferenceProxy section */
51E04F4324F7DCD0004D7452 /* Example.app */ = {
isa = PBXReferenceProxy;
fileType = wrapper.application;
path = Example.app;
remoteRef = 51E04F4224F7DCD0004D7452 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
383B83811F4787E200027965 /* Resources */ = {
isa = PBXResourcesBuildPhase;
Expand Down
3 changes: 0 additions & 3 deletions InputBarAccessoryView.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>

0 comments on commit 4c2d1e4

Please sign in to comment.