Compare commits

..

13 Commits

Author SHA1 Message Date
jonkykong 78a3a66a69 Updated podspec 2019-07-23 01:41:18 -07:00
jonkykong 8fe0a23a38 Auto-assignment of leftSide property from SideMenuManager 2019-07-23 01:40:35 -07:00
jonkykong 3a873661c3 Refactor 2019-07-23 00:58:06 -07:00
jonkykong 89fc05a324 Example project fix 2019-07-23 00:55:16 -07:00
jonkykong 453e110246 Refactor 2019-07-23 00:55:02 -07:00
jonkykong b39142bc1a Updated podspec 2019-07-22 01:13:26 -07:00
jonkykong a6bd743e99 README correction 2019-07-22 01:13:15 -07:00
jonkykong 749588918c Logic correction 2019-07-22 01:13:02 -07:00
jonkykong f5b6615c72 Podspec update 2019-07-21 21:44:17 -07:00
jonkykong 8804675b80 Demo project correction 2019-07-21 21:43:42 -07:00
jonkykong b0a09a5b7d Fix for layout when menu not dismissed during presentation 2019-07-21 21:43:25 -07:00
jonkykong f1e4efeb46 Refactor 2019-07-21 21:43:07 -07:00
jonkykong aea7592d85 Scope change 2019-07-19 00:49:26 -07:00
8 changed files with 81 additions and 72 deletions
+2 -2
View File
@@ -54,7 +54,7 @@ class MainViewController: UIViewController {
menuScaleFactorSlider.value = Float(settings.presentationStyle.menuScaleFactor)
presentingAlphaSlider.value = Float(settings.presentationStyle.presentingEndAlpha)
presentingScaleFactorSlider.value = Float(settings.presentationStyle.presentingScaleFactor)
screenWidthSlider.value = Float(settings.menuWidth / view.frame.width)
screenWidthSlider.value = Float(settings.menuWidth / min(view.frame.width, view.frame.height))
shadowOpacitySlider.value = Float(settings.presentationStyle.onTopShadowOpacity)
}
@@ -89,7 +89,7 @@ class MainViewController: UIViewController {
var settings = SideMenuSettings()
settings.presentationStyle = presentationStyle
settings.menuWidth = view.frame.width * CGFloat(screenWidthSlider.value)
settings.menuWidth = min(view.frame.width, view.frame.height) * CGFloat(screenWidthSlider.value)
let styles:[UIBlurEffect.Style?] = [nil, .dark, .light, .extraLight]
settings.blurEffectStyle = styles[blurSegmentControl.selectedSegmentIndex]
settings.statusBarEndAlpha = blackOutStatusBar.isOn ? 1 : 0
+13 -5
View File
@@ -13,22 +13,30 @@ internal enum Print: String { case
menuAlreadyAssigned = "%@ was already assigned to the %@ of %@. When using multiple SideMenuManagers you may want to use new instances of UISideMenuNavigationController instead of existing instances to avoid crashes if the menu is presented more than once.",
menuInUse = "%@ cannot be modified while it's presented.",
panGestureAdded = "%@ was called before %@ or %@ was set. Gestures will not work without a menu.",
property = "a menu's %@ property can only be changed when it is hidden.",
property = "A menu's %@ property can only be changed when it is hidden.",
screenGestureAdded = "%@ was called before %@ was set. The gesture will not work without a menu. Use %@ to add gestures for only one menu.",
transitioningDelegate = "SideMenu requires use of the transitioningDelegate. It cannot be modified."
internal static func warning(_ print: Print, arguments: CVarArg..., required: Bool = false) {
warning(String(format: print.rawValue, arguments), required: required)
enum PropertyName: String { case
leftSide
}
internal static func warning(_ print: Print, required: Bool = false) {
static func warning(_ print: Print, arguments: CVarArg..., required: Bool = false) {
warning(String(format: print.rawValue, arguments: arguments), required: required)
}
static func warning(_ print: Print, arguments: PropertyName..., required: Bool = false) {
warning(String(format: print.rawValue, arguments: arguments.map { $0.rawValue }), required: required)
}
static func warning(_ print: Print, required: Bool = false) {
warning(print.rawValue, required: required)
}
}
private extension Print {
private static func warning(_ message: String, required: Bool = false) {
static func warning(_ message: String, required: Bool = false) {
let message = "SideMenu Warning: \(message)"
if required {
+6 -20
View File
@@ -9,32 +9,18 @@ import Foundation
internal final class Protected<T: Equatable> {
typealias ConditionBlock = (T) -> Bool
typealias Block = (T) -> Void
typealias ConditionBlock = (_ oldValue: T, T) -> T
private var _value: T
private var conditionBlock: ConditionBlock
private var thenBlock: Block?
private var elseBlock: Block?
private var condition: ConditionBlock
public var value: T {
get {
return _value
}
set {
guard conditionBlock(_value) else {
elseBlock?(_value)
return
}
_value = newValue
thenBlock?(_value)
}
get { return _value }
set { _value = condition(_value, newValue) }
}
init(_ value: T, if conditionBlock: @escaping ConditionBlock, then thenBlock: Block? = nil, else elseBlock: Block? = nil) {
init(_ value: T, when condition: @escaping ConditionBlock) {
self._value = value
self.conditionBlock = conditionBlock
self.thenBlock = thenBlock
self.elseBlock = elseBlock
self.condition = condition
}
}
+23 -12
View File
@@ -36,15 +36,8 @@ public class SideMenuManager: NSObject {
}
}
private var _leftMenu: Protected<Menu?> =
Protected(nil,
if: { $0?.isHidden != false },
else: { _ in Print.warning(.menuInUse, arguments: PresentDirection.left.name, required: true) } )
private var _rightMenu: Protected<Menu?> =
Protected(nil,
if: { $0?.isHidden != false },
else: { _ in Print.warning(.menuInUse, arguments: PresentDirection.right.name, required: true) } )
private var _leftMenu: Protected<Menu?> = Protected(nil) { SideMenuManager.setMenu(fromMenu: $0, toMenu: $1) }
private var _rightMenu: Protected<Menu?> = Protected(nil) { SideMenuManager.setMenu(fromMenu: $0, toMenu: $1) }
private var switching: Bool = false
@@ -58,13 +51,23 @@ public class SideMenuManager: NSObject {
/// The left menu.
open var leftMenuNavigationController: UISideMenuNavigationController? {
get { return _leftMenu.value }
get {
if _leftMenu.value?.isHidden == true {
_leftMenu.value?.leftSide = true
}
return _leftMenu.value
}
set(menu) { _leftMenu.value = menu }
}
/// The right menu.
open var rightMenuNavigationController: UISideMenuNavigationController? {
get { return _rightMenu.value }
get {
if _rightMenu.value?.isHidden == true {
_rightMenu.value?.leftSide = false
}
return _rightMenu.value
}
set(menu) { _rightMenu.value = menu }
}
@@ -123,6 +126,14 @@ internal extension SideMenuManager {
case false: rightMenuNavigationController = menu
}
}
private class func setMenu(fromMenu: Menu?, toMenu: Menu?) -> Menu? {
if fromMenu?.isHidden == false {
Print.warning(.menuInUse, arguments: PresentDirection.left.name, required: true)
return fromMenu
}
return toMenu
}
}
private extension SideMenuManager {
@@ -210,7 +221,7 @@ private extension SideMenuManager {
}
}
private var activeViewController: UIViewController? {
var activeViewController: UIViewController? {
return UIApplication.shared.keyWindow?.rootViewController?.activeViewController
}
}
+1 -1
View File
@@ -8,7 +8,7 @@
import Foundation
@objcMembers
public class SideMenuPresentationStyle {
open class SideMenuPresentationStyle {
/// Background color behind the views and status bar color
public var backgroundColor: UIColor = .black
/// The starting alpha value of the menu before it appears
@@ -67,14 +67,15 @@ internal typealias Menu = UISideMenuNavigationController
@objcMembers
open class UISideMenuNavigationController: UINavigationController {
private enum PropertyName: String { case
leftSide
private lazy var _leftSide =
Protected(false) { [weak self] oldValue, newValue in
guard self?.isHidden != false else {
Print.warning(.property, arguments: .leftSide, required: true)
return oldValue
}
return newValue
}
private lazy var _leftSide = Protected(false,
if: { [weak self] _ in self?.isHidden != false },
else: { _ in Menu.elseCondition(.leftSide) } )
private weak var _sideMenuManager: SideMenuManager?
private weak var foundViewController: UIViewController?
private weak var interactionController: SideMenuInteractionController?
@@ -164,24 +165,26 @@ open class UISideMenuNavigationController: UINavigationController {
override open func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// When presenting a view controller from the menu, the menu view gets moved into another transition view above our transition container
// which can break the visual layout we had before. So, we move the menu view back to its original transition view to preserve it.
if dismissOnPresent && !isBeingDismissed {
// We're presenting a view controller from the menu, so we need to hide the menu so it isn't showing when the presented view is dismissed.
if !isBeingDismissed {
// When presenting a view controller from the menu, the menu view gets moved into another transition view above our transition container
// which can break the visual layout we had before. So, we move the menu view back to its original transition view to preserve it.
if let presentingView = presentingViewController?.view, let containerView = presentingView.superview {
containerView.addSubview(view)
}
transitionController?.transition(presenting: false, animated: animated, alongsideTransition: { [weak self] in
guard let self = self else { return }
self.activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
}, complete: false, completion: { [weak self] _ in
guard let self = self else { return }
self.activeDelegate?.sideMenuDidDisappear?(menu: self, animated: animated)
self.view.isHidden = true
})
} else {
activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
if dismissOnPresent {
// We're presenting a view controller from the menu, so we need to hide the menu so it isn't showing when the presented view is dismissed.
transitionController?.transition(presenting: false, animated: animated, alongsideTransition: { [weak self] in
guard let self = self else { return }
self.activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
}, complete: false, completion: { [weak self] _ in
guard let self = self else { return }
self.activeDelegate?.sideMenuDidDisappear?(menu: self, animated: animated)
self.view.isHidden = true
})
} else {
activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
}
}
}
@@ -206,11 +209,11 @@ open class UISideMenuNavigationController: UINavigationController {
activeDelegate?.sideMenuDidDisappear?(menu: self, animated: animated)
if dismissOnPresent && !isBeingDismissed {
view.isHidden = true
} else {
if isBeingDismissed {
transitionController = nil
interactive = false
} else if dismissOnPresent {
view.isHidden = true
}
}
@@ -237,6 +240,11 @@ open class UISideMenuNavigationController: UINavigationController {
self.rotating = false
}
}
open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
transitionController?.layout()
}
override open func pushViewController(_ viewController: UIViewController, animated: Bool) {
let push = shouldPushViewController(viewController: viewController, animated: animated) { [weak self] _ in
@@ -543,10 +551,6 @@ private extension UISideMenuNavigationController {
}
}
private class func elseCondition(_ propertyName: PropertyName) {
Print.warning(.property, arguments: propertyName.rawValue, required: true)
}
weak var activeDelegate: UISideMenuNavigationControllerDelegate? {
guard !view.isHidden else { return nil }
if let sideMenuDelegate = sideMenuDelegate {
+4 -4
View File
@@ -137,11 +137,11 @@ dismiss(animated: true, completion: nil)
To use gestures you have to use the `SideMenuManager`. In your `AppDelegate` do something like this:
``` swift
// Define the menus
let menuLeftNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.menuLeftNavigationController = menuLeftNavigationController
let leftMenuNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.leftMenuNavigationController = leftMenuNavigationController
let menuRightNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.menuRightNavigationController = menuRightNavigationController
let rightMenuNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.rightMenuNavigationController = rightMenuNavigationController
// Setup gestures: the left and/or right menus must be set up (above) for these to work.
// Note that these continue to work on the Navigation Controller independent of the view controller it displays!
+1 -1
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "SideMenu"
s.version = "6.0.5"
s.version = "6.0.9"
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.