Skip to content

Commit 39d367d

Browse files
committed
Keep Background Unchanged when 2 Consecutive Entry Screen Backgrounds Match #46
1 parent 19dcf0d commit 39d367d

File tree

10 files changed

+74
-26
lines changed

10 files changed

+74
-26
lines changed

CHANGELOG.md

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

4+
## 0.4.1
5+
6+
### Issues Handled
7+
8+
[Keep Background Unchanged when 2 Consecutive Entry Screen Backgrounds Match #46](https://github.com/huri000/SwiftEntryKit/issues/46)
9+
410
## 0.4.0
511

612
### Features

Example/Podfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PODS:
22
- Nimble (7.0.2)
33
- Quick (1.2.0)
44
- QuickLayout (2.0.2)
5-
- SwiftEntryKit (0.4.0):
5+
- SwiftEntryKit (0.4.1):
66
- QuickLayout (= 2.0.2)
77

88
DEPENDENCIES:
@@ -24,8 +24,8 @@ SPEC CHECKSUMS:
2424
Nimble: bfe1f814edabba69ff145cb1283e04ed636a67f2
2525
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
2626
QuickLayout: a730730b646b231fd4ef7cffaeb1e81fe0e1ca92
27-
SwiftEntryKit: 89fdd4a15ae213d9b9bbcf36a319d2d3696f5f13
27+
SwiftEntryKit: ea33b0916c8071f6d61b5d6c0aa34a09e1ee315a
2828

2929
PODFILE CHECKSUM: edd6c2af5cc390dbf823427759474ab6c303ec9e
3030

31-
COCOAPODS: 1.5.2
31+
COCOAPODS: 1.5.3

Example/Pods/Local Podspecs/SwiftEntryKit.podspec.json

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

Example/Pods/Manifest.lock

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

Example/Pods/Target Support Files/SwiftEntryKit/Info.plist

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

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ source 'https://github.com/cocoapods/specs.git'
127127
platform :ios, '9.0'
128128
use_frameworks!
129129

130-
pod 'SwiftEntryKit', '0.4.0'
130+
pod 'SwiftEntryKit', '0.4.1'
131131
```
132132

133133
Then, run the following command:
@@ -150,7 +150,7 @@ $ brew install carthage
150150
To integrate SwiftEntryKit into your Xcode project using Carthage, specify the following in your `Cartfile`:
151151

152152
```ogdl
153-
github "huri000/SwiftEntryKit" == 0.4.0
153+
github "huri000/SwiftEntryKit" == 0.4.1
154154
```
155155

156156
## Usage

Source/Infra/EKContentView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import QuickLayout
1111

1212
protocol EntryContentViewDelegate: class {
1313
func changeToActive(withAttributes attributes: EKAttributes)
14-
func changeToInactive(withAttributes attributes: EKAttributes)
14+
func changeToInactive(withAttributes attributes: EKAttributes, pushOut: Bool)
1515
}
1616

1717
class EKContentView: UIView {
@@ -319,7 +319,7 @@ class EKContentView: UIView {
319319
}
320320

321321
outDispatchWorkItem?.cancel()
322-
entryDelegate?.changeToInactive(withAttributes: attributes)
322+
entryDelegate?.changeToInactive(withAttributes: attributes, pushOut: pushOut)
323323

324324
if case .animated(animation: let animation) = attributes.popBehavior, pushOut {
325325
animateOut(with: animation, outTranslationType: .pop)
@@ -439,7 +439,7 @@ class EKContentView: UIView {
439439
// Removes the view promptly - DOES NOT animate out
440440
func removePromptly(keepWindow: Bool = true) {
441441
outDispatchWorkItem?.cancel()
442-
entryDelegate?.changeToInactive(withAttributes: attributes)
442+
entryDelegate?.changeToInactive(withAttributes: attributes, pushOut: false)
443443
removeFromSuperview(keepWindow: keepWindow)
444444
}
445445

@@ -632,7 +632,7 @@ extension EKContentView {
632632

633633
private func stretchOut(usingSwipe type: OutTranslation, duration: TimeInterval) {
634634
outDispatchWorkItem?.cancel()
635-
entryDelegate?.changeToInactive(withAttributes: attributes)
635+
entryDelegate?.changeToInactive(withAttributes: attributes, pushOut: false)
636636

637637
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 4, options: [.allowUserInteraction, .beginFromCurrentState], animations: {
638638
self.translateOut(withType: type)

Source/Infra/EKRootViewController.swift

+25-6
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ class EKRootViewController: UIViewController {
7575
// Extract the attributes struct
7676
let attributes = entryView.attributes
7777

78-
// Remove the last entry
79-
removeLastEntry(keepWindow: true)
80-
8178
// Assign attributes
79+
let previousAttributes = lastAttributes
80+
81+
// Remove the last entry
82+
removeLastEntry(lastAttributes: previousAttributes, keepWindow: true)
83+
8284
lastAttributes = attributes
8385

8486
let entryContentView = EKContentView(withEntryDelegate: self)
@@ -97,7 +99,7 @@ class EKRootViewController: UIViewController {
9799
}
98100

99101
// Removes last entry - can keep the window 'ON' if necessary
100-
private func removeLastEntry(keepWindow: Bool) {
102+
private func removeLastEntry(lastAttributes: EKAttributes?, keepWindow: Bool) {
101103
guard let attributes = lastAttributes else {
102104
return
103105
}
@@ -142,11 +144,28 @@ extension EKRootViewController: EntryContentViewDelegate {
142144
changeBackground(to: attributes.screenBackground, duration: attributes.entranceAnimation.totalDuration)
143145
}
144146

145-
func changeToInactive(withAttributes attributes: EKAttributes) {
147+
func changeToInactive(withAttributes attributes: EKAttributes, pushOut: Bool) {
146148
guard EKAttributes.count <= 1 else {
147149
return
148150
}
149-
changeBackground(to: .clear, duration: attributes.exitAnimation.totalDuration)
151+
152+
let clear = {
153+
self.changeBackground(to: .clear, duration: attributes.exitAnimation.totalDuration)
154+
}
155+
156+
guard pushOut else {
157+
clear()
158+
return
159+
}
160+
161+
guard let lastBackroundStyle = lastAttributes?.screenBackground else {
162+
clear()
163+
return
164+
}
165+
166+
if lastBackroundStyle != attributes.screenBackground {
167+
clear()
168+
}
150169
}
151170

152171
private func changeBackground(to style: EKAttributes.BackgroundStyle, duration: TimeInterval) {

Source/Model/EntryAttributes/EKAttributes+BackgroundStyle.swift

+27-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import UIKit
1111
public extension EKAttributes {
1212

1313
/** The background style property */
14-
public enum BackgroundStyle {
14+
public enum BackgroundStyle: Equatable {
1515

1616
/** Gradient background style */
1717
public struct Gradient {
18-
public let colors: [UIColor]
19-
public let startPoint: CGPoint
20-
public let endPoint: CGPoint
18+
public var colors: [UIColor]
19+
public var startPoint: CGPoint
20+
public var endPoint: CGPoint
2121

2222
public init(colors: [UIColor], startPoint: CGPoint, endPoint: CGPoint) {
2323
self.colors = colors
@@ -40,5 +40,28 @@ public extension EKAttributes {
4040

4141
/** Clear background style */
4242
case clear
43+
44+
/** == operator overload */
45+
public static func == (lhs: EKAttributes.BackgroundStyle, rhs: EKAttributes.BackgroundStyle) -> Bool {
46+
switch (lhs, rhs) {
47+
case (visualEffect(style: let leftStyle), visualEffect(style: let rightStyle)):
48+
return leftStyle == rightStyle
49+
case (color(color: let leftColor), color(color: let rightColor)):
50+
return leftColor == rightColor
51+
case (image(image: let leftImage), image(image: let rightImage)):
52+
return leftImage == rightImage
53+
case (gradient(gradient: let leftGradient), gradient(gradient: let rightGradient)):
54+
for (leftColor, rightColor) in zip(leftGradient.colors, rightGradient.colors) {
55+
guard leftColor == rightColor else {
56+
return false
57+
}
58+
}
59+
return leftGradient.startPoint == rightGradient.startPoint && leftGradient.endPoint == rightGradient.endPoint
60+
case (clear, clear):
61+
return true
62+
default:
63+
return false
64+
}
65+
}
4366
}
4467
}

SwiftEntryKit.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SwiftEntryKit'
11-
s.version = '0.4.0'
11+
s.version = '0.4.1'
1212
s.summary = 'A simple banner and pop-up displayer for iOS. Written in Swift.'
1313
s.platform = :ios
1414
s.ios.deployment_target = '9.0'

0 commit comments

Comments
 (0)