Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle committed Apr 25, 2018
2 parents 9827ce1 + fe92630 commit c5c5b60
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 97 deletions.
4 changes: 2 additions & 2 deletions Example/Example/View Controllers/Helper/PopMenuExamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ final class PopMenuExamples {
}

/// PopMenu with separator line.
func popMenuSeparatorLine(_ separatorLineHidden: Bool) -> PopMenuViewController {
func popMenuSeparatorLine(_ separatorStyle: PopMenuActionSeparator) -> PopMenuViewController {
let popMenu = popMenuTextAndImage()

popMenu.appearance.popMenuItemSeparatorHidden = separatorLineHidden
popMenu.appearance.popMenuItemSeparator = separatorStyle

return popMenu
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/View Controllers/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ extension RootViewController {
case (2, 10):
popMenu = examples.popMenuCustomStatusBarStyle(.default)
case (2, 11):
popMenu = examples.popMenuSeparatorLine(false)
popMenu = examples.popMenuSeparatorLine(.fill())
case (3, 0):
let cell = tableView.cellForRow(at: indexPath)!
popMenu = examples.popMenuStandard(cell)
Expand Down
4 changes: 0 additions & 4 deletions PopMenu.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
9D397AD720805F9900C58037 /* PopMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AD620805F9900C58037 /* PopMenuViewController.swift */; };
9D397AF32080885F00C58037 /* PopMenuPresentAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AF22080885F00C58037 /* PopMenuPresentAnimationController.swift */; };
9D397AF52080887600C58037 /* PopMenuDismissAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AF42080887600C58037 /* PopMenuDismissAnimationController.swift */; };
9D397AFA2080A13300C58037 /* PopMenuColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AF92080A13300C58037 /* PopMenuColor.swift */; };
9D397AFD2080A5F000C58037 /* PopMenuAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AFC2080A5F000C58037 /* PopMenuAppearance.swift */; };
9D397AFF2080AB9200C58037 /* PopMenuGradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AFE2080AB9200C58037 /* PopMenuGradientView.swift */; };
9D91B30A208207B30029ACAD /* UIView+Shadows.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D91B309208207B30029ACAD /* UIView+Shadows.swift */; };
Expand Down Expand Up @@ -49,7 +48,6 @@
9D397AD620805F9900C58037 /* PopMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopMenuViewController.swift; sourceTree = "<group>"; };
9D397AF22080885F00C58037 /* PopMenuPresentAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuPresentAnimationController.swift; sourceTree = "<group>"; };
9D397AF42080887600C58037 /* PopMenuDismissAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuDismissAnimationController.swift; sourceTree = "<group>"; };
9D397AF92080A13300C58037 /* PopMenuColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuColor.swift; sourceTree = "<group>"; };
9D397AFC2080A5F000C58037 /* PopMenuAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuAppearance.swift; sourceTree = "<group>"; };
9D397AFE2080AB9200C58037 /* PopMenuGradientView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuGradientView.swift; sourceTree = "<group>"; };
9D91B309208207B30029ACAD /* UIView+Shadows.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Shadows.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -131,7 +129,6 @@
children = (
9D397AF62080A06200C58037 /* Helpers */,
9D397AD420805F4D00C58037 /* PopMenuManager.swift */,
9D397AF92080A13300C58037 /* PopMenuColor.swift */,
9D397AFC2080A5F000C58037 /* PopMenuAppearance.swift */,
);
path = Classes;
Expand Down Expand Up @@ -280,7 +277,6 @@
9D397AF32080885F00C58037 /* PopMenuPresentAnimationController.swift in Sources */,
9D397AFD2080A5F000C58037 /* PopMenuAppearance.swift in Sources */,
9D397AF52080887600C58037 /* PopMenuDismissAnimationController.swift in Sources */,
9D397AFA2080A13300C58037 /* PopMenuColor.swift in Sources */,
9D397AD720805F9900C58037 /* PopMenuViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
90 changes: 87 additions & 3 deletions PopMenu/Classes/PopMenuAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import UIKit

#if os(macOS)
public typealias Color = NSColor
#else
public typealias Color = UIColor
#endif

/// Appearance for PopMenu.
/// Use for configuring custom styles and looks.
final public class PopMenuAppearance: NSObject {
Expand All @@ -26,9 +32,9 @@ final public class PopMenuAppearance: NSObject {

/// How tall each action is.
public var popMenuActionHeight: CGFloat = 50

/// Visibility of the separator line between actions.
public var popMenuItemSeparatorHidden: Bool = true
/// The separator style for each action.
public var popMenuItemSeparator: PopMenuActionSeparator = .none()

/// The status bar style of the pop menu.
public var popMenuStatusBarStyle: UIStatusBarStyle?
Expand Down Expand Up @@ -75,3 +81,81 @@ public struct PopMenuBackgroundStyle {
}

}

/// Color structure for PopMenu color styles.
public struct PopMenuColor {

/// Background color instance.
public var backgroundColor: PopMenuActionBackgroundColor

/// Action tint color instance.
public var actionColor: PopMenuActionColor

/// Compose the color.
public static func configure(background: PopMenuActionBackgroundColor, action: PopMenuActionColor) -> PopMenuColor {
return PopMenuColor(backgroundColor: background, actionColor: action)
}

/// Get default background and action color.
public static func `default`() -> PopMenuColor {
return PopMenuColor(backgroundColor: .gradient(fill: #colorLiteral(red: 0.168627451, green: 0.168627451, blue: 0.168627451, alpha: 1), #colorLiteral(red: 0.2156862745, green: 0.2156862745, blue: 0.2156862745, alpha: 1)), actionColor: .tint(.white))
}

}

/// Background color structure to control PopMenu backgrounds.
public struct PopMenuActionBackgroundColor {

/// All colors (only one if solid color, or else it's gradient)
public let colors: [Color]

/// Fill an only solid color into the colors palette.
public static func solid(fill color: Color) -> PopMenuActionBackgroundColor {
return .init(colors: [color])
}

/// Fill gradient colors into the colors palette.
public static func gradient(fill colors: Color...) -> PopMenuActionBackgroundColor {
return .init(colors: colors)
}

}

/// Action color structure to control PopMenu actions.
public struct PopMenuActionColor {

/// Tint color.
public let color: Color

/// Get action's color instance with given color.
public static func tint(_ color: Color) -> PopMenuActionColor {
return PopMenuActionColor(color: color)
}

}

/// Action separator structure to control PopMenu item separators.
public struct PopMenuActionSeparator: Equatable {

/// Height of separator.
public let height: CGFloat

/// Color of separator.
public let color: Color

/// Fill separator color with given color and height.
public static func fill(_ color: Color = Color.white.withAlphaComponent(0.5), height: CGFloat = 0.5) -> PopMenuActionSeparator {
return PopMenuActionSeparator(height: height, color: color)
}

/// Get separator instance with no separator style.
public static func none() -> PopMenuActionSeparator {
return PopMenuActionSeparator(height: 0, color: .clear)
}

/// Equatable operation.
public static func == (lhs: PopMenuActionSeparator, rhs: PopMenuActionSeparator) -> Bool {
return lhs.color == rhs.color && lhs.height == rhs.height
}

}
67 changes: 0 additions & 67 deletions PopMenu/Classes/PopMenuColor.swift

This file was deleted.

2 changes: 1 addition & 1 deletion PopMenu/View Controller & Views/PopMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public class PopMenuDefaultAction: NSObject, PopMenuAction {
public func highlightActionView(_ highlight: Bool) {
DispatchQueue.main.async {
UIView.animate(withDuration: 0.26, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 9, options: self.highlighted ? .curveEaseIn : .curveEaseOut, animations: {
self.view.transform = self.highlighted ? CGAffineTransform.identity.scaledBy(x: 1.11, y: 1.11) : .identity
self.view.transform = self.highlighted ? CGAffineTransform.identity.scaledBy(x: 1.09, y: 1.09) : .identity
self.view.backgroundColor = self.highlighted ? self.backgroundColor.withAlphaComponent(0.25) : .clear
}, completion: nil)
}
Expand Down
44 changes: 29 additions & 15 deletions PopMenu/View Controller & Views/PopMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,18 @@ extension PopMenuViewController {
actionsView.alignment = .fill
actionsView.distribution = .fillEqually

for i in 0..<actions.count {
let action = actions[i]
action.font = self.appearance.popMenuFont
action.tintColor = action.color ?? self.appearance.popMenuColor.actionColor.color
action.cornerRadius = self.appearance.popMenuCornerRadius / 2
// Configure each action
actions.forEach { action in
action.font = appearance.popMenuFont
action.tintColor = action.color ?? appearance.popMenuColor.actionColor.color
action.cornerRadius = appearance.popMenuCornerRadius / 2
action.renderActionView()

if self.appearance.popMenuItemSeparatorHidden == false && i < actions.count - 1 {
addSeparatorViewTo(actionView: action.view)

// Give separator to each action but the last
if !action.isEqual(actions.last) {
addSeparator(to: action.view)
}

let tapper = UITapGestureRecognizer(target: self, action: #selector(menuDidTap(_:)))
tapper.delaysTouchesEnded = false

Expand All @@ -435,18 +436,31 @@ extension PopMenuViewController {
])
}

fileprivate func addSeparatorViewTo(actionView: UIView) {
/// Add separator view for the given action view.
///
/// - Parameters:
/// - separator: Separator style
/// - actionView: Action's view
fileprivate func addSeparator(to actionView: UIView) {
// Only setup separator if the style is neither 0 height or clear color
guard appearance.popMenuItemSeparator != .none() else { return }

let separator = appearance.popMenuItemSeparator

let separatorView = UIView()
separatorView.translatesAutoresizingMaskIntoConstraints = false
separatorView.backgroundColor = view.backgroundColor?.blackOrWhiteContrastingColor()
separatorView.backgroundColor = separator.color

actionView.addSubview(separatorView)

NSLayoutConstraint.activate([
separatorView.leadingAnchor.constraint(equalTo: actionView.leadingAnchor),
separatorView.trailingAnchor.constraint(equalTo: actionView.trailingAnchor),
separatorView.leftAnchor.constraint(equalTo: actionView.leftAnchor),
separatorView.rightAnchor.constraint(equalTo: actionView.rightAnchor),
separatorView.bottomAnchor.constraint(equalTo: actionView.bottomAnchor),
separatorView.heightAnchor.constraint(equalToConstant: 0.5)
])
separatorView.heightAnchor.constraint(equalToConstant: separator.height)
])
}

}

// MARK: - Gestures Control
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,19 @@ manager.popMenuAppearance.popMenuActionHeight = 65
menu.appearance.popMenuActionHeight = 65
```

Action Item Separator Hidden // Default: true
Action Item Separator // Default: none
---------

To set the action item separator visible:
To set the action item separator:

```swift
// The manager way
manager.popMenuAppearance.popMenuItemSeparatorHidden = false
manager.popMenuAppearance.popMenuItemSeparator = .none()
manager.popMenuAppearance.popMenuItemSeparator = .fill() // Default height of 0.5, white color with 0.5 opacity
manager.popMenuAppearance.popMenuItemSeparator = .fill(.yellow, height: 1) // Or set it yourself

// The manual way
menu.appearance.popMenuItemSeparatorHidden = false
menu.appearance.popMenuItemSeparator = ...
```

Status Bar Style // Default: automatic detection based on background color
Expand Down

0 comments on commit c5c5b60

Please sign in to comment.