Skip to content

Commit c502648

Browse files
wtmoosegiginet
andauthored
Work/9.0.4 (SwiftKickMobile#479)
* Add dark mode theme * Remove availability check, which is not supported in iOS 15 * Support Xcode 13 (SwiftKickMobile#478) * Remove @available from enum cases * Carthage support * Refactor * Remove unnecessary methods * Code review Co-authored-by: Timothy Moose <tim@swiftkick.it> * Prep for release * Update changelog Co-authored-by: Kohki Miki <giginet.net@gmail.com>
1 parent 349fec7 commit c502648

10 files changed

+550
-471
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 9.0.4
5+
6+
* #471 Xcode 13 issue - Enum cases with associated values cannot be marked potentially unavailable with '@available'
7+
* Improve colors for dark mode.
8+
49
## 9.0.3
510

611
### Fixes

SwiftMessages.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'SwiftMessages'
3-
spec.version = '9.0.3'
3+
spec.version = '9.0.4'
44
spec.license = { :type => 'MIT' }
55
spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages'
66
spec.authors = { 'Timothy Moose' => 'tim@swiftkick.it' }

SwiftMessages.xcodeproj/project.pbxproj

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0797E40E26EE12B400691606 /* WindowScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0797E40D26EE12B400691606 /* WindowScene.swift */; };
1011
220655121FAF82B600F4E00F /* MarginAdjustable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */; };
1112
220D386E2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 220D386D2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift */; };
1213
224FB69921153B440081D4DE /* CALayer+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 224FB69821153B440081D4DE /* CALayer+Extensions.swift */; };
@@ -54,7 +55,7 @@
5455
2298C2051EE47DC900E2DDC1 /* Weak.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2041EE47DC900E2DDC1 /* Weak.swift */; };
5556
2298C2071EE480D000E2DDC1 /* Animator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2061EE480D000E2DDC1 /* Animator.swift */; };
5657
2298C2091EE486E300E2DDC1 /* TopBottomAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2298C2081EE486E300E2DDC1 /* TopBottomAnimation.swift */; };
57-
229F778125FAB1E9008C2ACB /* UIWindow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */; };
58+
229F778125FAB1E9008C2ACB /* UIWindow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */; };
5859
22DFC9161EFF30F6001B1CA1 /* CenteredView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22DFC9151EFF30F6001B1CA1 /* CenteredView.xib */; };
5960
22DFC9181F00674E001B1CA1 /* PhysicsPanHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22DFC9171F00674E001B1CA1 /* PhysicsPanHandler.swift */; };
6061
22E01F641E74EC8B00ACE19A /* MaskingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22E01F631E74EC8B00ACE19A /* MaskingView.swift */; };
@@ -94,6 +95,7 @@
9495
/* End PBXContainerItemProxy section */
9596

9697
/* Begin PBXFileReference section */
98+
0797E40D26EE12B400691606 /* WindowScene.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowScene.swift; sourceTree = "<group>"; };
9799
220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MarginAdjustable+Extensions.swift"; sourceTree = "<group>"; };
98100
220D386D2597AA5B00BB2B88 /* SwiftMessages.Config+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftMessages.Config+Extensions.swift"; sourceTree = "<group>"; };
99101
224FB69821153B440081D4DE /* CALayer+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CALayer+Extensions.swift"; sourceTree = "<group>"; };
@@ -141,7 +143,7 @@
141143
2298C2041EE47DC900E2DDC1 /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weak.swift; sourceTree = "<group>"; };
142144
2298C2061EE480D000E2DDC1 /* Animator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Animator.swift; sourceTree = "<group>"; };
143145
2298C2081EE486E300E2DDC1 /* TopBottomAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TopBottomAnimation.swift; sourceTree = "<group>"; };
144-
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+Extensions.swift"; sourceTree = "<group>"; };
146+
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+Extensions.swift"; sourceTree = "<group>"; };
145147
22A2EA6E24EC6CFA00BB2540 /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
146148
22DFC9151EFF30F6001B1CA1 /* CenteredView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CenteredView.xib; path = Resources/CenteredView.xib; sourceTree = "<group>"; };
147149
22DFC9171F00674E001B1CA1 /* PhysicsPanHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhysicsPanHandler.swift; sourceTree = "<group>"; };
@@ -211,7 +213,7 @@
211213
children = (
212214
220655111FAF82B600F4E00F /* MarginAdjustable+Extensions.swift */,
213215
22774B9F20B5EF2A00813732 /* UIEdgeInsets+Extensions.swift */,
214-
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */,
216+
229F778025FAB1E9008C2ACB /* UIWindow+Extensions.swift */,
215217
);
216218
name = Extensions;
217219
sourceTree = "<group>";
@@ -304,6 +306,7 @@
304306
2298C2041EE47DC900E2DDC1 /* Weak.swift */,
305307
22F27950210CE25900273E7F /* CornerRoundingView.swift */,
306308
225304652293000C00A03ACF /* KeyboardTrackingView.swift */,
309+
0797E40D26EE12B400691606 /* WindowScene.swift */,
307310
);
308311
name = Base;
309312
sourceTree = "<group>";
@@ -555,6 +558,7 @@
555558
86BBA9081D5E040C00FE8F16 /* Error.swift in Sources */,
556559
2298C2091EE486E300E2DDC1 /* TopBottomAnimation.swift in Sources */,
557560
86589D471D64B6E40041676C /* BaseView.swift in Sources */,
561+
0797E40E26EE12B400691606 /* WindowScene.swift in Sources */,
558562
225304622290C76E00A03ACF /* NSLayoutConstraint+Extensions.swift in Sources */,
559563
86BBA9071D5E040C00FE8F16 /* MarginAdjustable.swift in Sources */,
560564
867BED211D622793005212E3 /* BackgroundViewable.swift in Sources */,

SwiftMessages/MessageView.swift

+60-12
Original file line numberDiff line numberDiff line change
@@ -251,24 +251,72 @@ extension MessageView {
251251
*/
252252
public func configureTheme(_ theme: Theme, iconStyle: IconStyle = .default) {
253253
let iconImage = iconStyle.image(theme: theme)
254+
let backgroundColor: UIColor
255+
let foregroundColor: UIColor
256+
let defaultBackgroundColor: UIColor
257+
let defaultForegroundColor: UIColor
254258
switch theme {
255259
case .info:
256-
let backgroundColor = UIColor(red: 225.0/255.0, green: 225.0/255.0, blue: 225.0/255.0, alpha: 1.0)
257-
let foregroundColor = UIColor.darkText
258-
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
260+
defaultBackgroundColor = UIColor(red: 225.0/255.0, green: 225.0/255.0, blue: 225.0/255.0, alpha: 1.0)
261+
defaultForegroundColor = UIColor.darkText
259262
case .success:
260-
let backgroundColor = UIColor(red: 97.0/255.0, green: 161.0/255.0, blue: 23.0/255.0, alpha: 1.0)
261-
let foregroundColor = UIColor.white
262-
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
263+
defaultBackgroundColor = UIColor(red: 97.0/255.0, green: 161.0/255.0, blue: 23.0/255.0, alpha: 1.0)
264+
defaultForegroundColor = UIColor.white
263265
case .warning:
264-
let backgroundColor = UIColor(red: 238.0/255.0, green: 189.0/255.0, blue: 34.0/255.0, alpha: 1.0)
265-
let foregroundColor = UIColor.white
266-
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
266+
defaultBackgroundColor = UIColor(red: 246.0/255.0, green: 197.0/255.0, blue: 44.0/255.0, alpha: 1.0)
267+
defaultForegroundColor = UIColor.white
267268
case .error:
268-
let backgroundColor = UIColor(red: 249.0/255.0, green: 66.0/255.0, blue: 47.0/255.0, alpha: 1.0)
269-
let foregroundColor = UIColor.white
270-
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
269+
defaultBackgroundColor = UIColor(red: 249.0/255.0, green: 66.0/255.0, blue: 47.0/255.0, alpha: 1.0)
270+
defaultForegroundColor = UIColor.white
271271
}
272+
if #available(iOS 13.0, *) {
273+
switch theme {
274+
case .info:
275+
backgroundColor = UIColor {
276+
switch $0.userInterfaceStyle {
277+
case .dark, .unspecified: return UIColor(red: 125/255.0, green: 125/255.0, blue: 125/255.0, alpha: 1.0)
278+
case .light: fallthrough
279+
@unknown default:
280+
return defaultBackgroundColor
281+
}
282+
}
283+
foregroundColor = .label
284+
case .success:
285+
backgroundColor = UIColor {
286+
switch $0.userInterfaceStyle {
287+
case .dark, .unspecified: return UIColor(red: 55/255.0, green: 122/255.0, blue: 0/255.0, alpha: 1.0)
288+
case .light: fallthrough
289+
@unknown default:
290+
return defaultBackgroundColor
291+
}
292+
}
293+
foregroundColor = .white
294+
case .warning:
295+
backgroundColor = UIColor {
296+
switch $0.userInterfaceStyle {
297+
case .dark, .unspecified: return UIColor(red: 239/255.0, green: 184/255.0, blue: 10/255.0, alpha: 1.0)
298+
case .light: fallthrough
299+
@unknown default:
300+
return defaultBackgroundColor
301+
}
302+
}
303+
foregroundColor = .white
304+
case .error:
305+
backgroundColor = UIColor {
306+
switch $0.userInterfaceStyle {
307+
case .dark, .unspecified: return UIColor(red: 195/255.0, green: 12/255.0, blue: 12/255.0, alpha: 1.0)
308+
case .light: fallthrough
309+
@unknown default:
310+
return defaultBackgroundColor
311+
}
312+
}
313+
foregroundColor = .white
314+
}
315+
} else {
316+
backgroundColor = defaultBackgroundColor
317+
foregroundColor = defaultForegroundColor
318+
}
319+
configureTheme(backgroundColor: backgroundColor, foregroundColor: foregroundColor, iconImage: iconImage)
272320
}
273321

274322
/**

SwiftMessages/SwiftMessages.Config+Extensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension SwiftMessages.Config {
2020
@available (iOS 13.0, *)
2121
var windowScene: UIWindowScene? {
2222
switch presentationContext {
23-
case .windowScene(let scene, _): return scene
23+
case .windowScene(let scene, _): return scene as? UIWindowScene
2424
default:
2525
#if SWIFTMESSAGES_APP_EXTENSIONS
2626
return nil

SwiftMessages/SwiftMessages.swift

+13-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ open class SwiftMessages {
7777
of any message view that adopts the `MarginInsetting` protocol (as `MessageView` does)
7878
to account for the status bar. As of iOS 13, windows can no longer cover the
7979
status bar. The only alternative is to set `Config.prefersStatusBarHidden = true`
80-
to hide it.
80+
to hide it. The `WindowScene` protocol works around the change in Xcode 13 that prevents
81+
using `@availability` attribute with `enum` cases containing associated values.
8182
*/
82-
@available(iOS 13.0, *)
83-
case windowScene(_: UIWindowScene, windowLevel: UIWindow.Level)
83+
case windowScene(_: WindowScene, windowLevel: UIWindow.Level)
8484

8585
/**
8686
Displays the message view under navigation bars and tab bars if an
@@ -248,7 +248,16 @@ open class SwiftMessages {
248248
Specifies how the container for presenting the message view
249249
is selected. The default is `.Automatic`.
250250
*/
251-
public var presentationContext = PresentationContext.automatic
251+
public var presentationContext = PresentationContext.automatic {
252+
didSet {
253+
if case .windowScene = presentationContext {
254+
guard #available(iOS 13.0, *) else {
255+
assertionFailure("windowScene is not supported below iOS 13.0.")
256+
return
257+
}
258+
}
259+
}
260+
}
252261

253262
/**
254263
Specifies the duration of the message view's time on screen before it is

SwiftMessages/WindowScene.swift

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Foundation
2+
import UIKit
3+
4+
/// A workaround for the change in Xcode 13 that prevents using `@availability` attribute
5+
/// with `enum` cases containing associated values.
6+
public protocol WindowScene {}
7+
8+
@available(iOS 13.0, *)
9+
extension UIWindowScene: WindowScene {}

iMessageDemo/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ SPEC CHECKSUMS:
1313

1414
PODFILE CHECKSUM: 2eb9a33592d0c52131c37a9dd169a8c4604ffd7b
1515

16-
COCOAPODS: 1.10.0
16+
COCOAPODS: 1.10.1

iMessageDemo/Pods/Manifest.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)