From 6fd409696974040301ecb313d42e4d2c5b2b9ce8 Mon Sep 17 00:00:00 2001 From: Jonathan Samudio Date: Wed, 16 May 2018 14:31:53 -0400 Subject: [PATCH 1/4] Updates frame of base view on layout subviews. --- Example/Pods/Pods.xcodeproj/project.pbxproj | 25 +++++++++++++------ Velar/Classes/Base View/BaseView.swift | 5 ++++ .../Helper Classes/ModalViewDismisser.swift | 8 +++--- .../Helper Classes/ViewPresenter.swift | 5 ++-- Velar/Classes/Protocols/Dismissable.swift | 4 ++- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index c6f0499..396e00d 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -72,7 +72,7 @@ 252B40698EB6CF75B0999889C1970E6C /* ConstraintGenerator.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ConstraintGenerator.swift; sourceTree = ""; }; 2993431868D196163AEDA9736653094F /* BackgroundOverlayView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BackgroundOverlayView.swift; sourceTree = ""; }; 2A6F4EBA562E6F25E09E65EA0EFE58C2 /* ViewAnimator.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ViewAnimator.swift; sourceTree = ""; }; - 2BB49A8AC6BEA6CF70C5ADE9CB2A34EB /* Pods_Velar_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_Velar_Tests.framework; path = "Pods-Velar_Tests.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + 2BB49A8AC6BEA6CF70C5ADE9CB2A34EB /* Pods_Velar_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Velar_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2BD12015CFD019CAD43AB6A94F43C13D /* Pods-Velar_Example-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-Velar_Example-frameworks.sh"; sourceTree = ""; }; 327196D0A7556969E472C4EC6AEC470D /* BackgroundOverlayDesignable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BackgroundOverlayDesignable.swift; sourceTree = ""; }; 327927A6C01B3125800703484D6B89DF /* Pods-Velar_Example-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-Velar_Example-acknowledgements.plist"; sourceTree = ""; }; @@ -86,19 +86,19 @@ 6604A7D69453B4569E4E4827FB9155A9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; 66FC2138E2CDBDBCE05916F5FE1E0AB8 /* Velar.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = Velar.xcconfig; sourceTree = ""; }; 67FA07061892BD633C7358DB9FCCC58A /* Velar.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.module; path = Velar.modulemap; sourceTree = ""; }; - 78316B7ABCCC0E92F5487E78C4C1EA5F /* Velar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Velar.framework; path = Velar.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 78316B7ABCCC0E92F5487E78C4C1EA5F /* Velar.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Velar.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7C774C1CDA58C07532ED4C0A8F20A047 /* CenterAdjustable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CenterAdjustable.swift; sourceTree = ""; }; 8124B626310EFDDF3E7355AA8651EB8E /* Pods-Velar_Tests-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-Velar_Tests-frameworks.sh"; sourceTree = ""; }; 84DD29C515BE76579011E2D47E2B63FA /* Velar-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Velar-prefix.pch"; sourceTree = ""; }; 85BF2B8E5F270FBA1981CC3E5044D384 /* AlphaAnimatable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AlphaAnimatable.swift; sourceTree = ""; }; 8757ED51BB214547B3F44B439F81E13E /* PanGestureAdderDelegate.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = PanGestureAdderDelegate.swift; sourceTree = ""; }; 90FE00093AD1427133DC5583109D9CE1 /* Pods-Velar_Example.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.module; path = "Pods-Velar_Example.modulemap"; sourceTree = ""; }; - 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 93A4A3777CF96A4AAC1D13BA6DCCEA73 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 93A678548D0028F102A244342DB20841 /* ViewAnimatable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ViewAnimatable.swift; sourceTree = ""; }; 96B30B6244CC15381F1F9235FCE8A4E6 /* CenterAdjuster.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CenterAdjuster.swift; sourceTree = ""; }; 98BB4F1C2DA11094F5E5D6AA0CA9C1C4 /* Pods-Velar_Tests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-Velar_Tests-acknowledgements.plist"; sourceTree = ""; }; 9DA0F323C1654FCE8FBD8689BD038D26 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - A21E0BFA3BE31AF68BE84622854603D7 /* Pods_Velar_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_Velar_Example.framework; path = "Pods-Velar_Example.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + A21E0BFA3BE31AF68BE84622854603D7 /* Pods_Velar_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Velar_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A85CD989AB656923CA6F015E76B12967 /* ViewVerticalMover.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ViewVerticalMover.swift; sourceTree = ""; }; A886E0290FC6B2AC45B1E3C239F20D14 /* Pods-Velar_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Velar_Example.release.xcconfig"; sourceTree = ""; }; B29576D329F73114C6A80AD6947FFBF6 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -111,13 +111,13 @@ CC7E0E3FE6353576A0E1678F051D03FF /* PanGestureAdder.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = PanGestureAdder.swift; sourceTree = ""; }; CDB5B586F8E0183D36C490B3E3D11A41 /* Pods-Velar_Example-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-Velar_Example-umbrella.h"; sourceTree = ""; }; D03868FC5558E53DCD19F4397A299753 /* UIViewExtension.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = UIViewExtension.swift; sourceTree = ""; }; - D57AFB6336BC820D0E3B058A3E90F89A /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; path = README.md; sourceTree = ""; }; - DBDAC562034EF2C5CAD41A1DD0F7C935 /* Velar.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; lastKnownFileType = text; path = Velar.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + D57AFB6336BC820D0E3B058A3E90F89A /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; + DBDAC562034EF2C5CAD41A1DD0F7C935 /* Velar.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; path = Velar.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; DD1F676B4DE4906AE4D1EADA64AA6968 /* BaseView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = BaseView.swift; sourceTree = ""; }; E0BF9D632C210BFD88F6E8AD2A6E3D58 /* Pods-Velar_Tests-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-Velar_Tests-dummy.m"; sourceTree = ""; }; E1AE1CAD0748B61B8B8F80C1389B8968 /* Pods-Velar_Tests-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-Velar_Tests-resources.sh"; sourceTree = ""; }; E36FFF24AF2C1C2B41B02816F7D505D3 /* Velar-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Velar-dummy.m"; sourceTree = ""; }; - E97F120ED1B982A738E4B0A6EE60910D /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; path = LICENSE; sourceTree = ""; }; + E97F120ED1B982A738E4B0A6EE60910D /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; EB5E91442065B1F55131AB65225FEC28 /* CenterMovable.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = CenterMovable.swift; sourceTree = ""; }; EC6FA60CE47306B1A3391727CDE8DAEA /* ViewConstraintGenerator.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ViewConstraintGenerator.swift; sourceTree = ""; }; F00A6D27208C28CE1DA59DA14A8E93D0 /* Pods-Velar_Example-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-Velar_Example-resources.sh"; sourceTree = ""; }; @@ -315,6 +315,7 @@ isa = PBXGroup; children = ( 35947F9B8CAD33F5987001C8B7A235FA /* AlphaAnimator.swift */, + C13B79716F25B7F54DDD20188061E757 /* ViewPresenter.swift */, 96B30B6244CC15381F1F9235FCE8A4E6 /* CenterAdjuster.swift */, FA08FD6E026CF1949879B904348336ED /* ConstraintAnimator.swift */, 46F009BAF798222A976C50C9B2D06874 /* ModalViewDismisser.swift */, @@ -322,7 +323,6 @@ 107F3FD2ECF1E7FB2D25C32F38FE4BD3 /* VerticalCenterMover.swift */, 2A6F4EBA562E6F25E09E65EA0EFE58C2 /* ViewAnimator.swift */, EC6FA60CE47306B1A3391727CDE8DAEA /* ViewConstraintGenerator.swift */, - C13B79716F25B7F54DDD20188061E757 /* ViewPresenter.swift */, A85CD989AB656923CA6F015E76B12967 /* ViewVerticalMover.swift */, ); name = "Helper Classes"; @@ -462,6 +462,11 @@ attributes = { LastSwiftUpdateCheck = 0930; LastUpgradeCheck = 0930; + TargetAttributes = { + 6E30391101560030AAE553FE5E74EF71 = { + LastSwiftMigration = 0930; + }; + }; }; buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 3.2"; @@ -654,6 +659,7 @@ baseConfigurationReference = A886E0290FC6B2AC45B1E3C239F20D14 /* Pods-Velar_Example.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; @@ -677,6 +683,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -754,6 +761,7 @@ baseConfigurationReference = F6B68A2FA048C930710394C40CCC0BBA /* Pods-Velar_Example.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; @@ -778,6 +786,7 @@ SKIP_INSTALL = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; diff --git a/Velar/Classes/Base View/BaseView.swift b/Velar/Classes/Base View/BaseView.swift index 675f909..5eecb35 100644 --- a/Velar/Classes/Base View/BaseView.swift +++ b/Velar/Classes/Base View/BaseView.swift @@ -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 { diff --git a/Velar/Classes/Helper Classes/ModalViewDismisser.swift b/Velar/Classes/Helper Classes/ModalViewDismisser.swift index aa27410..726ba0c 100644 --- a/Velar/Classes/Helper Classes/ModalViewDismisser.swift +++ b/Velar/Classes/Helper Classes/ModalViewDismisser.swift @@ -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 diff --git a/Velar/Classes/Helper Classes/ViewPresenter.swift b/Velar/Classes/Helper Classes/ViewPresenter.swift index 94dbbdc..066382c 100644 --- a/Velar/Classes/Helper Classes/ViewPresenter.swift +++ b/Velar/Classes/Helper Classes/ViewPresenter.swift @@ -11,7 +11,7 @@ import UIKit internal class ViewPresenter: Presentable { var view: UIView? = nil - + private var viewConstraintGenerator: ConstraintGenerator private var verticalMover: VerticalMovable @@ -19,6 +19,7 @@ internal class ViewPresenter: Presentable { private weak var superView: UIView? init(superView: UIView?, viewConstraintGenerator: ConstraintGenerator, verticalMover: VerticalMovable) { + self.viewConstraintGenerator = viewConstraintGenerator self.verticalMover = verticalMover self.superView = superView @@ -26,7 +27,7 @@ internal class ViewPresenter: Presentable { func present(view: UIView, animate: Bool) { self.view = view - + viewConstraintGenerator.constraint(subView: view, top: 0, leading: 0, bottom: 0, trailing: 0) superView?.layoutIfNeeded() diff --git a/Velar/Classes/Protocols/Dismissable.swift b/Velar/Classes/Protocols/Dismissable.swift index 3fe8136..f6c3fca 100644 --- a/Velar/Classes/Protocols/Dismissable.swift +++ b/Velar/Classes/Protocols/Dismissable.swift @@ -11,6 +11,8 @@ import Foundation internal protocol Dismissable { var canDismiss: Bool { get } - + + var viewHeight: CGFloat { get set } + func dismiss(animate: Bool, completion: (()->())?) } From 6cd27ac9cbe52c9e20ca010f1b86ec7e6515e361 Mon Sep 17 00:00:00 2001 From: Jonathan Samudio Date: Wed, 16 May 2018 14:35:46 -0400 Subject: [PATCH 2/4] Updated the animation duration of the view presenter. --- Velar/Classes/VelarPresenter/VelarPresenter.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Velar/Classes/VelarPresenter/VelarPresenter.swift b/Velar/Classes/VelarPresenter/VelarPresenter.swift index f89901f..7962584 100644 --- a/Velar/Classes/VelarPresenter/VelarPresenter.swift +++ b/Velar/Classes/VelarPresenter/VelarPresenter.swift @@ -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. From 1d3b8c5c518ff66a9812bdb74686e249fbde4b63 Mon Sep 17 00:00:00 2001 From: Jonathan Samudio Date: Wed, 16 May 2018 14:44:41 -0400 Subject: [PATCH 3/4] Added check for taps with in the modal view. --- Velar/Classes/VelarPresenter/VelarPresenter.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Velar/Classes/VelarPresenter/VelarPresenter.swift b/Velar/Classes/VelarPresenter/VelarPresenter.swift index 7962584..9cb97f2 100644 --- a/Velar/Classes/VelarPresenter/VelarPresenter.swift +++ b/Velar/Classes/VelarPresenter/VelarPresenter.swift @@ -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) + } } } From 759f4c2b6b2e0c8bd96f644d3ce2d0e8153bc7b4 Mon Sep 17 00:00:00 2001 From: Jonathan Samudio Date: Wed, 16 May 2018 14:49:53 -0400 Subject: [PATCH 4/4] Bumped version number. --- Example/Velar.xcodeproj/project.pbxproj | 2 ++ Velar.podspec | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Example/Velar.xcodeproj/project.pbxproj b/Example/Velar.xcodeproj/project.pbxproj index 6c1dfcd..92c2be9 100644 --- a/Example/Velar.xcodeproj/project.pbxproj +++ b/Example/Velar.xcodeproj/project.pbxproj @@ -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)", @@ -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)", diff --git a/Velar.podspec b/Velar.podspec index a37819f..4624b6c 100644 --- a/Velar.podspec +++ b/Velar.podspec @@ -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