Skip to content

Commit

Permalink
fix survey, contact, and task view tint colors (#676)
Browse files Browse the repository at this point in the history
* fix survey tint color

* Only set color if it's the default

* check window.tintColor directly

* propagate tintColor through rest of CareKit

* use new determineTintColor helper method

* nits

* mart new method for removal
  • Loading branch information
cbaker6 authored Dec 15, 2022
1 parent 8ca7962 commit 0c4268c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,18 @@ UIViewController, OCKContactViewDelegate, MFMessageComposeViewControllerDelegate

open func didSelectContactView(_ contactView: UIView & OCKContactDisplayable) {
handleThrowable(method: controller.initiateSystemContactLookup) { [weak self] contactViewController in
/*
TODO: Remove in the future. Explicitly setting the tint color here to support
current developers that have a SwiftUI lifecycle app and wrap this view
controller in a `UIViewControllerRepresentable` implementation...Tint color
is not propagated...etc.
*/
let tintColor = determineTintColor(from: view)
contactViewController.view.tintColor = tintColor
contactViewController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self,
action: #selector(dismissViewController))
let navigationController = UINavigationController(rootViewController: contactViewController)
navigationController.navigationBar.tintColor = tintColor
present(navigationController, animated: true, completion: nil)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ internal extension UIViewController {
stackView.insertArrangedSubview(view, at: index, animated: animated)
didMove(toParent: containerViewController)
}

func determineTintColor(from view: UIView) -> UIColor {
self.view.window?.tintColor ?? view.tintColor
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ open class OCKSurveyTaskViewController: OCKTaskViewController<OCKTaskController,

warningAlert.addAction(cancelAction)
warningAlert.addAction(confirmAction)
/*
TODO: Remove in the future. Explicitly setting the tint color here to support
current developers that have a SwiftUI lifecycle app and wrap this view
controller in a `UIViewControllerRepresentable` implementation...Tint color
is not propagated...etc.
*/
warningAlert.view.tintColor = determineTintColor(from: view)
present(warningAlert, animated: true, completion: nil)

return
Expand All @@ -169,6 +176,13 @@ open class OCKSurveyTaskViewController: OCKTaskViewController<OCKTaskController,
).last!.appendingPathComponent("ResearchKit", isDirectory: true)

surveyViewController.outputDirectory = directory
/*
TODO: Remove in the future. Explicitly setting the tint color here to support
current developers that have a SwiftUI lifecycle app and wrap this view
controller in a `UIViewControllerRepresentable` implementation...Tint color
is not propagated...etc.
*/
surveyViewController.view.tintColor = determineTintColor(from: view)
surveyViewController.delegate = self

present(surveyViewController, animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ UIViewController, OCKTaskViewDelegate {
alert.popoverPresentationController?.sourceView = anchor
alert.popoverPresentationController?.permittedArrowDirections = .any
}
/*
TODO: Remove in the future. Explicitly setting the tint color here to support
current developers that have a SwiftUI lifecycle app and wrap this view
controller in a `UIViewControllerRepresentable` implementation...Tint color
is not propagated...etc.
*/
alert.view.tintColor = determineTintColor(from: view)
present(alert, animated: true, completion: nil)
} catch {
if delegate == nil {
Expand All @@ -209,6 +216,13 @@ UIViewController, OCKTaskViewDelegate {
open func didSelectTaskView(_ taskView: UIView & OCKTaskDisplayable, eventIndexPath: IndexPath) {
do {
let detailsViewController = try controller.initiateDetailsViewController(forIndexPath: eventIndexPath)
/*
TODO: Remove in the future. Explicitly setting the tint color here to support
current developers that have a SwiftUI lifecycle app and wrap this view
controller in a `UIViewControllerRepresentable` implementation...Tint color
is not propagated...etc.
*/
detailsViewController.view.tintColor = determineTintColor(from: view)
present(detailsViewController, animated: true)
} catch {
if delegate == nil {
Expand Down

0 comments on commit 0c4268c

Please sign in to comment.