Skip to content

Commit 6cf696c

Browse files
authored
Merge pull request #81 from handsomecode/develop
Update to SideMenuItemShadow
2 parents cd17ad8 + 84ab9b1 commit 6cf696c

File tree

11 files changed

+83
-55
lines changed

11 files changed

+83
-55
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22
All notable changes of the library will be documented in this file.
33

4+
## 2.3
5+
### Changed
6+
- Renamed `SideMenuItemShadow` to `SideMenuItemOptions` to allow for additional visual properties to be changed. (Sorry for the volitility. The new name gives better flexibility going forward.)
7+
- Moved the drop shadow customization for the opened menu item to a property on `SideMenuItemOption` called `shadow`. Use the `Shadow` struct now to assign your custom values.
8+
- `MenuContainerViewController`'s `shadowOptions` property has been renamed to `currentItemOptions`
9+
410
## 2.2
511
### Added
612
- Ability to globally change the drop shadow of the current content view while the menu is open (#61)

InteractiveSideMenu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "InteractiveSideMenu"
3-
s.version = "2.2.1"
3+
s.version = "2.3"
44
s.summary = "Interactive Side Menu in Swift"
55
s.homepage = "https://github.com/handsomecode/InteractiveSideMenu"
66
s.license = "Apache 2.0 license"

InteractiveSideMenu.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
881EF0981E3101B80035DEB4 /* MenuContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881EF0941E3101B80035DEB4 /* MenuContainerViewController.swift */; };
1515
881EF0991E3101B80035DEB4 /* SideMenuItemContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881EF0951E3101B80035DEB4 /* SideMenuItemContent.swift */; };
1616
881EF09A1E3101B80035DEB4 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881EF0961E3101B80035DEB4 /* MenuViewController.swift */; };
17-
D48B8AEC202CDE1A0010D9A4 /* SideMenuItemShadow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48B8AEB202CDE1A0010D9A4 /* SideMenuItemShadow.swift */; };
17+
D48B8AEC202CDE1A0010D9A4 /* SideMenuItemOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48B8AEB202CDE1A0010D9A4 /* SideMenuItemOptions.swift */; };
1818
/* End PBXBuildFile section */
1919

2020
/* Begin PBXFileReference section */
@@ -27,7 +27,7 @@
2727
881EF0941E3101B80035DEB4 /* MenuContainerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuContainerViewController.swift; sourceTree = "<group>"; };
2828
881EF0951E3101B80035DEB4 /* SideMenuItemContent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideMenuItemContent.swift; sourceTree = "<group>"; };
2929
881EF0961E3101B80035DEB4 /* MenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = "<group>"; };
30-
D48B8AEB202CDE1A0010D9A4 /* SideMenuItemShadow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuItemShadow.swift; sourceTree = "<group>"; };
30+
D48B8AEB202CDE1A0010D9A4 /* SideMenuItemOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuItemOptions.swift; sourceTree = "<group>"; };
3131
/* End PBXFileReference section */
3232

3333
/* Begin PBXFrameworksBuildPhase section */
@@ -65,7 +65,7 @@
6565
881EF0931E3101B80035DEB4 /* MenuAnimator.swift */,
6666
881EF0941E3101B80035DEB4 /* MenuContainerViewController.swift */,
6767
881EF0951E3101B80035DEB4 /* SideMenuItemContent.swift */,
68-
D48B8AEB202CDE1A0010D9A4 /* SideMenuItemShadow.swift */,
68+
D48B8AEB202CDE1A0010D9A4 /* SideMenuItemOptions.swift */,
6969
881EF0961E3101B80035DEB4 /* MenuViewController.swift */,
7070
881EF08F1E3101130035DEB4 /* Info.plist */,
7171
881EF0901E3101130035DEB4 /* InteractiveSideMenu.h */,
@@ -157,7 +157,7 @@
157157
84E2E6771F15406600E5FF37 /* MenuTransitioningDelegate.swift in Sources */,
158158
881EF0981E3101B80035DEB4 /* MenuContainerViewController.swift in Sources */,
159159
881EF0991E3101B80035DEB4 /* SideMenuItemContent.swift in Sources */,
160-
D48B8AEC202CDE1A0010D9A4 /* SideMenuItemShadow.swift in Sources */,
160+
D48B8AEC202CDE1A0010D9A4 /* SideMenuItemOptions.swift in Sources */,
161161
84E2E6751F15401000E5FF37 /* Options.swift in Sources */,
162162
881EF09A1E3101B80035DEB4 /* MenuViewController.swift in Sources */,
163163
);

Sample/Sample/Controllers/HostViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class HostViewController: MenuContainerViewController {
4545

4646
// Select initial content controller. It's needed even if the first view controller should be selected.
4747
self.selectContentViewController(contentViewControllers.first!)
48+
49+
self.currentItemOptions.cornerRadius = 10.0
4850
}
4951

5052
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {

Sample/Sample/Menu Controllers/TweakViewController.storyboard

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
<nil key="highlightedColor"/>
6262
</label>
6363
</subviews>
64-
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
6564
<constraints>
6665
<constraint firstItem="nuF-oz-bcT" firstAttribute="top" secondItem="MYI-N6-xji" secondAttribute="bottom" constant="4" id="0mz-3G-vMu"/>
6766
<constraint firstItem="MYI-N6-xji" firstAttribute="leading" secondItem="xZP-x5-Bib" secondAttribute="leading" constant="20" id="0zE-3h-1yb"/>
@@ -100,7 +99,6 @@
10099
<nil key="highlightedColor"/>
101100
</label>
102101
</subviews>
103-
<color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
104102
<constraints>
105103
<constraint firstItem="SjD-jD-nvG" firstAttribute="leading" secondItem="14M-Ay-GAi" secondAttribute="leading" constant="20" id="7Wd-jH-3nZ"/>
106104
<constraint firstItem="SjD-jD-nvG" firstAttribute="top" secondItem="dc6-ru-tjk" secondAttribute="bottom" constant="6" id="FGC-aD-pSR"/>
@@ -139,7 +137,6 @@
139137
<nil key="highlightedColor"/>
140138
</label>
141139
</subviews>
142-
<color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
143140
<constraints>
144141
<constraint firstAttribute="trailing" secondItem="gOZ-qG-agZ" secondAttribute="trailing" id="3S5-zP-4s7"/>
145142
<constraint firstItem="LmW-e8-ol0" firstAttribute="centerX" secondItem="f8c-TI-8tN" secondAttribute="centerX" id="5ZE-bl-Fw6"/>

Sources/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.2.1</string>
18+
<string>2.3</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Sources/MenuAnimator.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class MenuInteractiveTransition: NSObject {
2727

2828
var present = false
2929
var interactionInProgress = false
30-
var shadowOptions: SideMenuItemShadow
30+
var currentItemOptions: SideMenuItemOptions
3131

3232
var options = TransitionOptions()
3333
fileprivate let presentAction: Action
@@ -41,8 +41,8 @@ final class MenuInteractiveTransition: NSObject {
4141
fileprivate var tapRecognizer: UITapGestureRecognizer?
4242
fileprivate var panRecognizer: UIPanGestureRecognizer?
4343

44-
required init(shadowOptions: SideMenuItemShadow, presentAction: @escaping Action, dismissAction: @escaping Action) {
45-
self.shadowOptions = shadowOptions
44+
required init(currentItemOptions: SideMenuItemOptions, presentAction: @escaping Action, dismissAction: @escaping Action) {
45+
self.currentItemOptions = currentItemOptions
4646
self.presentAction = presentAction
4747
self.dismissAction = dismissAction
4848
super.init()
@@ -201,15 +201,24 @@ private extension MenuInteractiveTransition {
201201
addShadow(to: placeholderView)
202202
return placeholderView
203203
}
204-
addShadow(to: snapshotView)
205-
return snapshotView
204+
205+
snapshotView.layer.cornerRadius = currentItemOptions.cornerRadius
206+
snapshotView.layer.masksToBounds = true
207+
208+
let baseView = UIView(frame: from.bounds)
209+
baseView.addSubview(snapshotView)
210+
addShadow(to: baseView)
211+
return baseView
206212
}
207213

208214
func addShadow(to view: UIView) {
209-
view.layer.shadowColor = shadowOptions.color?.cgColor
210-
view.layer.shadowOpacity = Float(shadowOptions.opacity)
211-
view.layer.shadowOffset = shadowOptions.offset
212-
view.layer.shadowRadius = shadowOptions.radius
215+
view.layer.shadowColor = currentItemOptions.shadow.color?.cgColor
216+
view.layer.shadowOpacity = Float(currentItemOptions.shadow.opacity)
217+
view.layer.shadowOffset = currentItemOptions.shadow.offset
218+
view.layer.shadowRadius = currentItemOptions.shadow.radius
219+
view.layer.shadowPath = UIBezierPath(roundedRect: view.bounds, cornerRadius: currentItemOptions.cornerRadius).cgPath
220+
view.layer.shouldRasterize = true
221+
view.layer.rasterizationScale = UIScreen.main.scale
213222
}
214223

215224
func removeShadow(from view: UIView) {

Sources/MenuContainerViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ open class MenuContainerViewController: UIViewController {
3535
*/
3636
fileprivate var isShown = false
3737

38-
public var shadowOptions = SideMenuItemShadow() {
38+
public var currentItemOptions = SideMenuItemOptions() {
3939
didSet {
40-
navigationMenuTransitionDelegate?.shadowOptions = shadowOptions
40+
navigationMenuTransitionDelegate?.currentItemOptions = currentItemOptions
4141
}
4242
}
4343

@@ -80,7 +80,7 @@ open class MenuContainerViewController: UIViewController {
8080
super.viewDidLoad()
8181

8282
let interactiveTransition = MenuInteractiveTransition(
83-
shadowOptions: shadowOptions,
83+
currentItemOptions: currentItemOptions,
8484
presentAction: { [unowned self] in
8585
self.presentNavigationMenu()
8686
},

Sources/MenuTransitioningDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ final class MenuTransitioningDelegate: NSObject {
2525

2626
let interactiveTransition: MenuInteractiveTransition
2727

28-
public var shadowOptions = SideMenuItemShadow() {
28+
public var currentItemOptions = SideMenuItemOptions() {
2929
didSet {
30-
interactiveTransition.shadowOptions = shadowOptions
30+
interactiveTransition.currentItemOptions = currentItemOptions
3131
}
3232
}
3333

Sources/SideMenuItemOptions.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// SideMenuItemOptions.swift
3+
// InteractiveSideMenu
4+
//
5+
// Created by Eric Miller on 2/8/18.
6+
// Copyright © 2018 Handsome. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
Defines the parameters for the shadow that is shown under to content controller when the side menu is open.
13+
*/
14+
public struct SideMenuItemOptions {
15+
16+
public struct Shadow {
17+
public var color: UIColor? = UIColor.black
18+
public var opacity: CGFloat = 0.3
19+
public var offset: CGSize = CGSize(width: -5, height: 5)
20+
public var radius: CGFloat = 3
21+
22+
public init() { }
23+
24+
public init(color: UIColor? = UIColor.black,
25+
opacity: CGFloat = 0.3,
26+
offset: CGSize = CGSize(width: -5, height: 5),
27+
radius: CGFloat = 3) {
28+
self.color = color
29+
self.opacity = opacity
30+
self.offset = offset
31+
self.radius = radius
32+
}
33+
}
34+
35+
public var shadow = Shadow()
36+
37+
public var cornerRadius: CGFloat = 0.0 {
38+
willSet {
39+
if newValue < 0 {
40+
preconditionFailure("Invalid `cornerRadius` value: \(newValue). Must be non-negative")
41+
}
42+
}
43+
}
44+
45+
public init() { }
46+
}

0 commit comments

Comments
 (0)