Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Add shadow to sidemenu #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions Source/SideMenuController+CustomTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public extension SideMenuController {
public var sidePanelWidth: CGFloat = 300
public var centerPanelOverlayColor = UIColor(hue:0.15, saturation:0.21, brightness:0.17, alpha:0.6)
public var centerPanelShadow = false
public var sidePanelShadow = false
public var menuButtonSize = CGSize(width: 40, height: 40)
public var menuButtonSeparatorWidth = CGFloat(-10)
}

public struct Animating {
Expand Down
13 changes: 13 additions & 0 deletions Source/SideMenuController+SideOver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ extension SideMenuController {
}
}

func setShadowFromSideMenu(hidden: Bool) {

guard _preferences.drawing.sidePanelShadow else {
return
}

if hidden {
sidePanel.layer.shadowOpacity = 0.0
} else {
sidePanel.layer.shadowOpacity = 0.8
}
}

func setAboveSidePanel(hidden: Bool, completion: ((Bool) -> ())? = nil){

var destinationFrame = sidePanel.frame
Expand Down
13 changes: 13 additions & 0 deletions Source/SideMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ open class SideMenuController: UIViewController, UIGestureRecognizerDelegate {

// MARK: - Configurations -

func configureSideMenuShadow() {
guard _preferences.drawing.sidePanelShadow else {
return
}
sidePanel.layer.shadowOffset = CGSize(width: 18, height: 0)
sidePanel.layer.shadowRadius = 20
sidePanel.layer.shadowOpacity = 0.9
sidePanel.layer.shadowColor = UIColor.black.cgColor
sidePanel.layer.masksToBounds = false
}

func repositionViews() {

if sidePanelVisible {
Expand Down Expand Up @@ -242,6 +253,7 @@ open class SideMenuController: UIViewController, UIGestureRecognizerDelegate {
sidePanel = UIView(frame: sidePanelFrame)
view.addSubview(sidePanel)
sidePanel.clipsToBounds = true
configureSideMenuShadow()

if sidePanelPosition.isPositionedUnder {
view.sendSubview(toBack: sidePanel)
Expand Down Expand Up @@ -305,6 +317,7 @@ open class SideMenuController: UIViewController, UIGestureRecognizerDelegate {
}else if !display {
centerPanelOverlay.removeFromSuperview()
}
setShadowFromSideMenu(hidden: !display)
} else {
setSideShadow(hidden: !display)
}
Expand Down
5 changes: 3 additions & 2 deletions Source/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public extension UINavigationController {
return
}

let button = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
let buttonSize = SideMenuController.preferences.drawing.menuButtonSize
let button = UIButton(frame: CGRect(x: 0, y: 0, width: buttonSize.width, height: buttonSize.height))
button.accessibilityIdentifier = SideMenuController.preferences.interaction.menuButtonAccessibilityIdentifier
button.setImage(image, for: .normal)
button.addTarget(sideMenuController, action: #selector(SideMenuController.toggle), for: UIControlEvents.touchUpInside)
Expand Down Expand Up @@ -75,7 +76,7 @@ public extension UINavigationController {
item.customView = button

let spacer = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
spacer.width = -10
spacer.width = SideMenuController.preferences.drawing.menuButtonSeparatorWidth

items.append(contentsOf: positionLeft ? [spacer, item] : [item, spacer])
return items
Expand Down