Skip to content

Commit

Permalink
Work/9.0.4 (#479)
Browse files Browse the repository at this point in the history
* Add dark mode theme

* Remove availability check, which is not supported in iOS 15

* Support Xcode 13 (#478)

* Remove @available from enum cases

* Carthage support

* Refactor

* Remove unnecessary methods

* Code review

Co-authored-by: Timothy Moose <[email protected]>

* Prep for release

* Update changelog

Co-authored-by: Kohki Miki <[email protected]>
  • Loading branch information
wtmoose and giginet authored Sep 17, 2021
1 parent 349fec7 commit c502648
Show file tree
Hide file tree
Showing 10 changed files with 550 additions and 471 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.

## 9.0.4

* #471 Xcode 13 issue - Enum cases with associated values cannot be marked potentially unavailable with '@available'
* Improve colors for dark mode.

## 9.0.3

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion SwiftMessages.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'SwiftMessages'
spec.version = '9.0.3'
spec.version = '9.0.4'
spec.license = { :type => 'MIT' }
spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages'
spec.authors = { 'Timothy Moose' => '[email protected]' }
Expand Down
10 changes: 7 additions & 3 deletions SwiftMessages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0797E40E26EE12B400691606 /* WindowScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0797E40D26EE12B400691606 /* WindowScene.swift */; };
220655121FAF82B600F4E00F /* MarginAdjustable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */; };
220D386E2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 220D386D2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift */; };
224FB69921153B440081D4DE /* CALayer+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 224FB69821153B440081D4DE /* CALayer+Extensions.swift */; };
Expand Down Expand Up @@ -54,7 +55,7 @@
2298C2051EE47DC900E2DDC1 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2041EE47DC900E2DDC1 /* Weak.swift */; };
2298C2071EE480D000E2DDC1 /* Animator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2061EE480D000E2DDC1 /* Animator.swift */; };
2298C2091EE486E300E2DDC1 /* TopBottomAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2081EE486E300E2DDC1 /* TopBottomAnimation.swift */; };
229F778125FAB1E9008C2ACB /* UIWindow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */; };
229F778125FAB1E9008C2ACB /* UIWindow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */; };
22DFC9161EFF30F6001B1CA1 /* CenteredView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22DFC9151EFF30F6001B1CA1 /* CenteredView.xib */; };
22DFC9181F00674E001B1CA1 /* PhysicsPanHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22DFC9171F00674E001B1CA1 /* PhysicsPanHandler.swift */; };
22E01F641E74EC8B00ACE19A /* MaskingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22E01F631E74EC8B00ACE19A /* MaskingView.swift */; };
Expand Down Expand Up @@ -94,6 +95,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0797E40D26EE12B400691606 /* WindowScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowScene.swift; sourceTree = "<group>"; };
220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MarginAdjustable+Extensions.swift"; sourceTree = "<group>"; };
220D386D2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftMessages.Config+Extensions.swift"; sourceTree = "<group>"; };
224FB69821153B440081D4DE /* CALayer+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CALayer+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -141,7 +143,7 @@
2298C2041EE47DC900E2DDC1 /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
2298C2061EE480D000E2DDC1 /* Animator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Animator.swift; sourceTree = "<group>"; };
2298C2081EE486E300E2DDC1 /* TopBottomAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TopBottomAnimation.swift; sourceTree = "<group>"; };
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+Extensions.swift"; sourceTree = "<group>"; };
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+Extensions.swift"; sourceTree = "<group>"; };
22A2EA6E24EC6CFA00BB2540 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
22DFC9151EFF30F6001B1CA1 /* CenteredView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CenteredView.xib; path = Resources/CenteredView.xib; sourceTree = "<group>"; };
22DFC9171F00674E001B1CA1 /* PhysicsPanHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhysicsPanHandler.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -211,7 +213,7 @@
children = (
220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */,
22774B9F20B5EF2A00813732 /* UIEdgeInsets+Extensions.swift */,
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */,
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */,
);
name = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -304,6 +306,7 @@
2298C2041EE47DC900E2DDC1 /* Weak.swift */,
22F27950210CE25900273E7F /* CornerRoundingView.swift */,
225304652293000C00A03ACF /* KeyboardTrackingView.swift */,
0797E40D26EE12B400691606 /* WindowScene.swift */,
);
name = Base;
sourceTree = "<group>";
Expand Down Expand Up @@ -555,6 +558,7 @@
86BBA9081D5E040C00FE8F16 /* Error.swift in Sources */,
2298C2091EE486E300E2DDC1 /* TopBottomAnimation.swift in Sources */,
86589D471D64B6E40041676C /* BaseView.swift in Sources */,
0797E40E26EE12B400691606 /* WindowScene.swift in Sources */,
225304622290C76E00A03ACF /* NSLayoutConstraint+Extensions.swift in Sources */,
86BBA9071D5E040C00FE8F16 /* MarginAdjustable.swift in Sources */,
867BED211D622793005212E3 /* BackgroundViewable.swift in Sources */,
Expand Down
72 changes: 60 additions & 12 deletions SwiftMessages/MessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,24 +251,72 @@ extension MessageView {
*/
public func configureTheme(_ theme: Theme, iconStyle: IconStyle = .default) {
let iconImage = iconStyle.image(theme: theme)
let backgroundColor: UIColor
let foregroundColor: UIColor
let defaultBackgroundColor: UIColor
let defaultForegroundColor: UIColor
switch theme {
case .info:
let backgroundColor = UIColor(red: 225.0/255.0, green: 225.0/255.0, blue: 225.0/255.0, alpha: 1.0)
let foregroundColor = UIColor.darkText
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
defaultBackgroundColor = UIColor(red: 225.0/255.0, green: 225.0/255.0, blue: 225.0/255.0, alpha: 1.0)
defaultForegroundColor = UIColor.darkText
case .success:
let backgroundColor = UIColor(red: 97.0/255.0, green: 161.0/255.0, blue: 23.0/255.0, alpha: 1.0)
let foregroundColor = UIColor.white
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
defaultBackgroundColor = UIColor(red: 97.0/255.0, green: 161.0/255.0, blue: 23.0/255.0, alpha: 1.0)
defaultForegroundColor = UIColor.white
case .warning:
let backgroundColor = UIColor(red: 238.0/255.0, green: 189.0/255.0, blue: 34.0/255.0, alpha: 1.0)
let foregroundColor = UIColor.white
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
defaultBackgroundColor = UIColor(red: 246.0/255.0, green: 197.0/255.0, blue: 44.0/255.0, alpha: 1.0)
defaultForegroundColor = UIColor.white
case .error:
let backgroundColor = UIColor(red: 249.0/255.0, green: 66.0/255.0, blue: 47.0/255.0, alpha: 1.0)
let foregroundColor = UIColor.white
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
defaultBackgroundColor = UIColor(red: 249.0/255.0, green: 66.0/255.0, blue: 47.0/255.0, alpha: 1.0)
defaultForegroundColor = UIColor.white
}
if #available(iOS 13.0, *) {
switch theme {
case .info:
backgroundColor = UIColor {
switch $0.userInterfaceStyle {
case .dark, .unspecified: return UIColor(red: 125/255.0, green: 125/255.0, blue: 125/255.0, alpha: 1.0)
case .light: fallthrough
@unknown default:
return defaultBackgroundColor
}
}
foregroundColor = .label
case .success:
backgroundColor = UIColor {
switch $0.userInterfaceStyle {
case .dark, .unspecified: return UIColor(red: 55/255.0, green: 122/255.0, blue: 0/255.0, alpha: 1.0)
case .light: fallthrough
@unknown default:
return defaultBackgroundColor
}
}
foregroundColor = .white
case .warning:
backgroundColor = UIColor {
switch $0.userInterfaceStyle {
case .dark, .unspecified: return UIColor(red: 239/255.0, green: 184/255.0, blue: 10/255.0, alpha: 1.0)
case .light: fallthrough
@unknown default:
return defaultBackgroundColor
}
}
foregroundColor = .white
case .error:
backgroundColor = UIColor {
switch $0.userInterfaceStyle {
case .dark, .unspecified: return UIColor(red: 195/255.0, green: 12/255.0, blue: 12/255.0, alpha: 1.0)
case .light: fallthrough
@unknown default:
return defaultBackgroundColor
}
}
foregroundColor = .white
}
} else {
backgroundColor = defaultBackgroundColor
foregroundColor = defaultForegroundColor
}
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion SwiftMessages/SwiftMessages.Config+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension SwiftMessages.Config {
@available (iOS 13.0, *)
var windowScene: UIWindowScene? {
switch presentationContext {
case .windowScene(let scene, _): return scene
case .windowScene(let scene, _): return scene as? UIWindowScene
default:
#if SWIFTMESSAGES_APP_EXTENSIONS
return nil
Expand Down
17 changes: 13 additions & 4 deletions SwiftMessages/SwiftMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ open class SwiftMessages {
of any message view that adopts the `MarginInsetting` protocol (as `MessageView` does)
to account for the status bar. As of iOS 13, windows can no longer cover the
status bar. The only alternative is to set `Config.prefersStatusBarHidden = true`
to hide it.
to hide it. The `WindowScene` protocol works around the change in Xcode 13 that prevents
using `@availability` attribute with `enum` cases containing associated values.
*/
@available(iOS 13.0, *)
case windowScene(_: UIWindowScene, windowLevel: UIWindow.Level)
case windowScene(_: WindowScene, windowLevel: UIWindow.Level)

/**
Displays the message view under navigation bars and tab bars if an
Expand Down Expand Up @@ -248,7 +248,16 @@ open class SwiftMessages {
Specifies how the container for presenting the message view
is selected. The default is `.Automatic`.
*/
public var presentationContext = PresentationContext.automatic
public var presentationContext = PresentationContext.automatic {
didSet {
if case .windowScene = presentationContext {
guard #available(iOS 13.0, *) else {
assertionFailure("windowScene is not supported below iOS 13.0.")
return
}
}
}
}

/**
Specifies the duration of the message view's time on screen before it is
Expand Down
9 changes: 9 additions & 0 deletions SwiftMessages/WindowScene.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation
import UIKit

/// A workaround for the change in Xcode 13 that prevents using `@availability` attribute
/// with `enum` cases containing associated values.
public protocol WindowScene {}

@available(iOS 13.0, *)
extension UIWindowScene: WindowScene {}
2 changes: 1 addition & 1 deletion iMessageDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 2eb9a33592d0c52131c37a9dd169a8c4604ffd7b

COCOAPODS: 1.10.0
COCOAPODS: 1.10.1
2 changes: 1 addition & 1 deletion iMessageDemo/Pods/Manifest.lock

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

Loading

0 comments on commit c502648

Please sign in to comment.