Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep Background Unchanged when 2 Consecutive Entry Screen Backgrounds… #47

Merged
merged 1 commit into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SwiftEntryKit.podspec.json

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

6 changes: 3 additions & 3 deletions Example/Pods/Manifest.lock

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

2 changes: 1 addition & 1 deletion Example/Pods/Target Support Files/SwiftEntryKit/Info.plist

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

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Source/Infra/EKContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
31 changes: 25 additions & 6 deletions Source/Infra/EKRootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down
31 changes: 27 additions & 4 deletions Source/Model/EntryAttributes/EKAttributes+BackgroundStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}
}
2 changes: 1 addition & 1 deletion SwiftEntryKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down