From 840ece880bb1a1ae3ee9f3f774acfdd92ec6b988 Mon Sep 17 00:00:00 2001 From: Aaron Brethorst Date: Thu, 3 Oct 2019 06:55:02 -0600 Subject: [PATCH] Adds support for Dark Mode on iOS 13 (#170) Fixes https://github.com/alexaubry/BulletinBoard/issues/168 - iOS 13 Dark Mode --- .../Swift/Bulletin/BulletinDataSource.swift | 12 ++++- Sources/Appearance/BLTNItemAppearance.swift | 50 +++++++++++++++---- Sources/BLTNItemManager.swift | 28 ++++++++--- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/Example/Swift/Bulletin/BulletinDataSource.swift b/Example/Swift/Bulletin/BulletinDataSource.swift index d5752ee..19bee1b 100644 --- a/Example/Swift/Bulletin/BulletinDataSource.swift +++ b/Example/Swift/Bulletin/BulletinDataSource.swift @@ -225,8 +225,16 @@ enum BulletinDataSource { let page = BLTNPageItem(title: "Setup Completed") page.image = #imageLiteral(resourceName: "IntroCompletion") page.imageAccessibilityLabel = "Checkmark" - page.appearance.actionButtonColor = #colorLiteral(red: 0.2980392157, green: 0.8509803922, blue: 0.3921568627, alpha: 1) - page.appearance.imageViewTintColor = #colorLiteral(red: 0.2980392157, green: 0.8509803922, blue: 0.3921568627, alpha: 1) + + let tintColor: UIColor + if #available(iOS 13.0, *) { + tintColor = .systemGreen + } else { + tintColor = #colorLiteral(red: 0.2980392157, green: 0.8509803922, blue: 0.3921568627, alpha: 1) + } + page.appearance.actionButtonColor = tintColor + page.appearance.imageViewTintColor = tintColor + page.appearance.actionButtonTitleColor = .white page.descriptionText = "PetBoard is ready for you to use. Happy browsing!" diff --git a/Sources/Appearance/BLTNItemAppearance.swift b/Sources/Appearance/BLTNItemAppearance.swift index 59a9bd0..76c45c6 100644 --- a/Sources/Appearance/BLTNItemAppearance.swift +++ b/Sources/Appearance/BLTNItemAppearance.swift @@ -13,8 +13,14 @@ import UIKit // MARK: - Color Customization - /// The tint color to apply to the action button (default blue). - @objc public var actionButtonColor: UIColor = #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1) + /// The tint color to apply to the action button (default `.link` on iOS 13 and `.blue` on older systems). + @objc public var actionButtonColor: UIColor = { + if #available(iOS 13.0, *) { + return .link + } else { + return #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1) + } + }() /// The button image to apply to the action button @objc public var actionButtonImage: UIImage? @@ -28,8 +34,14 @@ import UIKit /// The border width to apply to action button. @objc public var actionButtonBorderWidth: CGFloat = 1.0 - /// The title color to apply to the alternative button (default blue). - @objc public var alternativeButtonTitleColor: UIColor = #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1) + /// The title color to apply to the alternative button (default `.link` on iOS 13 and `.blue` on older systems). + @objc public var alternativeButtonTitleColor: UIColor = { + if #available(iOS 13.0, *) { + return .link + } else { + return #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1) + } + }() /// The border color to apply to the alternative button. @objc public var alternativeButtonBorderColor: UIColor? = nil @@ -37,14 +49,32 @@ import UIKit /// The border width to apply to the alternative button. @objc public var alternativeButtonBorderWidth: CGFloat = 1.0 - /// The tint color to apply to the imageView (if image rendered in template mode, default blue). - @objc public var imageViewTintColor = #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1) + /// The tint color to apply to the imageView (if image rendered in template mode, default `.link` on iOS 13 and `.blue` on older systems). + @objc public var imageViewTintColor: UIColor = { + if #available(iOS 13.0, *) { + return .link + } else { + return #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1) + } + }() - /// The color of title text labels (default light gray). - @objc public var titleTextColor = #colorLiteral(red: 0.568627451, green: 0.5647058824, blue: 0.5725490196, alpha: 1) + /// The color of title text labels (default `.secondaryLabel` on iOS 13 and light gray on older systems). + @objc public var titleTextColor: UIColor = { + if #available(iOS 13.0, *) { + return .secondaryLabel + } else { + return #colorLiteral(red: 0.568627451, green: 0.5647058824, blue: 0.5725490196, alpha: 1) + } + }() - /// The color of description text labels (default black). - @objc public var descriptionTextColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) + /// The color of description text labels (default `.label` on iOS 13 and black on older systems). + @objc public var descriptionTextColor: UIColor = { + if #available(iOS 13.0, *) { + return .label + } else { + return #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) + } + }() // MARK: - Corner Radius Customization diff --git a/Sources/BLTNItemManager.swift b/Sources/BLTNItemManager.swift index 14073f3..a33e86b 100644 --- a/Sources/BLTNItemManager.swift +++ b/Sources/BLTNItemManager.swift @@ -27,12 +27,19 @@ import UIKit // MARK: - Background /** - * The background color of the bulletin card. Defaults to white. + * The background color of the bulletin card. Defaults to `systemBackground` on iOS 13 + * and white on older versions of the OS. * * Set this value before presenting the bulletin. Changing it after will have no effect. */ - @objc public var backgroundColor: UIColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0) + @objc public var backgroundColor: UIColor = { + if #available(iOS 13.0, *) { + return .systemBackground + } else { + return .white + } + }() /** * The style of the view covering the content. Defaults to `.dimmed`. @@ -247,21 +254,30 @@ extension BLTNItemManager { * Displaying the loading indicator does not change the height of the page or the current item. It will disable * dismissal by tapping and swiping to allow the task to complete and avoid resource deallocation. * - * - parameter color: The color of the activity indicator to display. Defaults to black. + * - parameter color: The color of the activity indicator to display. Defaults to .label on iOS 13 and .black on older systems. * * Displaying the loading indicator does not change the height of the page or the current item. */ - @objc public func displayActivityIndicator(color: UIColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)) { + @objc public func displayActivityIndicator(color: UIColor? = nil) { assertIsPrepared() assertIsMainThread() shouldDisplayActivityIndicator = true - lastActivityIndicatorColor = color + lastActivityIndicatorColor = color ?? defaultActivityIndicatorColor - bulletinController.displayActivityIndicator(color: color) + bulletinController.displayActivityIndicator(color: lastActivityIndicatorColor) + } + /// Provides a default color for activity indicator views. + /// Defaults to .label on iOS 13 and .black on older systems. + private var defaultActivityIndicatorColor: UIColor { + if #available(iOS 13.0, *) { + return .label + } else { + return .black + } } /**