Skip to content

Commit ff3271a

Browse files
author
Ryan Nystrom
committed
fixup examples, add motion effect
1 parent 1f97693 commit ff3271a

11 files changed

+113
-82
lines changed

ContextMenu.podspec

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Pod::Spec.new do |spec|
77
spec.summary = 'Context menu inspired by Things 3.'
88
spec.source = { :git => 'https://github.com/GitHawkApp/ContextMenu.git', :tag => '#{s.version}' }
99
spec.source_files = 'ContextMenu/*.swift'
10+
spec.platform = :ios, '10.0'
11+
spec.swift_version = '4.0'
1012
end

ContextMenu/ClippedContainerViewController.swift

+16-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,23 @@ internal class ClippedContainerViewController: UIViewController {
2727
super.viewDidLoad()
2828
view.layer.cornerRadius = options.containerStyle.cornerRadius
2929
view.layer.shadowRadius = options.containerStyle.shadowRadius
30+
view.layer.shadowOpacity = options.containerStyle.shadowOpacity
3031
view.layer.shadowColor = UIColor.black.cgColor
31-
view.layer.shadowOpacity = 0.2
32+
33+
if options.containerStyle.motionEffect {
34+
let amount = 12
35+
let tiltX = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis)
36+
tiltX.minimumRelativeValue = -amount
37+
tiltX.maximumRelativeValue = amount
38+
39+
let tiltY = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis)
40+
tiltY.minimumRelativeValue = -amount
41+
tiltY.maximumRelativeValue = amount
42+
43+
let group = UIMotionEffectGroup()
44+
group.motionEffects = [tiltX, tiltY]
45+
view.addMotionEffect(group)
46+
}
3247

3348
containedViewController.view.layer.cornerRadius = view.layer.cornerRadius
3449
containedViewController.view.clipsToBounds = true

ContextMenu/ContextMenu+ContainerStyle.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,34 @@ extension ContextMenu {
1414

1515
public let cornerRadius: CGFloat
1616
public let shadowRadius: CGFloat
17+
public let shadowOpacity: Float
1718
public let xPadding: CGFloat
1819
public let yPadding: CGFloat
1920
public let edgePadding: CGFloat
2021
public let backgroundColor: UIColor
2122
public let overlayColor: UIColor
23+
public let motionEffect: Bool
2224

2325
public init(
2426
cornerRadius: CGFloat = 8,
2527
shadowRadius: CGFloat = 15,
28+
shadowOpacity: Float = 0.1,
2629
xPadding: CGFloat = 8,
2730
yPadding: CGFloat = 8,
2831
edgePadding: CGFloat = 15,
2932
backgroundColor: UIColor = .white,
30-
overlayColor: UIColor = UIColor(white: 0, alpha: 0.3)
33+
overlayColor: UIColor = UIColor(white: 0, alpha: 0.3),
34+
motionEffect: Bool = true
3135
) {
3236
self.cornerRadius = cornerRadius
3337
self.shadowRadius = shadowRadius
38+
self.shadowOpacity = shadowOpacity
3439
self.xPadding = xPadding
3540
self.yPadding = yPadding
3641
self.edgePadding = edgePadding
3742
self.backgroundColor = backgroundColor
3843
self.overlayColor = overlayColor
44+
self.motionEffect = motionEffect
3945
}
4046

4147
}

ContextMenu/ContextMenu+Options.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ extension ContextMenu {
1515
let durations: AnimationDurations
1616
let containerStyle: ContainerStyle
1717
let menuStyle: MenuStyle
18+
let haptics: Bool
1819

1920
public init(
2021
durations: AnimationDurations = AnimationDurations(),
2122
containerStyle: ContainerStyle = ContainerStyle(),
22-
menuStyle: MenuStyle = .default
23+
menuStyle: MenuStyle = .default,
24+
haptics: Bool = true
2325
) {
2426
self.durations = durations
2527
self.containerStyle = containerStyle
2628
self.menuStyle = menuStyle
29+
self.haptics = haptics
2730
}
2831
}
2932

ContextMenu/ContextMenu.swift

+5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ public class ContextMenu: NSObject {
1313
public static let shared = ContextMenu()
1414

1515
internal var item: Item?
16+
internal let haptics = UISelectionFeedbackGenerator()
1617

1718
public func show(
1819
sourceViewController: UIViewController,
1920
viewController: UIViewController,
2021
options: Options = Options(),
2122
sourceView: UIView? = nil
2223
) {
24+
if options.haptics {
25+
haptics.selectionChanged()
26+
}
27+
2328
let item = Item(
2429
viewController: viewController,
2530
options: options,

Example/Example.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@
6363
2971CEA4205454BD00342296 /* Example */ = {
6464
isa = PBXGroup;
6565
children = (
66-
2971CEB72054553400342296 /* MenuViewController.swift */,
6766
2971CEA5205454BD00342296 /* AppDelegate.swift */,
68-
2971CEA7205454BD00342296 /* ViewController.swift */,
69-
2971CEA9205454BD00342296 /* Main.storyboard */,
7067
2971CEAC205454BD00342296 /* Assets.xcassets */,
71-
2971CEAE205454BD00342296 /* LaunchScreen.storyboard */,
7268
2971CEB1205454BD00342296 /* Info.plist */,
69+
2971CEAE205454BD00342296 /* LaunchScreen.storyboard */,
70+
2971CEA9205454BD00342296 /* Main.storyboard */,
71+
2971CEB72054553400342296 /* MenuViewController.swift */,
72+
2971CEA7205454BD00342296 /* ViewController.swift */,
7373
);
7474
path = Example;
7575
sourceTree = "<group>";

Example/Example/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ViewController: UIViewController {
2727
ContextMenu.shared.show(
2828
sourceViewController: self,
2929
viewController: MenuViewController(),
30-
sourceView: nil
30+
sourceView: button
3131
)
3232
}
3333

Example/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: ../ContextMenu.podspec
1010

1111
SPEC CHECKSUMS:
12-
ContextMenu: 74f68e96197cdbfb1b5d91c703cc0906bc914cfc
12+
ContextMenu: f542992e2dd56e8a116a59a2ab5a215637982744
1313

1414
PODFILE CHECKSUM: aa060c7f3a10a9cb8b2633f1297c22bb65e4f54d
1515

Example/Pods/Local Podspecs/ContextMenu.podspec.json

+3-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)