Compare commits

...

8 Commits

Author SHA1 Message Date
jonkykong 2e8740a91e Update podspec 2019-08-07 01:39:23 -07:00
jonkykong b387ef2dd7 Merge branch 'pr/524' into 6.1.4
* pr/524:
  Refactor
  Added isHidden property for public usage
2019-08-07 01:38:41 -07:00
jonkykong 22596320a3 Refactor 2019-08-07 01:38:28 -07:00
jonkykong 9363b747d1 Push logic fix 2019-08-07 01:31:22 -07:00
Mykola Vaniurskyi baae6186d7 Added isHidden property for public usage 2019-08-06 16:10:20 +03:00
jonkykong c5f80f954c Updated podspec version 2019-08-05 00:30:31 -07:00
jonkykong 493fa9a7a1 Updated podspec for swift version 2019-08-05 00:29:25 -07:00
jonkykong 2de8d7f758 Minor refactoring 2019-08-02 03:12:04 -07:00
5 changed files with 85 additions and 108 deletions
-1
View File
@@ -46,7 +46,6 @@ internal extension UIViewController {
}
}
// Indicates if the menu is anywhere in the view hierarchy, even if covered by another view controller.
@objc var isHidden: Bool {
return presentingViewController == nil
}
+6 -4
View File
@@ -7,10 +7,11 @@
import Foundation
internal protocol InitializableClass: class {
public protocol InitializableClass: class {
init()
}
extension InitializableClass {
public extension InitializableClass {
init(_ block: (Self) -> Void) {
self.init()
@@ -23,10 +24,11 @@ extension InitializableClass {
}
}
internal protocol InitializableStruct {
public protocol InitializableStruct {
init()
}
internal extension InitializableStruct {
public extension InitializableStruct {
init(_ block: (inout Self) -> Void) {
self.init()
block(&self)
+2 -7
View File
@@ -8,7 +8,7 @@
import Foundation
@objcMembers
open class SideMenuPresentationStyle {
open class SideMenuPresentationStyle: InitializableClass {
/// Background color behind the views and status bar color
public var backgroundColor: UIColor = .black
/// The starting alpha value of the menu before it appears
@@ -36,12 +36,7 @@ open class SideMenuPresentationStyle {
/// The strength of the parallax effect on the presenting view once the menu is displayed.
public var presentingParallaxStrength: CGSize = .zero
public init() {}
public convenience init(_ block: (SideMenuPresentationStyle) -> Void) {
self.init()
block(self)
}
required public init() {}
/// This method is called just before the presentation transition begins. Use this to setup any animations. The super method does not need to be called.
func presentationTransitionWillBegin(to presentedViewController: UIViewController, from presentingViewController: UIViewController) {}
@@ -27,7 +27,7 @@ internal protocol UISideMenuNavigationControllerTransitionDelegate: class {
func sideMenuTransitionDidDismiss(menu: Menu)
}
public struct SideMenuSettings: MenuModel {
public struct SideMenuSettings: MenuModel, InitializableStruct {
public var allowPushOfSameClassTwice: Bool = true
public var alwaysAnimate: Bool = true
public var animationOptions: UIView.AnimationOptions = .curveEaseInOut
@@ -56,11 +56,6 @@ public struct SideMenuSettings: MenuModel {
public var usingSpringWithDamping: CGFloat = 1
public init() {}
public init(_ block: (inout SideMenuSettings) -> Void) {
self.init()
block(&self)
}
}
internal typealias Menu = UISideMenuNavigationController
@@ -253,13 +248,77 @@ open class UISideMenuNavigationController: UINavigationController {
}
override open func pushViewController(_ viewController: UIViewController, animated: Bool) {
let push = shouldPushViewController(viewController: viewController, animated: animated) { [weak self] _ in
self?.foundViewController = nil
guard viewControllers.count > 0 && pushStyle != .subMenu else {
// NOTE: pushViewController is called by init(rootViewController: UIViewController)
// so we must perform the normal super method in this case
return super.pushViewController(viewController, animated: animated)
}
if push {
super.pushViewController(viewController, animated: animated)
let splitViewController = presentingViewController as? UISplitViewController
let tabBarController = presentingViewController as? UITabBarController
let potentialNavigationController = (splitViewController?.viewControllers.first ?? tabBarController?.selectedViewController) ?? presentingViewController
guard let navigationController = potentialNavigationController as? UINavigationController else {
return Print.warning(.cannotPush, arguments: String(describing: potentialNavigationController.self), required: true)
}
// To avoid overlapping dismiss & pop/push calls, create a transaction block where the menu
// is dismissed after showing the appropriate screen
CATransaction.begin()
defer { CATransaction.commit() }
if dismissOnPush {
let animated = animated || alwaysAnimate
if animated {
let areAnimationsEnabled = UIView.areAnimationsEnabled
UIView.setAnimationsEnabled(true)
transitionController?.transition(presenting: false, animated: animated, alongsideTransition: { [weak self] in
guard let self = self else { return }
self.activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
}, completion: { [weak self] _ in
guard let self = self else { return }
self.activeDelegate?.sideMenuDidDisappear?(menu: self, animated: animated)
self.dismiss(animated: false, completion: nil)
self.foundViewController = nil
})
UIView.setAnimationsEnabled(areAnimationsEnabled)
}
}
if let lastViewController = navigationController.viewControllers.last,
!allowPushOfSameClassTwice && type(of: lastViewController) == type(of: viewController) {
return
}
switch pushStyle {
case .subMenu: return // handled earlier
case .default: break
case .popWhenPossible:
for subViewController in navigationController.viewControllers.reversed() {
if type(of: subViewController) == type(of: viewController) {
navigationController.popToViewController(subViewController, animated: animated)
return
}
}
case .preserve, .preserveAndHideBackButton:
var viewControllers = navigationController.viewControllers
let filtered = viewControllers.filter { preservedViewController in type(of: preservedViewController) == type(of: viewController) }
if let preservedViewController = filtered.last {
viewControllers = viewControllers.filter { subViewController in subViewController !== preservedViewController }
if pushStyle == .preserveAndHideBackButton {
preservedViewController.navigationItem.hidesBackButton = true
}
viewControllers.append(preservedViewController)
return navigationController.setViewControllers(viewControllers, animated: animated)
}
if pushStyle == .preserveAndHideBackButton {
viewController.navigationItem.hidesBackButton = true
}
case .replace:
viewController.navigationItem.hidesBackButton = true
return navigationController.setViewControllers([viewController], animated: animated)
}
navigationController.pushViewController(viewController, animated: animated)
}
override open var transitioningDelegate: UIViewControllerTransitioningDelegate? {
@@ -346,6 +405,11 @@ extension UISideMenuNavigationController: MenuModel {
get { return _leftSide.value }
set { _leftSide.value = newValue }
}
/// Indicates if the menu is anywhere in the view hierarchy, even if covered by another view controller.
open override var isHidden: Bool {
return super.isHidden
}
@IBInspectable open var menuWidth: CGFloat {
get { return settings.menuWidth }
@@ -477,89 +541,6 @@ internal extension UISideMenuNavigationController {
private extension UISideMenuNavigationController {
func shouldPushViewController(viewController: UIViewController, animated: Bool, completion: ((Bool) -> Void)?) -> Bool {
guard viewControllers.count > 0 && pushStyle != .subMenu else {
// NOTE: pushViewController is called by init(rootViewController: UIViewController)
// so we must perform the normal super method in this case
return true
}
let splitViewController = presentingViewController as? UISplitViewController
let tabBarController = presentingViewController as? UITabBarController
let potentialNavigationController = (splitViewController?.viewControllers.first ?? tabBarController?.selectedViewController) ?? presentingViewController
guard let navigationController = potentialNavigationController as? UINavigationController else {
Print.warning(.cannotPush, arguments: String(describing: potentialNavigationController.self), required: true)
return false
}
// To avoid overlapping dismiss & pop/push calls, create a transaction block where the menu
// is dismissed after showing the appropriate screen
CATransaction.begin()
defer { CATransaction.commit() }
var push = false
if dismissOnPush {
let animated = animated || alwaysAnimate
if animated {
let areAnimationsEnabled = UIView.areAnimationsEnabled
UIView.setAnimationsEnabled(true)
transitionController?.transition(presenting: false, animated: animated, alongsideTransition: { [weak self] in
guard let self = self else { return }
self.activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
}, completion: { [weak self] _ in
guard let self = self else { return }
self.activeDelegate?.sideMenuDidDisappear?(menu: self, animated: animated)
self.dismiss(animated: false, completion: nil)
completion?(push)
})
UIView.setAnimationsEnabled(areAnimationsEnabled)
}
}
if let lastViewController = navigationController.viewControllers.last,
!allowPushOfSameClassTwice && type(of: lastViewController) == type(of: viewController) {
return false
}
switch pushStyle {
case .subMenu: return false // handled earlier
case .default:
navigationController.pushViewController(viewController, animated: animated)
return false
case .popWhenPossible:
for subViewController in navigationController.viewControllers.reversed() {
if type(of: subViewController) == type(of: viewController) {
navigationController.popToViewController(subViewController, animated: animated)
return false
}
}
push = true
return true
case .preserve, .preserveAndHideBackButton:
var viewControllers = navigationController.viewControllers
let filtered = viewControllers.filter { preservedViewController in type(of: preservedViewController) == type(of: viewController) }
if let preservedViewController = filtered.last {
viewControllers = viewControllers.filter { subViewController in subViewController !== preservedViewController }
if pushStyle == .preserveAndHideBackButton {
preservedViewController.navigationItem.hidesBackButton = true
}
viewControllers.append(preservedViewController)
navigationController.setViewControllers(viewControllers, animated: animated)
return false
}
if pushStyle == .preserveAndHideBackButton {
viewController.navigationItem.hidesBackButton = true
}
push = true
return true
case .replace:
viewController.navigationItem.hidesBackButton = true
navigationController.setViewControllers([viewController], animated: animated)
return false
}
}
weak var activeDelegate: UISideMenuNavigationControllerDelegate? {
guard !view.isHidden else { return nil }
if let sideMenuDelegate = sideMenuDelegate {
+2 -2
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "SideMenu"
s.version = "6.1.2"
s.version = "6.1.4"
s.summary = "Simple side menu control for iOS in Swift inspired by Facebook. Right and Left sides. No coding required."
# This description is used to generate tags and improve search results.
@@ -29,7 +29,7 @@ Pod::Spec.new do |s|
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '10.0'
s.swift_version = '5'
s.swift_version = '5.0'
s.source_files = 'Pod/Classes/**/*'
# s.resource_bundles = {