Skip to content

Commit

Permalink
[0.1.6] perform operation on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
shial4 committed Jun 21, 2018
1 parent 82fa6de commit 4a4ce1f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions SWindow.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = "SWindow"
s.version = "0.1.4"
s.version = "0.1.6"
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!
DESC
s.homepage = "https://github.com/shial4/SWindow.git"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Szymon Lorenz" => "[email protected]" }
s.social_media_url = "https://twitter.com/shial_4"
s.social_media_url = "https://www.facebook.com/SLSolutionsAU/"
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/shial4/SWindow.git", :tag => s.version.to_s }
s.source_files = "Sources/**/*.swift"
Expand Down
Binary file not shown.
53 changes: 28 additions & 25 deletions Sources/SWindow/SWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,24 @@ extension SModalPresentation where Self: UIViewController {
/// - animated: Boolean value idicating if operation should be animated
/// - completion: Completion block called on the end of operation
public func sReplace<T: UIViewController>(with controller: T, animated: Bool = false, completion: (() -> Void)? = nil) where T: SModalPresentation {
if animated {
SModal.modalWindow.isHidden = false
UIView.animate(withDuration: SModal.animationDuration, animations: {
DispatchQueue.main.sync {
if animated {
SModal.modalWindow.isHidden = false
UIView.animate(withDuration: SModal.animationDuration, animations: {
SModal.modalWindow.rootViewController = controller
SModal.makeKey()
SModal.modalWindow.alpha = 1
}, completion: { completed in
completion?()
})
} else {
SModal.modalWindow.rootViewController = controller
SModal.makeKey()
SModal.modalWindow.alpha = 1
}, completion: { completed in
SModal.modalWindow.isHidden = false
completion?()
})
} else {
SModal.modalWindow.rootViewController = controller
SModal.makeKey()
SModal.modalWindow.alpha = 1
SModal.modalWindow.isHidden = false
completion?()
}
}

}

/// Default implementation, Object is presented if avaiable or placed in stack. If other object is current presented but can be dissmised SModal is replacing him the next one from stack.
Expand All @@ -168,20 +169,22 @@ 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 {
SModal.modalWindow.rootViewController = self
SModal.makeKey()
if animated {
SModal.modalWindow.alpha = 0
SModal.modalWindow.isHidden = false
UIView.animate(withDuration: SModal.animationDuration, animations: {
DispatchQueue.main.sync {
SModal.modalWindow.rootViewController = self
SModal.makeKey()
if animated {
SModal.modalWindow.alpha = 0
SModal.modalWindow.isHidden = false
UIView.animate(withDuration: SModal.animationDuration, animations: {
SModal.modalWindow.alpha = 1
}, completion: { completed in
completion?()
})
} else {
SModal.modalWindow.alpha = 1
}, completion: { completed in
SModal.modalWindow.isHidden = false
completion?()
})
} else {
SModal.modalWindow.alpha = 1
SModal.modalWindow.isHidden = false
completion?()
}
}
return
}
Expand All @@ -207,7 +210,7 @@ extension SModalPresentation where Self: UIViewController {
completion?()
}
}
DispatchQueue.main.async {
DispatchQueue.main.sync {
if SModal.modalWindow.rootViewController === self {
if animated {
SModal.modalWindow.alpha = 1
Expand Down

0 comments on commit 4a4ce1f

Please sign in to comment.