Skip to content

Commit

Permalink
Merge pull request #40 from WeTransfer/feature/swift4-2-update
Browse files Browse the repository at this point in the history
Updated to Swift 4.2
  • Loading branch information
AvdLee authored Nov 26, 2018
2 parents 2d513e1 + 0b0fb77 commit 159b978
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode9.2
osx_image: xcode10.1
gemfile: Gemfile
bundler_args: "--without documentation --path bundle" # Don't download documentation for gems.
cache:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
source "https://rubygems.org"

# Needed for Fastlane & Danger
gem 'fastlane', '~>2.86.2'
gem 'fastlane'
gem 'danger'
gem 'danger-swiftlint', '~>0.13.1'
gem 'danger-swiftlint'
gem 'danger-xcov'
gem 'danger-xcode_summary'
gem 'xcpretty'
Expand Down
40 changes: 20 additions & 20 deletions Sources/UINotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public protocol UINotificationStyle {
var backgroundColor: UIColor { get }

/// The height of the notification which applies on the notification view.
var height: UINotificationHeight { get }
var height: UINotification.Height { get }

/// When `true`, the notification is swipeable and tappable.
var interactive: Bool { get }
Expand All @@ -32,24 +32,6 @@ public protocol UINotificationStyle {
var chevronImage: UIImage? { get }
}

/// Defines the height which will be applied on the notification view.
public enum UINotificationHeight {
case statusBar
case navigationBar
case custom(height: CGFloat)

internal var value: CGFloat {
switch self {
case .statusBar:
return UIApplication.shared.statusBarFrame.height
case .navigationBar:
return UIApplication.shared.statusBarFrame.height + 44
case .custom(let height):
return height
}
}
}

/// Handles changes in UINotification
protocol UINotificationDelegate: class {
// Called when Notification is updated
Expand All @@ -58,7 +40,25 @@ protocol UINotificationDelegate: class {

/// An UINotification which can be showed on top of the `UINavigationBar` and `UIStatusBar`
public final class UINotification: Equatable {


/// Defines the height which will be applied on the notification view.
public enum Height {
case statusBar
case navigationBar
case custom(height: CGFloat)

internal var value: CGFloat {
switch self {
case .statusBar:
return UIApplication.shared.statusBarFrame.height
case .navigationBar:
return UIApplication.shared.statusBarFrame.height + 44
case .custom(let height):
return height
}
}
}

/// The content of the notification.
public var content: UINotificationContent

Expand Down
2 changes: 1 addition & 1 deletion Sources/UINotificationCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class UINotificationCenter {

/// The window level that notification should appear at. The default level is over the status bar.
/// Changing the window level while a notification is displayed might give some issues.
public var windowLevel: UIWindowLevel = UIWindowLevelStatusBar
public var windowLevel: UIWindow.Level = UIWindow.Level.statusBar

/// If `true`, the same notifications can be queued. This can result in duplicate notifications being presented after each other.
public var isDuplicateQueueingAllowed: Bool = false
Expand Down
2 changes: 1 addition & 1 deletion Sources/UINotificationDismissTrigger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public protocol Dismissable: class {
/// A trigger which can be used to dismiss an `UINotificationView`.
public protocol UINotificationDismissTrigger: class {
/// The target to dismiss.
weak var target: Dismissable? { get set }
var target: Dismissable? { get set }
}

/// A trigger which is schedulable and therefor cancelable.
Expand Down
6 changes: 3 additions & 3 deletions Sources/UINotificationPresentationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class UINotificationPresentationContext {
public let containerWindow: UIWindow

/// The level the container window should be on when presenting the notification
private let windowLevel: UIWindowLevel
private let windowLevel: UIWindow.Level

/// The `UINotificationView` containing the visual representation of the `UINotification`.
public let notificationView: UINotificationView
Expand All @@ -28,7 +28,7 @@ public final class UINotificationPresentationContext {
return request.notification
}

internal init(request: UINotificationRequest, containerWindow: UIWindow, windowLevel: UIWindowLevel, notificationView: UINotificationView) {
internal init(request: UINotificationRequest, containerWindow: UIWindow, windowLevel: UIWindow.Level, notificationView: UINotificationView) {
self.request = request
self.containerWindow = containerWindow
self.notificationView = notificationView
Expand Down Expand Up @@ -86,7 +86,7 @@ public final class UINotificationPresentationContext {

private func resetContainerWindow() {
/// Move the window behind the key application window.
containerWindow.windowLevel = UIWindowLevelNormal - 1
containerWindow.windowLevel = UIWindow.Level.normal - 1
containerWindow.rootViewController = nil

/// Make sure the key window of the app is visible again.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class UINotificationEaseOutEaseInPresenter: UINotificationPresenter
presentationContext.notificationView.topConstraint?.constant = presentationContext.notificationView.layoutMargins.top + UIApplication.shared.statusBarFrame.size.height
}

UIView.animate(withDuration: inDuration, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: {
UIView.animate(withDuration: inDuration, delay: 0.0, options: UIView.AnimationOptions.curveEaseOut, animations: {
self.presentationContext.containerWindow.layoutIfNeeded()
}, completion: { (_) in
self.state = .presented
Expand All @@ -53,7 +53,7 @@ public final class UINotificationEaseOutEaseInPresenter: UINotificationPresenter

presentationContext.notificationView.topConstraint?.constant = -presentationContext.notification.style.height.value

UIView.animate(withDuration: outDuration, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: {
UIView.animate(withDuration: outDuration, delay: 0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.presentationContext.containerWindow.layoutIfNeeded()
}, completion: { (_) in
self.state = .idle
Expand Down
5 changes: 2 additions & 3 deletions Sources/UINotificationQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ internal final class UINotificationQueue {

internal func remove(_ request: UINotificationRequest) {
lockQueue.sync {
guard let index = requests.index(where: { $0 == request }) else { return }
requests.remove(at: index)
requests.removeAll(where: { $0 == request })
}
updateRunningRequest()
}
Expand All @@ -81,7 +80,7 @@ internal final class UINotificationQueue {
}

extension UINotificationQueue: UINotificationRequestDelegate {
func notificationRequest(_ request: UINotificationRequest, didChangeStateTo state: UINotificationRequest.UINotificationRequestState) {
func notificationRequest(_ request: UINotificationRequest, didChangeStateTo state: UINotificationRequest.State) {
switch state {
case .finished, .cancelled:
remove(request)
Expand Down
6 changes: 3 additions & 3 deletions Sources/UINotificationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protocol UINotificationRequestDelegate: class {
/// - Parameters:
/// - request: The `UINotificationRequest` of which the state is changed.
/// - state: The new state of the passed `UINotificationRequest`.
func notificationRequest(_ request: UINotificationRequest, didChangeStateTo state: UINotificationRequest.UINotificationRequestState)
func notificationRequest(_ request: UINotificationRequest, didChangeStateTo state: UINotificationRequest.State)
}

/// Defines the request of a notification presentation.
Expand All @@ -26,7 +26,7 @@ public final class UINotificationRequest: Equatable {
weak var target: UINotificationRequestDelegate?
}

public enum UINotificationRequestState {
public enum State {
/// Waiting to run
case idle

Expand All @@ -53,7 +53,7 @@ public final class UINotificationRequest: Equatable {
private let identifier: UUID

/// The current state of the request.
private(set) public var state: UINotificationRequestState = .idle {
private(set) public var state: UINotificationRequest.State = .idle {
didSet {
delegates.forEach { $0.target?.notificationRequest(self, didChangeStateTo: state) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct UINotificationSystemStyle: UINotificationStyle {
public var backgroundColor: UIColor = UIColor.white
public var titleTextColor: UIColor = UIColor.black
public var subtitleTextColor: UIColor = UIColor.darkGray
public var height: UINotificationHeight = .navigationBar
public var height: UINotification.Height = .navigationBar
public var interactive: Bool = true
public var chevronImage: UIImage?

Expand Down
2 changes: 1 addition & 1 deletion Sources/UINotificationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ open class UINotificationView: UIView {
handlePanGestureState(panGestureRecognizer.state, translation: translation)
}

internal func handlePanGestureState(_ state: UIGestureRecognizerState, translation: CGPoint) {
internal func handlePanGestureState(_ state: UIGestureRecognizer.State, translation: CGPoint) {
guard let presenter = presenter, let topConstraint = topConstraint else { return }

if state == .began {
Expand Down
20 changes: 13 additions & 7 deletions UINotifications.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0920;
LastUpgradeCheck = 1010;
ORGANIZATIONNAME = WeTransfer;
TargetAttributes = {
502C139F206E5F230082CE37 = {
Expand Down Expand Up @@ -365,13 +365,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -425,13 +427,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -481,7 +485,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -503,7 +507,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -520,7 +524,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotificationsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -536,7 +540,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotificationsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -555,13 +559,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -618,7 +624,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotifications;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Test;
Expand All @@ -635,7 +641,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wetransfer.UINotificationsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,12 +26,12 @@
buildConfiguration = "Test"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
skipped = "NO"
testExecutionOrdering = "random">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "502C13A8206E5F230082CE37"
Expand All @@ -57,7 +57,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -10,7 +10,6 @@
buildConfiguration = "Test"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand All @@ -31,7 +30,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion UINotificationsTests/Extensions/XCTestExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension XCTestCase {
let end = Date().addingTimeInterval(timeout)

while !condition() && 0 < end.timeIntervalSinceNow {
if RunLoop.current.run(mode: RunLoopMode.defaultRunLoopMode, before: Date(timeIntervalSinceNow: 0.002)) {
if RunLoop.current.run(mode: RunLoop.Mode.default, before: Date(timeIntervalSinceNow: 0.002)) {
Thread.sleep(forTimeInterval: 0.002)
}
}
Expand Down
4 changes: 2 additions & 2 deletions UINotificationsTests/UINotificationDefaultElementsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ final class UINotificationDefaultElementsTests: UINotificationTestCase {
var titleTextColor: UIColor = UIColor.black
var subtitleTextColor: UIColor = UIColor.black
var backgroundColor: UIColor = UIColor.white
var height: UINotificationHeight {
return UINotificationHeight.custom(height: self.customHeight)
var height: UINotification.Height {
return UINotification.Height.custom(height: self.customHeight)
}
var interactive: Bool = true
var chevronImage: UIImage?
Expand Down
Loading

0 comments on commit 159b978

Please sign in to comment.