From 39d367d457036b2969eb0961a238017248d68cd6 Mon Sep 17 00:00:00 2001 From: Daniel Huri Date: Fri, 8 Jun 2018 16:48:30 +0300 Subject: [PATCH] Keep Background Unchanged when 2 Consecutive Entry Screen Backgrounds Match #46 --- CHANGELOG.md | 6 ++++ Example/Podfile.lock | 6 ++-- .../Local Podspecs/SwiftEntryKit.podspec.json | 4 +-- Example/Pods/Manifest.lock | 6 ++-- .../SwiftEntryKit/Info.plist | 2 +- README.md | 4 +-- Source/Infra/EKContentView.swift | 8 ++--- Source/Infra/EKRootViewController.swift | 31 +++++++++++++++---- .../EKAttributes+BackgroundStyle.swift | 31 ++++++++++++++++--- SwiftEntryKit.podspec | 2 +- 10 files changed, 74 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19284764..c69c218c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log Any notable changes to this project will be documented in this file. +## 0.4.1 + +### Issues Handled + +[Keep Background Unchanged when 2 Consecutive Entry Screen Backgrounds Match #46](https://github.com/huri000/SwiftEntryKit/issues/46) + ## 0.4.0 ### Features diff --git a/Example/Podfile.lock b/Example/Podfile.lock index b7a1f790..fd115b9c 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -2,7 +2,7 @@ PODS: - Nimble (7.0.2) - Quick (1.2.0) - QuickLayout (2.0.2) - - SwiftEntryKit (0.4.0): + - SwiftEntryKit (0.4.1): - QuickLayout (= 2.0.2) DEPENDENCIES: @@ -24,8 +24,8 @@ SPEC CHECKSUMS: Nimble: bfe1f814edabba69ff145cb1283e04ed636a67f2 Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08 QuickLayout: a730730b646b231fd4ef7cffaeb1e81fe0e1ca92 - SwiftEntryKit: 89fdd4a15ae213d9b9bbcf36a319d2d3696f5f13 + SwiftEntryKit: ea33b0916c8071f6d61b5d6c0aa34a09e1ee315a PODFILE CHECKSUM: edd6c2af5cc390dbf823427759474ab6c303ec9e -COCOAPODS: 1.5.2 +COCOAPODS: 1.5.3 diff --git a/Example/Pods/Local Podspecs/SwiftEntryKit.podspec.json b/Example/Pods/Local Podspecs/SwiftEntryKit.podspec.json index 12f41017..c9a07529 100644 --- a/Example/Pods/Local Podspecs/SwiftEntryKit.podspec.json +++ b/Example/Pods/Local Podspecs/SwiftEntryKit.podspec.json @@ -1,6 +1,6 @@ { "name": "SwiftEntryKit", - "version": "0.4.0", + "version": "0.4.1", "summary": "A simple banner and pop-up displayer for iOS. Written in Swift.", "platforms": { "ios": "9.0" @@ -17,7 +17,7 @@ }, "source": { "git": "https://github.com/huri000/SwiftEntryKit.git", - "tag": "0.4.0" + "tag": "0.4.1" }, "source_files": "Source/**/*", "frameworks": "UIKit", diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index b7a1f790..fd115b9c 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -2,7 +2,7 @@ PODS: - Nimble (7.0.2) - Quick (1.2.0) - QuickLayout (2.0.2) - - SwiftEntryKit (0.4.0): + - SwiftEntryKit (0.4.1): - QuickLayout (= 2.0.2) DEPENDENCIES: @@ -24,8 +24,8 @@ SPEC CHECKSUMS: Nimble: bfe1f814edabba69ff145cb1283e04ed636a67f2 Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08 QuickLayout: a730730b646b231fd4ef7cffaeb1e81fe0e1ca92 - SwiftEntryKit: 89fdd4a15ae213d9b9bbcf36a319d2d3696f5f13 + SwiftEntryKit: ea33b0916c8071f6d61b5d6c0aa34a09e1ee315a PODFILE CHECKSUM: edd6c2af5cc390dbf823427759474ab6c303ec9e -COCOAPODS: 1.5.2 +COCOAPODS: 1.5.3 diff --git a/Example/Pods/Target Support Files/SwiftEntryKit/Info.plist b/Example/Pods/Target Support Files/SwiftEntryKit/Info.plist index 53e4061e..13a981e1 100644 --- a/Example/Pods/Target Support Files/SwiftEntryKit/Info.plist +++ b/Example/Pods/Target Support Files/SwiftEntryKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.4.0 + 0.4.1 CFBundleSignature ???? CFBundleVersion diff --git a/README.md b/README.md index 87baa700..bf5c58dc 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ source 'https://github.com/cocoapods/specs.git' platform :ios, '9.0' use_frameworks! -pod 'SwiftEntryKit', '0.4.0' +pod 'SwiftEntryKit', '0.4.1' ``` Then, run the following command: @@ -150,7 +150,7 @@ $ brew install carthage To integrate SwiftEntryKit into your Xcode project using Carthage, specify the following in your `Cartfile`: ```ogdl -github "huri000/SwiftEntryKit" == 0.4.0 +github "huri000/SwiftEntryKit" == 0.4.1 ``` ## Usage diff --git a/Source/Infra/EKContentView.swift b/Source/Infra/EKContentView.swift index 18d3b344..b5792463 100644 --- a/Source/Infra/EKContentView.swift +++ b/Source/Infra/EKContentView.swift @@ -11,7 +11,7 @@ import QuickLayout protocol EntryContentViewDelegate: class { func changeToActive(withAttributes attributes: EKAttributes) - func changeToInactive(withAttributes attributes: EKAttributes) + func changeToInactive(withAttributes attributes: EKAttributes, pushOut: Bool) } class EKContentView: UIView { @@ -319,7 +319,7 @@ class EKContentView: UIView { } outDispatchWorkItem?.cancel() - entryDelegate?.changeToInactive(withAttributes: attributes) + entryDelegate?.changeToInactive(withAttributes: attributes, pushOut: pushOut) if case .animated(animation: let animation) = attributes.popBehavior, pushOut { animateOut(with: animation, outTranslationType: .pop) @@ -439,7 +439,7 @@ class EKContentView: UIView { // Removes the view promptly - DOES NOT animate out func removePromptly(keepWindow: Bool = true) { outDispatchWorkItem?.cancel() - entryDelegate?.changeToInactive(withAttributes: attributes) + entryDelegate?.changeToInactive(withAttributes: attributes, pushOut: false) removeFromSuperview(keepWindow: keepWindow) } @@ -632,7 +632,7 @@ extension EKContentView { private func stretchOut(usingSwipe type: OutTranslation, duration: TimeInterval) { outDispatchWorkItem?.cancel() - entryDelegate?.changeToInactive(withAttributes: attributes) + entryDelegate?.changeToInactive(withAttributes: attributes, pushOut: false) UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 4, options: [.allowUserInteraction, .beginFromCurrentState], animations: { self.translateOut(withType: type) diff --git a/Source/Infra/EKRootViewController.swift b/Source/Infra/EKRootViewController.swift index e399dc6e..3a6a0e96 100644 --- a/Source/Infra/EKRootViewController.swift +++ b/Source/Infra/EKRootViewController.swift @@ -75,10 +75,12 @@ class EKRootViewController: UIViewController { // Extract the attributes struct let attributes = entryView.attributes - // Remove the last entry - removeLastEntry(keepWindow: true) - // Assign attributes + let previousAttributes = lastAttributes + + // Remove the last entry + removeLastEntry(lastAttributes: previousAttributes, keepWindow: true) + lastAttributes = attributes let entryContentView = EKContentView(withEntryDelegate: self) @@ -97,7 +99,7 @@ class EKRootViewController: UIViewController { } // Removes last entry - can keep the window 'ON' if necessary - private func removeLastEntry(keepWindow: Bool) { + private func removeLastEntry(lastAttributes: EKAttributes?, keepWindow: Bool) { guard let attributes = lastAttributes else { return } @@ -142,11 +144,28 @@ extension EKRootViewController: EntryContentViewDelegate { changeBackground(to: attributes.screenBackground, duration: attributes.entranceAnimation.totalDuration) } - func changeToInactive(withAttributes attributes: EKAttributes) { + func changeToInactive(withAttributes attributes: EKAttributes, pushOut: Bool) { guard EKAttributes.count <= 1 else { return } - changeBackground(to: .clear, duration: attributes.exitAnimation.totalDuration) + + let clear = { + self.changeBackground(to: .clear, duration: attributes.exitAnimation.totalDuration) + } + + guard pushOut else { + clear() + return + } + + guard let lastBackroundStyle = lastAttributes?.screenBackground else { + clear() + return + } + + if lastBackroundStyle != attributes.screenBackground { + clear() + } } private func changeBackground(to style: EKAttributes.BackgroundStyle, duration: TimeInterval) { diff --git a/Source/Model/EntryAttributes/EKAttributes+BackgroundStyle.swift b/Source/Model/EntryAttributes/EKAttributes+BackgroundStyle.swift index 0144f6fd..8150669c 100644 --- a/Source/Model/EntryAttributes/EKAttributes+BackgroundStyle.swift +++ b/Source/Model/EntryAttributes/EKAttributes+BackgroundStyle.swift @@ -11,13 +11,13 @@ import UIKit public extension EKAttributes { /** The background style property */ - public enum BackgroundStyle { + public enum BackgroundStyle: Equatable { /** Gradient background style */ public struct Gradient { - public let colors: [UIColor] - public let startPoint: CGPoint - public let endPoint: CGPoint + public var colors: [UIColor] + public var startPoint: CGPoint + public var endPoint: CGPoint public init(colors: [UIColor], startPoint: CGPoint, endPoint: CGPoint) { self.colors = colors @@ -40,5 +40,28 @@ public extension EKAttributes { /** Clear background style */ case clear + + /** == operator overload */ + public static func == (lhs: EKAttributes.BackgroundStyle, rhs: EKAttributes.BackgroundStyle) -> Bool { + switch (lhs, rhs) { + case (visualEffect(style: let leftStyle), visualEffect(style: let rightStyle)): + return leftStyle == rightStyle + case (color(color: let leftColor), color(color: let rightColor)): + return leftColor == rightColor + case (image(image: let leftImage), image(image: let rightImage)): + return leftImage == rightImage + case (gradient(gradient: let leftGradient), gradient(gradient: let rightGradient)): + for (leftColor, rightColor) in zip(leftGradient.colors, rightGradient.colors) { + guard leftColor == rightColor else { + return false + } + } + return leftGradient.startPoint == rightGradient.startPoint && leftGradient.endPoint == rightGradient.endPoint + case (clear, clear): + return true + default: + return false + } + } } } diff --git a/SwiftEntryKit.podspec b/SwiftEntryKit.podspec index d324cc29..01a6c959 100644 --- a/SwiftEntryKit.podspec +++ b/SwiftEntryKit.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'SwiftEntryKit' - s.version = '0.4.0' + s.version = '0.4.1' s.summary = 'A simple banner and pop-up displayer for iOS. Written in Swift.' s.platform = :ios s.ios.deployment_target = '9.0'