Commit e15b9fff by Daniel Dahan

cleanup and removal of duplicate code

parent 454b272a
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import AppKit
import UIKit
public struct Color {
// clear
public static let clear: NSColor = NSColor.clearColor()
public static let clear: NSColor = NSColor.clear()
// white
public static let white: NSColor = NSColor.whiteColor()
public static let white: NSColor = NSColor.white()
// black
public static let black: NSColor = NSColor.blackColor()
public static let black: NSColor = NSColor.black()
// dark text
public struct darkText {
public static let primary: NSColor = NSColor.blackColor().colorWithAlphaComponent(0.87)
public static let secondary: NSColor = NSColor.blackColor().colorWithAlphaComponent(0.54)
public static let others: NSColor = NSColor.blackColor().colorWithAlphaComponent(0.38)
public static let dividers: NSColor = NSColor.blackColor().colorWithAlphaComponent(0.12)
public static let primary: NSColor = Color.black.withAlphaComponent(0.87)
public static let secondary: NSColor = Color.black.withAlphaComponent(0.54)
public static let others: NSColor = Color.black.withAlphaComponent(0.38)
public static let dividers: NSColor = Color.black.withAlphaComponent(0.12)
}
// light text
public struct lightText {
public static let primary: NSColor = NSColor.whiteColor()
public static let secondary: NSColor = NSColor.whiteColor().colorWithAlphaComponent(0.7)
public static let others: NSColor = NSColor.whiteColor().colorWithAlphaComponent(0.5)
public static let dividers: NSColor = NSColor.whiteColor().colorWithAlphaComponent(0.12)
public static let primary: NSColor = Color.white
public static let secondary: NSColor = Color.white.withAlphaComponent(0.7)
public static let others: NSColor = Color.white.withAlphaComponent(0.5)
public static let dividers: NSColor = Color.white.withAlphaComponent(0.12)
}
// red
......@@ -326,6 +326,7 @@ public struct Color {
public static let accent4: NSColor = NSColor(red: 255/255, green: 109/255, blue: 0/255, alpha: 1)
}
// deep orange
public struct deepOrange {
public static let lighten5: NSColor = NSColor(red: 251/255, green: 233/255, blue: 231/255, alpha: 1)
......@@ -344,6 +345,7 @@ public struct Color {
public static let accent4: NSColor = NSColor(red: 221/255, green: 44/255, blue: 0/255, alpha: 1)
}
// brown
public struct brown {
public static let lighten5: NSColor = NSColor(red: 239/255, green: 235/255, blue: 233/255, alpha: 1)
......
......@@ -30,18 +30,18 @@
import UIKit
public typealias MaterialAnimationRotationModeType = String
public typealias AnimateRotationModeType = String
public enum MaterialAnimationRotationMode {
public enum AnimateRotationMode {
case None
case Auto
case AutoReverse
}
/**
:name: MaterialAnimationRotationModeToValue
:name: AnimateRotationModeToValue
*/
public func MaterialAnimationRotationModeToValue(mode: MaterialAnimationRotationMode) -> MaterialAnimationRotationModeType? {
public func AnimateRotationModeToValue(mode: AnimateRotationMode) -> AnimateRotationModeType? {
switch mode {
case .none:
return nil
......@@ -52,15 +52,15 @@ public func MaterialAnimationRotationModeToValue(mode: MaterialAnimationRotation
}
}
public extension MaterialAnimation {
public extension Animate {
/**
:name: path
*/
public static func path(bezierPath: UIBezierPath, mode: MaterialAnimationRotationMode = .Auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation {
public static func path(bezierPath: UIBezierPath, mode: AnimateRotationMode = .Auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation {
let animation: CAKeyframeAnimation = CAKeyframeAnimation()
animation.keyPath = "position"
animation.path = bezierPath.CGPath
animation.rotationMode = MaterialAnimationRotationModeToValue(mode)
animation.rotationMode = AnimateRotationModeToValue(mode)
if let v: CFTimeInterval = duration {
animation.duration = v
}
......
......@@ -30,52 +30,46 @@
import UIKit
@objc(MaterialAnimationDelegate)
public protocol MaterialAnimationDelegate : MaterialDelegate {
optional func materialAnimationDidStart(animation: CAAnimation)
optional func materialAnimationDidStop(animation: CAAnimation, finished flag: Bool)
}
public typealias MaterialAnimationFillModeType = String
public typealias AnimationFillModeType = String
public enum MaterialAnimationFillMode {
case Forwards
case Backwards
case Both
case Removed
public enum AnimationFillMode {
case forwards
case backwards
case both
case removed
}
/**
:name: MaterialAnimationFillModeToValue
:name: AnimationFillModeToValue
*/
public func MaterialAnimationFillModeToValue(mode: MaterialAnimationFillMode) -> MaterialAnimationFillModeType {
public func AnimationFillModeToValue(mode: AnimationFillMode) -> AnimationFillModeType {
switch mode {
case .Forwards:
case .forwards:
return kCAFillModeForwards
case .Backwards:
case .backwards:
return kCAFillModeBackwards
case .Both:
case .both:
return kCAFillModeBoth
case .Removed:
case .removed:
return kCAFillModeRemoved
}
}
public typealias MaterialAnimationDelayCancelBlock = (cancel : Bool) -> Void
public typealias AnimationDelayCancelBlock = (cancel : Bool) -> Void
public struct MaterialAnimation {
public struct Animation {
/// Delay helper method.
public static func delay(time: TimeInterval, completion: ()-> Void) -> MaterialAnimationDelayCancelBlock? {
public static func delay(time: TimeInterval, completion: ()-> Void) -> AnimationDelayCancelBlock? {
func dispatch_later(completion: ()-> Void) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), completion)
DispatchQueue.main.after(when: DispatchTime.now() + time, execute: completion)
}
var cancelable: MaterialAnimationDelayCancelBlock?
var cancelable: AnimationDelayCancelBlock?
let delayed: MaterialAnimationDelayCancelBlock = { (cancel: Bool) in
let delayed: AnimationDelayCancelBlock = { (cancel: Bool) in
if !cancel {
dispatch_async(dispatch_get_main_queue(), completion)
DispatchQueue.main.asynchronously(execute: completion)
}
cancelable = nil
}
......@@ -92,7 +86,7 @@ public struct MaterialAnimation {
/**
:name: delayCancel
*/
public static func delayCancel(completion: MaterialAnimationDelayCancelBlock?) {
public static func delayCancel(completion: AnimationDelayCancelBlock?) {
completion?(cancel: true)
}
......@@ -101,7 +95,7 @@ public struct MaterialAnimation {
:name: animationDisabled
*/
public static func animationDisabled(animations: (() -> Void)) {
animateWithDuration(0, animations: animations)
animateWithDuration(duration: 0, animations: animations)
}
/**
......@@ -119,10 +113,10 @@ public struct MaterialAnimation {
/**
:name: animationGroup
*/
public static func animationGroup(animations: Array<CAAnimation>, duration: CFTimeInterval = 0.5) -> CAAnimationGroup {
public static func animationGroup(animations: [CAAnimation], duration: CFTimeInterval = 0.5) -> CAAnimationGroup {
let group: CAAnimationGroup = CAAnimationGroup()
group.fillMode = MaterialAnimationFillModeToValue(.Forwards)
group.removedOnCompletion = false
group.fillMode = AnimationFillModeToValue(mode: .forwards)
group.isRemovedOnCompletion = false
group.animations = animations
group.duration = duration
group.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
......@@ -133,8 +127,8 @@ public struct MaterialAnimation {
:name: animateWithDelay
*/
public static func animateWithDelay(delay d: CFTimeInterval, duration: CFTimeInterval, animations: (() -> Void), completion: (() -> Void)? = nil) {
delay(d) {
animateWithDuration(duration, animations: animations, completion: completion)
delay(time: d) {
animateWithDuration(duration: duration, animations: animations, completion: completion)
}
}
}
......@@ -217,12 +217,12 @@ public class Button: UIButton {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
......@@ -234,7 +234,7 @@ public class Button: UIButton {
*/
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -245,7 +245,7 @@ public class Button: UIButton {
*/
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -256,7 +256,7 @@ public class Button: UIButton {
*/
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -303,7 +303,7 @@ public class Button: UIButton {
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(animation: MaterialAnimation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......
......@@ -210,7 +210,7 @@ public class Capture : View, UIGestureRecognizerDelegate {
}
/// Content insert value.
public var contentInset: Inset = EdgeInsetsPresetToValue(preset: .square4) {
public var contentInset: EdgeInsets = EdgeInsetsPresetToValue(preset: .square4) {
didSet {
reloadView()
}
......@@ -544,17 +544,26 @@ public class Capture : View, UIGestureRecognizerDelegate {
}
/// Animates the tap and layer.
private func animateTapLayer(layer v: Layer, point: CGPoint) {
MaterialAnimation.animationDisabled {
private func animateTapLayer(layer: Layer, point: CGPoint) {
Animation.animationDisabled { [weak layer] in
guard let v = layer else {
return
}
v.transform = CATransform3DIdentity
v.position = point
v.isHidden = false
}
MaterialAnimation.animateWithDuration(duration: 0.25, animations: {
Animation.animateWithDuration(duration: 0.25, animations: { [weak layer] in
guard let v = layer else {
return
}
v.transform = CATransform3DMakeScale(0.5, 0.5, 1)
}) {
MaterialAnimation.delay(0.4) {
MaterialAnimation.animationDisabled {
Animation.delay(time: 0.4) { [weak layer] in
Animation.animationDisabled { [weak layer] in
guard let v = layer else {
return
}
v.isHidden = true
}
}
......
......@@ -393,7 +393,7 @@ public class Card: PulseView {
super.prepareView()
depthPreset = .depth1
dividerColor = Color.grey.lighten3
cornerRadiusPreset = .Radius1
cornerRadiusPreset = .cornerRadius1
}
/**
......
......@@ -32,28 +32,28 @@ import UIKit
public struct Color {
// clear
public static let clear: UIColor = UIColor.clearColor()
public static let clear: UIColor = UIColor.clear()
// white
public static let white: UIColor = UIColor.whiteColor()
public static let white: UIColor = UIColor.white()
// black
public static let black: UIColor = UIColor.blackColor()
public static let black: UIColor = UIColor.black()
// dark text
public struct darkText {
public static let primary: UIColor = Color.black.colorWithAlphaComponent(0.87)
public static let secondary: UIColor = Color.black.colorWithAlphaComponent(0.54)
public static let others: UIColor = Color.black.colorWithAlphaComponent(0.38)
public static let dividers: UIColor = Color.black.colorWithAlphaComponent(0.12)
public static let primary: UIColor = Color.black.withAlphaComponent(0.87)
public static let secondary: UIColor = Color.black.withAlphaComponent(0.54)
public static let others: UIColor = Color.black.withAlphaComponent(0.38)
public static let dividers: UIColor = Color.black.withAlphaComponent(0.12)
}
// light text
public struct lightText {
public static let primary: UIColor = Color.white
public static let secondary: UIColor = Color.white.colorWithAlphaComponent(0.7)
public static let others: UIColor = Color.white.colorWithAlphaComponent(0.5)
public static let dividers: UIColor = Color.white.colorWithAlphaComponent(0.12)
public static let secondary: UIColor = Color.white.withAlphaComponent(0.7)
public static let others: UIColor = Color.white.withAlphaComponent(0.5)
public static let dividers: UIColor = Color.white.withAlphaComponent(0.12)
}
// red
......
......@@ -41,8 +41,8 @@ public class FabButton: Button {
public override func prepareView() {
super.prepareView()
depthPreset = .depth1
shape = .circle
pulseAnimation = .CenterWithBacking
shapePreset = .circle
pulseAnimation = .centerWithBacking
pulseColor = Color.white
tintColor = Color.white
backgroundColor = Color.red.base
......
......@@ -40,7 +40,7 @@ public class FlatButton: Button {
*/
public override func prepareView() {
super.prepareView()
cornerRadiusPreset = .Radius1
cornerRadiusPreset = .cornerRadius1
contentEdgeInsetsPreset = .wideRectangle3
}
}
......@@ -40,7 +40,7 @@ public class IconButton: Button {
*/
public override func prepareView() {
super.prepareView()
cornerRadiusPreset = .Radius1
cornerRadiusPreset = .cornerRadius1
pulseAnimation = .center
}
}
......@@ -534,7 +534,7 @@ public class ImageCard: PulseView {
super.prepareView()
depthPreset = .depth1
dividerColor = Color.grey.lighten3
cornerRadiusPreset = .Radius1
cornerRadiusPreset = .cornerRadius1
}
/**
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public enum AnimationRotationMode {
case none
case auto
case autoReverse
}
/**
:name: AnimationRotationModeToValue
*/
public func AnimationRotationModeToValue(mode: AnimationRotationMode) -> String? {
switch mode {
case .none:
return nil
case .auto:
return kCAAnimationRotateAuto
case .autoReverse:
return kCAAnimationRotateAutoReverse
}
}
public extension Animation {
/**
:name: path
*/
public static func path(bezierPath: UIBezierPath, mode: AnimationRotationMode = .auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation {
let animation: CAKeyframeAnimation = CAKeyframeAnimation()
animation.keyPath = "position"
animation.path = bezierPath.cgPath
animation.rotationMode = AnimationRotationModeToValue(mode: mode)
if let v = duration {
animation.duration = v
}
return animation
}
}
......@@ -309,7 +309,7 @@ public class Layer: CAShapeLayer {
- Parameter animation: The currently running CAAnimation instance.
*/
public override func animationDidStart(_ animation: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(animation: animation)
(delegate as? AnimationDelegate)?.materialAnimationDidStart?(animation: animation)
}
/**
......@@ -330,7 +330,7 @@ public class Layer: CAShapeLayer {
}
}
}
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(animation: animation, finished: flag)
(delegate as? AnimationDelegate)?.materialAnimationDidStop?(animation: animation, finished: flag)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
......@@ -370,7 +370,7 @@ public class Layer: CAShapeLayer {
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(animation: MaterialAnimation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......
......@@ -118,7 +118,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
/// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity {
didSet {
contentsGravity = MaterialGravityToValue(contentsGravityPreset)
contentsGravity = MaterialGravityToValue(gravity: contentsGravityPreset)
}
}
......@@ -133,7 +133,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
}
/// A preset wrapper around contentInset.
public var contentEdgeInsetsPreset: Insets {
public var contentEdgeInsetsPreset: EdgeInsetsPreset {
get {
return grid.contentEdgeInsetsPreset
}
......@@ -153,9 +153,9 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
}
/// A preset wrapper around interimSpace.
public var interimSpacePreset: InterimSpace = .none {
public var interimSpacePreset: InterimSpacePreset = .none {
didSet {
interimSpace = InterimSpacePresetToValue(interimSpacePreset)
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
}
}
......@@ -208,7 +208,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
}
set(value) {
layer.frame.size.width = value
if .none != shape {
if .none != shapePreset {
layer.frame.size.height = value
}
}
......@@ -226,7 +226,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
}
set(value) {
layer.frame.size.height = value
if .none != shape {
if .none != shapePreset {
layer.frame.size.width = value
}
}
......@@ -310,12 +310,12 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
......@@ -327,7 +327,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
*/
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -338,7 +338,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
*/
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -349,7 +349,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
*/
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -396,7 +396,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(animation: MaterialAnimation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......
......@@ -31,7 +31,7 @@
import UIKit
@IBDesignable
public class MaterialCollectionView : UICollectionView {
public class MaterialCollectionView: UICollectionView {
/// A property that accesses the layer.frame.origin.x property.
@IBInspectable public var x: CGFloat {
get {
......@@ -73,12 +73,12 @@ public class MaterialCollectionView : UICollectionView {
}
/// A preset wrapper around contentInset.
public var contentEdgeInsetsPreset: Insets {
public var contentEdgeInsetsPreset: EdgeInsets {
get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentEdgeInsetsPreset
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset
}
set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentEdgeInsetsPreset = value
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset = value
}
}
......@@ -102,9 +102,9 @@ public class MaterialCollectionView : UICollectionView {
}
/// A preset wrapper around interimSpace.
public var interimSpacePreset: InterimSpace = .none {
public var interimSpacePreset: InterimSpacePreset = .none {
didSet {
interimSpace = InterimSpacePresetToValue(interimSpacePreset)
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
}
}
......
......@@ -118,7 +118,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
/// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity {
didSet {
contentsGravity = MaterialGravityToValue(contentsGravityPreset)
contentsGravity = MaterialGravityToValue(gravity: contentsGravityPreset)
}
}
......@@ -153,9 +153,9 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
}
/// A preset wrapper around interimSpace.
public var interimSpacePreset: InterimSpace = .none {
public var interimSpacePreset: InterimSpacePreset = .none {
didSet {
interimSpace = InterimSpacePresetToValue(interimSpacePreset)
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
}
}
......@@ -290,8 +290,8 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
self.init(frame: CGRect.zero)
}
public override func layoutSublayersOfLayer(layer: CALayer) {
super.layoutSublayersOfLayer(layer)
public override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
if self.layer == layer {
layoutShape()
layoutVisualLayer()
......@@ -310,12 +310,12 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
......@@ -327,7 +327,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
*/
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -338,7 +338,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
*/
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -349,7 +349,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
*/
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -390,12 +390,12 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
/// Sets the shadow path.
internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled {
if .none == depth {
if .none == depthPreset {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......
......@@ -30,10 +30,10 @@
import UIKit
public protocol MaterialCollectionViewDataSource : UICollectionViewDataSource {
public protocol MaterialCollectionViewDataSource: UICollectionViewDataSource {
/**
Retrieves the items for the collectionView.
- Returns: An Array of Arrays of MaterialDataSourceItem objects.
*/
func items() -> Array<MaterialDataSourceItem>
func items() -> [MaterialDataSourceItem]
}
......@@ -30,6 +30,6 @@
import UIKit
public protocol MaterialCollectionViewDelegate : MaterialDelegate, UICollectionViewDelegate {
public protocol MaterialCollectionViewDelegate: MaterialDelegate, UICollectionViewDelegate {
}
......@@ -30,7 +30,7 @@
import UIKit
public class MaterialCollectionViewLayout : UICollectionViewLayout {
public class MaterialCollectionViewLayout: UICollectionViewLayout {
/// Used to calculate the dimensions of the cells.
internal var offset: CGPoint = CGPoint.zero
......
......@@ -165,12 +165,12 @@ public class MaterialTableViewCell: UITableViewCell {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
......@@ -182,7 +182,7 @@ public class MaterialTableViewCell: UITableViewCell {
*/
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -193,7 +193,7 @@ public class MaterialTableViewCell: UITableViewCell {
*/
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -204,7 +204,7 @@ public class MaterialTableViewCell: UITableViewCell {
*/
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -243,9 +243,9 @@ public class MaterialTableViewCell: UITableViewCell {
if .none == depth {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
animate(Animation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......
......@@ -40,7 +40,7 @@ public enum PulseAnimation {
case pointWithBacking
}
internal extension MaterialAnimation {
internal extension Animation {
/**
Triggers the expanding animation.
- Parameter layer: Container CALayer.
......@@ -66,7 +66,7 @@ internal extension MaterialAnimation {
pulseLayers.insert(bLayer, at: 0)
visualLayer.addSublayer(bLayer)
MaterialAnimation.animationDisabled(animations: {
Animation.animationDisabled(animations: {
bLayer.frame = visualLayer.bounds
pLayer.bounds = CGRect(x: 0, y: 0, width: n, height: n)
......@@ -88,19 +88,19 @@ internal extension MaterialAnimation {
switch pulseAnimation {
case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(MaterialAnimation.backgroundColor(color: pulseColor.withAlphaComponent(pulseOpacity / 2), duration: duration), forKey: nil)
bLayer.add(Animation.backgroundColor(color: pulseColor.withAlphaComponent(pulseOpacity / 2), duration: duration), forKey: nil)
default:break
}
switch pulseAnimation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .point, .pointWithBacking:
pLayer.add(MaterialAnimation.scale(scale: 1, duration: duration), forKey: nil)
pLayer.add(Animation.scale(scale: 1, duration: duration), forKey: nil)
default:break
}
MaterialAnimation.delay(time: duration, completion: {
Animation.delay(time: duration) {
bLayer.setValue(true, forKey: "animated")
})
}
}
/**
......@@ -114,31 +114,35 @@ internal extension MaterialAnimation {
return
}
let animated: Bool? = bLayer.value(forKey: "animated") as? Bool
guard let animated = bLayer.value(forKey: "animated") as? Bool else {
return
}
Animation.delay(time: animated ? 0 : 0.15) {
guard let pLayer: CAShapeLayer = bLayer.sublayers?.first as? CAShapeLayer else {
return
}
MaterialAnimation.delay(time: true == animated ? 0 : 0.15) {
if let pLayer: CAShapeLayer = bLayer.sublayers?.first as? CAShapeLayer {
let duration: CFTimeInterval = 0.325
let duration = 0.325
switch pulseAnimation {
case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(MaterialAnimation.backgroundColor(color: pulseColor.withAlphaComponent(0), duration: 0.325), forKey: nil)
bLayer.add(Animation.backgroundColor(color: pulseColor.withAlphaComponent(0), duration: duration), forKey: nil)
default:break
}
switch pulseAnimation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .point, .pointWithBacking:
pLayer.addAnimation(MaterialAnimation.animationGroup(animations: [
MaterialAnimation.scale(scale: .Center == pulseAnimation ? 1 : 1.325),
MaterialAnimation.backgroundColor(pulseColor.colorWithAlphaComponent(0))
pLayer.add(Animation.animationGroup(animations: [
Animation.scale(scale: .center == pulseAnimation ? 1 : 1.325),
Animation.backgroundColor(color: pulseColor.withAlphaComponent(0))
], duration: duration), forKey: nil)
default:break
}
MaterialAnimation.delay(time: duration, completion: {
Animation.delay(time: duration) {
pLayer.removeFromSuperlayer()
bLayer.removeFromSuperlayer()
})
}
}
}
......
......@@ -54,12 +54,12 @@ public class PulseView: View {
*/
public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.delay(time: 0.35) { [weak self] in
guard let s = self else {
return
}
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
}
}
......@@ -71,7 +71,7 @@ public class PulseView: View {
*/
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -82,7 +82,7 @@ public class PulseView: View {
*/
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
/**
......@@ -93,6 +93,6 @@ public class PulseView: View {
*/
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
}
}
......@@ -41,7 +41,7 @@ public class RaisedButton: Button {
public override func prepareView() {
super.prepareView()
depthPreset = .depth1
cornerRadiusPreset = .Radius1
cornerRadiusPreset = .cornerRadius1
contentEdgeInsetsPreset = .wideRectangle3
backgroundColor = Color.white
}
......
......@@ -247,9 +247,9 @@ public class TextView: UITextView {
if .none == depth {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
animate(Animation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......
......@@ -30,17 +30,17 @@
import UIKit
public typealias MaterialAnimationTransitionType = String
public typealias MaterialAnimationTransitionSubTypeType = String
public typealias AnimationTransitionType = String
public typealias AnimationTransitionSubTypeType = String
public enum MaterialAnimationTransition {
public enum AnimationTransition {
case Fade
case MoveIn
case Push
case Reveal
}
public enum MaterialAnimationTransitionSubType {
public enum AnimationTransitionSubType {
case Right
case Left
case Top
......@@ -48,9 +48,9 @@ public enum MaterialAnimationTransitionSubType {
}
/**
:name: MaterialAnimationTransitionToValue
:name: AnimationTransitionToValue
*/
public func MaterialAnimationTransitionToValue(transition: MaterialAnimationTransition) -> MaterialAnimationTransitionType {
public func AnimationTransitionToValue(transition: AnimationTransition) -> AnimationTransitionType {
switch transition {
case .Fade:
return kCATransitionFade
......@@ -64,9 +64,9 @@ public func MaterialAnimationTransitionToValue(transition: MaterialAnimationTran
}
/**
:name: MaterialAnimationTransitionSubTypeToValue
:name: AnimationTransitionSubTypeToValue
*/
public func MaterialAnimationTransitionSubTypeToValue(direction: MaterialAnimationTransitionSubType) -> MaterialAnimationTransitionSubTypeType {
public func AnimationTransitionSubTypeToValue(direction: AnimationTransitionSubType) -> AnimationTransitionSubTypeType {
switch direction {
case .Right:
return kCATransitionFromRight
......@@ -79,15 +79,15 @@ public func MaterialAnimationTransitionSubTypeToValue(direction: MaterialAnimati
}
}
public extension MaterialAnimation {
public extension Animation {
/**
:name: transition
*/
public static func transition(type: MaterialAnimationTransition, direction: MaterialAnimationTransitionSubType? = nil, duration: CFTimeInterval? = nil) -> CATransition {
public static func transition(type: AnimationTransition, direction: AnimationTransitionSubType? = nil, duration: CFTimeInterval? = nil) -> CATransition {
let animation: CATransition = CATransition()
animation.type = MaterialAnimationTransitionToValue(type)
animation.type = AnimationTransitionToValue(transition: type)
if let d = direction {
animation.subtype = MaterialAnimationTransitionSubTypeToValue(d)
animation.subtype = AnimationTransitionSubTypeToValue(direction: d)
}
if let v: CFTimeInterval = duration {
animation.duration = v
......
......@@ -302,7 +302,7 @@ public class View: UIView {
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(animation: MaterialAnimation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment