Skip to content

Commit

Permalink
added more header docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Feb 2, 2017
1 parent ccaaaab commit ad5a1af
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 84 deletions.
8 changes: 8 additions & 0 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module: Hero
author: Luke Zhao
author_url: http://lkzhao.com
github_url: https://github.com/lkzhao/Hero
swift_version: 3.0.2
source_directory: Examples
readme: README.md
theme: fullwidth
2 changes: 2 additions & 0 deletions Examples/HeroExamples/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Expand Down
4 changes: 2 additions & 2 deletions Sources/BasePreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import UIKit

public class BasePreprocessor:HeroPreprocessor {
class BasePreprocessor:HeroPreprocessor {
var context:HeroContext { return Hero.shared.context }
public func process(fromViews:[UIView], toViews:[UIView]) {}
func process(fromViews:[UIView], toViews:[UIView]) {}
}
79 changes: 39 additions & 40 deletions Sources/CascadePreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,53 @@

import UIKit


public class CascadePreprocessor:BasePreprocessor {
public enum CascadeDirection{
case topToBottom
case bottomToTop
case leftToRight
case rightToLeft
case radial(center:CGPoint)
case inverseRadial(center:CGPoint)
var comparator: (UIView, UIView) -> Bool {
switch self {
case .topToBottom:
return { return $0.frame.minY < $1.frame.minY }
case .bottomToTop:
return { return $0.frame.maxY == $1.frame.maxY ? $0.frame.maxX > $1.frame.maxX : $0.frame.maxY > $1.frame.maxY }
case .leftToRight:
return { return $0.frame.minX < $1.frame.minX }
case .rightToLeft:
return { return $0.frame.maxX > $1.frame.maxX }
case .radial(let center):
return { return $0.center.distance(center) < $1.center.distance(center) }
case .inverseRadial(let center):
return { return $0.center.distance(center) > $1.center.distance(center) }
}
public enum CascadeDirection {
case topToBottom
case bottomToTop
case leftToRight
case rightToLeft
case radial(center:CGPoint)
case inverseRadial(center:CGPoint)
var comparator: (UIView, UIView) -> Bool {
switch self {
case .topToBottom:
return { return $0.frame.minY < $1.frame.minY }
case .bottomToTop:
return { return $0.frame.maxY == $1.frame.maxY ? $0.frame.maxX > $1.frame.maxX : $0.frame.maxY > $1.frame.maxY }
case .leftToRight:
return { return $0.frame.minX < $1.frame.minX }
case .rightToLeft:
return { return $0.frame.maxX > $1.frame.maxX }
case .radial(let center):
return { return $0.center.distance(center) < $1.center.distance(center) }
case .inverseRadial(let center):
return { return $0.center.distance(center) > $1.center.distance(center) }
}

init?(_ string: String) {
switch string {
case "bottomToTop":
self = .bottomToTop
case "leftToRight":
self = .leftToRight
case "rightToLeft":
self = .rightToLeft
case "topToBottom":
self = .topToBottom
default:
return nil
}
}

init?(_ string: String) {
switch string {
case "bottomToTop":
self = .bottomToTop
case "leftToRight":
self = .leftToRight
case "rightToLeft":
self = .rightToLeft
case "topToBottom":
self = .topToBottom
default:
return nil
}
}
}

override public func process(fromViews:[UIView], toViews:[UIView]) {
class CascadePreprocessor:BasePreprocessor {
override func process(fromViews:[UIView], toViews:[UIView]) {
process(views:fromViews)
process(views:toViews)
}

private func process(views:[UIView]){
func process(views:[UIView]){
for (viewIndex, fv) in views.enumerated() {
guard let (deltaTime, direction, delayMatchedViews) = context[fv]?.cascade else { continue }

Expand Down
71 changes: 44 additions & 27 deletions Sources/Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,43 @@

import UIKit

/**
### The singleton class/object for controlling interactive transitions.

```swift
Hero.shared
```

#### Use the following methods for controlling the interactive transition:

```swift
func update(progress:Double)
func end()
func cancel()
func apply(modifiers:[HeroModifier], to view:UIView)
```
*/
public class Hero:NSObject {
/**
## The Singleton object for controlling interactive transitions.

var presenting:Bool
var interactive:Bool

### Use the following methods for controlling the interactive transition:
func update(progress:Double)
func end()
func cancel()
func apply(modifiers:[HeroModifier], to view:UIView)
*/
// MARK: Shared Access

/// Shared singleton object for controlling the transition
public static let shared = Hero()

// MARK: Properties

/// destination view controller
public fileprivate(set) weak var toViewController:UIViewController?
/// source view controller
public fileprivate(set) weak var fromViewController:UIViewController?
/// context object holding transition informations
public fileprivate(set) var context: HeroContext!
/// whether or not we are presenting the destination view controller
public fileprivate(set) var presenting = true
/// whether or not we are handling transition interactively
public var interactive:Bool {
return displayLink == nil
}
/// progress of the current transition. 0 if no transition is happening
public fileprivate(set) var progress:Double = 0 {
didSet{
if transitioning, progress != oldValue {
Expand All @@ -69,20 +84,20 @@ public class Hero:NSObject {
}
}
}

/// whether or not we are doing a transition
public var transitioning: Bool {
return transitionContainer != nil
}

// container we created to hold all animating views, will be a subview of the
// transitionContainer when transitioning
/// container we created to hold all animating views, will be a subview of the
/// transitionContainer when transitioning
public fileprivate(set) var container: UIView!

// this is the container supplied by UIKit
/// this is the container supplied by UIKit
fileprivate var transitionContainer:UIView!

// a UIViewControllerContextTransitioning object provided by UIKit,
// might be nil when transitioning. This happens when calling heroReplaceViewController
/// a UIViewControllerContextTransitioning object provided by UIKit,
/// might be nil when transitioning. This happens when calling heroReplaceViewController
fileprivate weak var transitionContext: UIViewControllerContextTransitioning?

fileprivate var completionCallback: ((Bool) -> Void)?
Expand All @@ -92,7 +107,7 @@ public class Hero:NSObject {
fileprivate var progressUpdateObservers:[HeroProgressUpdateObserver]?


// max duration needed by the default animator and plugins
/// max duration needed by the default animator and plugins
fileprivate var totalDuration: TimeInterval = 0.0
fileprivate var duration: TimeInterval = 0.0
fileprivate var beginTime:TimeInterval?{
Expand Down Expand Up @@ -130,7 +145,7 @@ public class Hero:NSObject {


fileprivate var finishing:Bool = true
// true if transitioning inside a UINavigationController or UITabBarController
/// true if transitioning inside a UINavigationController or UITabBarController
fileprivate var inContainerController = false

fileprivate var toView: UIView { return toViewController!.view }
Expand All @@ -145,8 +160,9 @@ public class Hero:NSObject {
fileprivate override init(){}
}

// control interactive transition
public extension Hero {
// MARK: Interactive Transition

/**
Update the progress for the interactive transition.
- Parameters:
Expand Down Expand Up @@ -221,8 +237,9 @@ public extension Hero {
}
}

// observe progress
public extension Hero{
// MARK: Observe Progress

/**
Receive callbacks on each animation frame.
Observers will be cleaned when transition completes
Expand All @@ -238,7 +255,7 @@ public extension Hero{
}
}

// methods for transition
// internal methods for transition
internal extension Hero {
func start() {
if let fvc = fromViewController, let tvc = toViewController {
Expand Down Expand Up @@ -284,15 +301,13 @@ internal extension Hero {
container.addSubview(fromView)
container.insertSubview(toView, belowSubview: fromView)
container.backgroundColor = toView.backgroundColor

toView.updateConstraints()
toView.setNeedsLayout()
toView.layoutIfNeeded()

context = HeroContext(container:container, fromView: fromView, toView:toView)

// ask each preprocessor to process

for processor in processors {
processor.process(fromViews: context.fromViews, toViews: context.toViews)
}
Expand Down Expand Up @@ -437,7 +452,7 @@ internal extension Hero {
}
}

// plugin support
// MARK: Plugin Support
internal extension Hero {
static func isEnabled(plugin: HeroPlugin.Type) -> Bool {
return enabledPlugins.index(where: { return $0 == plugin}) != nil
Expand Down Expand Up @@ -490,6 +505,8 @@ fileprivate extension Hero {



// MARK: UIKit Protocol Conformance

/*****************************
* UIKit protocol extensions *
*****************************/
Expand Down
2 changes: 1 addition & 1 deletion Sources/HeroDebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protocol HeroDebugViewDelegate {
func onDone()
}

public class HeroDebugView: UIView {
class HeroDebugView: UIView {
var backgroundView: UIView!
var debugSlider: UISlider!
var perspectiveButton: UIButton!
Expand Down
6 changes: 3 additions & 3 deletions Sources/HeroModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ extension HeroModifier {
- delayMatchedViews: whether or not to delay matched subviews until all cascading animation have started
*/
public static func cascade(delta: TimeInterval = 0.02,
direction: CascadePreprocessor.CascadeDirection = .topToBottom,
direction: CascadeDirection = .topToBottom,
delayMatchedViews: Bool = false) -> HeroModifier {
return HeroModifier { targetState in
targetState.cascade = (delta, direction, delayMatchedViews)
Expand Down Expand Up @@ -359,9 +359,9 @@ extension HeroModifier {
case "arc":
modifier = .arc(intensity: parameters.getCGFloat(0) ?? 1)
case "cascade":
var cascadeDirection = CascadePreprocessor.CascadeDirection.topToBottom
var cascadeDirection = CascadeDirection.topToBottom
if let directionString = parameters.get(1),
let direction = CascadePreprocessor.CascadeDirection(directionString) {
let direction = CascadeDirection(directionString) {
cascadeDirection = direction
}
modifier = .cascade(delta: parameters.getDouble(0) ?? 0.02, direction: cascadeDirection, delayMatchedViews:parameters.getBool(2) ?? false)
Expand Down
2 changes: 1 addition & 1 deletion Sources/HeroTargetState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct HeroTargetState {
internal var zPosition: CGFloat?
internal var zPositionIfMatched: CGFloat?
internal var source: String?
internal var cascade: (TimeInterval, CascadePreprocessor.CascadeDirection, Bool)?
internal var cascade: (TimeInterval, CascadeDirection, Bool)?
internal var ignoreSubviewModifiers: Bool?
internal var useGlobalCoordinateSpace: Bool?

Expand Down
6 changes: 3 additions & 3 deletions Sources/IgnoreSubviewModifiersPreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

import UIKit

public class IgnoreSubviewModifiersPreprocessor:BasePreprocessor {
override public func process(fromViews:[UIView], toViews:[UIView]) {
class IgnoreSubviewModifiersPreprocessor: BasePreprocessor {
override func process(fromViews:[UIView], toViews:[UIView]) {
process(views:fromViews)
process(views:toViews)
}

private func process(views:[UIView]){
func process(views:[UIView]){
for (viewIndex, view) in views.enumerated(){
guard let recursive = context[view]?.ignoreSubviewModifiers else { continue }
var parentView = view
Expand Down
4 changes: 2 additions & 2 deletions Sources/MatchPreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import UIKit

public class MatchPreprocessor:BasePreprocessor {
override public func process(fromViews:[UIView], toViews:[UIView]) {
class MatchPreprocessor: BasePreprocessor {
override func process(fromViews:[UIView], toViews:[UIView]) {
for tv in toViews{
guard let id = tv.heroID, let fv = context.sourceView(for: id) else { continue }

Expand Down
7 changes: 2 additions & 5 deletions Sources/SourcePreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import UIKit

class SourcePreprocessor:BasePreprocessor {
override public func process(fromViews:[UIView], toViews:[UIView]) {
override func process(fromViews:[UIView], toViews:[UIView]) {
for fv in fromViews{
guard let id = context[fv]?.source,
let tv = context.destinationView(for: id) else { continue }
Expand All @@ -35,11 +35,8 @@ class SourcePreprocessor:BasePreprocessor {
prepareFor(view: tv, targetView: fv)
}
}
}

extension SourcePreprocessor {

fileprivate func prepareFor(view:UIView, targetView:UIView){
func prepareFor(view:UIView, targetView:UIView){
let targetPos = context.container.convert(targetView.layer.position, from: targetView.superview!)

var state = context[view]!
Expand Down

0 comments on commit ad5a1af

Please sign in to comment.