Compare commits

...

11 Commits

Author SHA1 Message Date
Shial e565726c9f [0.2.0] Update to swift 5 2019-03-26 14:59:28 +11:00
Shial ab8559e4f7 [0.1.13] make properties mandatory 2018-10-11 14:06:10 +11:00
Shial f3fabcdbfe [0.1.12] Move animation duration and window key component as a deciding properties of controller 2018-10-11 13:41:23 +11:00
Shial d252480d03 [0.1.11] Swift 4.2 2018-10-03 09:16:35 +10:00
Shial e72c2cb6e3 update to swift 4.2 2018-09-19 14:34:45 +10:00
Shial a0706d3445 Conver window level 2018-09-19 12:11:23 +10:00
Shial 0f72a6bda5 update to swift 4.2 2018-09-19 12:01:04 +10:00
Shial 4390cecc91 [0.1.9] updade cocoapods 2018-06-21 15:27:56 +10:00
Shial 51375f6cff [0.1.8] Check 2018-06-21 15:18:04 +10:00
Shial 3123be1c7b [0.1.8] Update threads 2018-06-21 15:15:03 +10:00
Shial af45b500f0 [0.1.7] Update podspec 2018-06-21 14:15:18 +10:00
8 changed files with 49 additions and 37 deletions

View File

@ -1 +1 @@
4.0
5.0

View File

@ -1,4 +1,4 @@
// swift-tools-version:4.0
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

View File

@ -1,6 +1,8 @@
# SWindow
<p align="center">
<img src="https://img.shields.io/badge/Swift-5.0-brightgreen.svg" alt="Language" />
</a>
<a href="https://raw.githubusercontent.com/shial4/SWindow/master/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" />
</a>
@ -97,7 +99,7 @@ Clone the repo and drag the file `SWindow.swift` into your Xcode project.
**Swift Package Manager:**
Add the line `.Package(url: "https://github.com/shial4/SWindow.git", majorVersion: 0, minor: 1)` to your `Package.swift`
Add the line `.package(url: "https://github.com/shial4/SWindow.git", from: "0.1.10")` to your `Package.swift`
## ⭐ Contributing

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SWindow"
s.version = "0.1.6"
s.version = "0.2.0"
s.summary = "Swift view controller presenter."
s.description = <<-DESC
SWindow is an easy to use Swift windows manager. Don't spend hours writing your code to present and dismiss modal view controllers, stop wasting your time on debugging why your modal presentation disapear. Without issues, simple and safe present your controller!

View File

@ -127,13 +127,19 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0930;
TargetAttributes = {
"SWindow::SWindow" = {
LastSwiftMigration = 1020;
};
};
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "SWindow" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = OBJ_5;
productRefGroup = OBJ_11 /* Products */;
@ -171,7 +177,7 @@
buildSettings = {
LD = /usr/bin/true;
OTHER_SWIFT_FLAGS = "-swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
@ -180,7 +186,7 @@
buildSettings = {
LD = /usr/bin/true;
OTHER_SWIFT_FLAGS = "-swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
@ -201,7 +207,7 @@
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGET_NAME = SWindow;
};
name = Debug;
@ -223,7 +229,7 @@
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGET_NAME = SWindow;
};
name = Release;

View File

@ -19,6 +19,11 @@
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>SWindowPackageDescription.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>

View File

@ -41,7 +41,7 @@ public class SModal {
static let modalWindow: UIWindow = {
let window = UIWindow(frame: UIScreen.main.bounds)
window.backgroundColor = .clear
window.windowLevel = windowLevel
window.windowLevel = UIWindow.Level(windowLevel)
window.isHidden = true
return window
}()
@ -49,33 +49,15 @@ public class SModal {
/// stack to store controllers in queue
static var stack: [SModalPresentation] = []
/// Boolean value defining if window upon presentation should become a key window.
public static var shouldMakeKey: Bool {
return false
}
/// window level on which should appear on top of windows
public static var windowLevel: UIWindowLevel {
return UIWindowLevelAlert - 1
}
/// animation duration used to animated transition between presentations
public static var animationDuration: TimeInterval {
return 0.2
public static var windowLevel: CGFloat {
return UIWindow.Level.alert.rawValue - 1
}
/// Discard curent root view controller and hide window
fileprivate static func dropRootViewController() {
modalWindow.isHidden = true
modalWindow.rootViewController = nil
modalWindow.resignKey()
}
/// Make our window key window.
fileprivate static func makeKey() {
if shouldMakeKey {
SModal.modalWindow.makeKey()
}
}
}
@ -101,6 +83,10 @@ public protocol SModalPresentation: class, SModalStack {
/// - animated: Boolean value idicating if operation should be animated
/// - completion: completion block called after dismiss procedure
func sWithdraw(animated: Bool, completion: (() -> Void)?)
/// animation duration used to animated transition between presentations
var animationDuration: TimeInterval { get }
/// Boolean value defining if window upon presentation should become a key window.
var shouldMakeKey: Bool { get }
}
// MARK: - Default implementation of Modal Presentation protocol
@ -145,18 +131,22 @@ extension SModalPresentation where Self: UIViewController {
DispatchQueue.main.async {
if animated {
SModal.modalWindow.isHidden = false
UIView.animate(withDuration: SModal.animationDuration, animations: {
UIView.animate(withDuration: controller.animationDuration, animations: {
SModal.modalWindow.rootViewController = controller
SModal.makeKey()
SModal.modalWindow.alpha = 1
}, completion: { completed in
if controller.shouldMakeKey {
SModal.modalWindow.makeKey()
}
completion?()
})
} else {
SModal.modalWindow.rootViewController = controller
SModal.makeKey()
SModal.modalWindow.alpha = 1
SModal.modalWindow.isHidden = false
if controller.shouldMakeKey {
SModal.modalWindow.makeKey()
}
completion?()
}
}
@ -169,15 +159,19 @@ extension SModalPresentation where Self: UIViewController {
/// - completion: Completion block called on the end of operation
public func sPresent(animated: Bool = false, completion: (() -> Void)? = nil) {
guard let currentPresented = SModal.modalWindow.rootViewController else {
DispatchQueue.main.async {
func presentController() {
SModal.modalWindow.rootViewController = self
SModal.makeKey()
if self.shouldMakeKey {
SModal.modalWindow.makeKey()
}
if animated {
SModal.modalWindow.alpha = 0
SModal.modalWindow.isHidden = false
UIView.animate(withDuration: SModal.animationDuration, animations: {
UIView.animate(withDuration: self.animationDuration, animations: {
SModal.modalWindow.alpha = 1
}, completion: { completed in
SModal.modalWindow.alpha = 1
SModal.modalWindow.isHidden = false
completion?()
})
} else {
@ -186,6 +180,11 @@ extension SModalPresentation where Self: UIViewController {
completion?()
}
}
if Thread.isMainThread {
presentController()
} else {
DispatchQueue.main.sync { presentController() }
}
return
}
SModal.stack.append(self)
@ -214,7 +213,7 @@ extension SModalPresentation where Self: UIViewController {
if SModal.modalWindow.rootViewController === self {
if animated {
SModal.modalWindow.alpha = 1
UIView.animate(withDuration: SModal.animationDuration, animations: {
UIView.animate(withDuration: self.animationDuration, animations: {
SModal.modalWindow.alpha = 0
}, completion: { completed in
SModal.dropRootViewController()