Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
![]() |
e565726c9f | |
![]() |
ab8559e4f7 | |
![]() |
f3fabcdbfe | |
![]() |
d252480d03 | |
![]() |
e72c2cb6e3 | |
![]() |
a0706d3445 | |
![]() |
0f72a6bda5 | |
![]() |
4390cecc91 | |
![]() |
51375f6cff | |
![]() |
3123be1c7b | |
![]() |
af45b500f0 |
|
@ -1 +1 @@
|
|||
4.0
|
||||
5.0
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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;
|
||||
|
|
Binary file not shown.
|
@ -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>
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue