Skip to content

Commit

Permalink
Merge pull request #2 from prolificinteractive/bugfix/instant_hide_an…
Browse files Browse the repository at this point in the history
…imation

[Bugfix] Instant Hide Animation
  • Loading branch information
jgsamudio authored May 16, 2018
2 parents 77bdfd7 + 759f4c2 commit fbd6fb3
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 19 deletions.
25 changes: 17 additions & 8 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

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

2 changes: 2 additions & 0 deletions Example/Velar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = B74458D812EA17F503470BCD /* Pods-Velar_Tests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -720,6 +721,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = BB4E23AEF5C67035F11856B9 /* Pods-Velar_Tests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand Down
2 changes: 1 addition & 1 deletion Velar.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Velar'
s.version = '0.1.2'
s.version = '0.1.3'
s.summary = 'A custom alert view presenter.'

s.description = <<-DESC
Expand Down
5 changes: 5 additions & 0 deletions Velar/Classes/Base View/BaseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ internal class BaseView: UIView {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()
modalViewDismisser.viewHeight = frame.height
}
}

private extension BaseView {
Expand Down
8 changes: 4 additions & 4 deletions Velar/Classes/Helper Classes/ModalViewDismisser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ internal class ModalViewDismisser: Dismissable {
var canDismiss: Bool {
return (modalView.center.y - (viewHeight / 2)) > dismissThreshold
}


var viewHeight: CGFloat

private var modalView: UIView

private var viewHeight: CGFloat


private var dismissThreshold: CGFloat

private var verticalMover: VerticalMovable
Expand Down
5 changes: 3 additions & 2 deletions Velar/Classes/Helper Classes/ViewPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ import UIKit
internal class ViewPresenter: Presentable {

var view: UIView? = nil

private var viewConstraintGenerator: ConstraintGenerator

private var verticalMover: VerticalMovable

private weak var superView: UIView?

init(superView: UIView?, viewConstraintGenerator: ConstraintGenerator, verticalMover: VerticalMovable) {

self.viewConstraintGenerator = viewConstraintGenerator
self.verticalMover = verticalMover
self.superView = superView
}

func present(view: UIView, animate: Bool) {
self.view = view

viewConstraintGenerator.constraint(subView: view, top: 0, leading: 0, bottom: 0, trailing: 0)

superView?.layoutIfNeeded()
Expand Down
4 changes: 3 additions & 1 deletion Velar/Classes/Protocols/Dismissable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Foundation
internal protocol Dismissable {

var canDismiss: Bool { get }


var viewHeight: CGFloat { get set }

func dismiss(animate: Bool, completion: (()->())?)
}
8 changes: 5 additions & 3 deletions Velar/Classes/VelarPresenter/VelarPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class VelarPresenter {

/// Animator for changing view alpha.
public var alphaAnimator: AlphaAnimatable = {
return AlphaAnimator(showAlpha: 1, hideAlpha: 0, duration: 0.25)
return AlphaAnimator(showAlpha: 1, hideAlpha: 0, duration: 0.35)
}()

/// The speed of the show and hide modal animation.
Expand Down Expand Up @@ -134,8 +134,10 @@ extension VelarPresenter: PanGestureAdderDelegate {

private extension VelarPresenter {

@objc func backgroundViewSelected() {
hide(animate: true)
@objc func backgroundViewSelected(recognizer: UIGestureRecognizer) {
if !baseView.modalView.frame.contains(recognizer.location(in: baseView)) {
hide(animate: true)
}
}
}

Expand Down

0 comments on commit fbd6fb3

Please sign in to comment.