Skip to content

Commit

Permalink
project cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Feb 11, 2017
1 parent ea762ec commit 8bea613
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 127 deletions.
5 changes: 5 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ disabled_rules: # rule identifiers to exclude from running
- missing_docs
- unused_closure_parameter
- force_cast
- weak_delegate
- variable_name
- cyclomatic_complexity
- function_body_length
- todo

opt_in_rules: # some rules are only opt-in
- empty_count
Expand Down
14 changes: 14 additions & 0 deletions Examples/HeroExamples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@
isa = PBXNativeTarget;
buildConfigurationList = A306D3BE1E1C7A2E00B6C23A /* Build configuration list for PBXNativeTarget "Hero (iOS)" */;
buildPhases = (
B16ECD011E4FA11500EAE0E0 /* ShellScript */,
A306D3AD1E1C7A2E00B6C23A /* Sources */,
A306D3AE1E1C7A2E00B6C23A /* Frameworks */,
A306D3AF1E1C7A2E00B6C23A /* Headers */,
Expand Down Expand Up @@ -749,6 +750,19 @@
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
B16ECD011E4FA11500EAE0E0 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
B60F2CF0B495F2D785FF29A1 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class AnimationSelectTableViewController: UITableViewController {
Hero.shared.setDefaultAnimationForNextTransition(animations[indexPath.item])
Hero.shared.setContainerColorForNextTransition(.lightGray)


hero_replaceViewController(with: vc)
}

Expand Down
13 changes: 6 additions & 7 deletions Sources/CG+Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ internal func - (left: CGPoint, right: CGPoint) -> CGPoint {
internal func / (left: CGPoint, right: CGFloat) -> CGPoint {
return CGPoint(x: left.x/right, y: left.y/right)
}
internal func /(left: CGPoint, right: CGPoint) -> CGPoint {
internal func / (left: CGPoint, right: CGPoint) -> CGPoint {
return CGPoint(x: left.x/right.x, y: left.y/right.y)
}
internal func *(left: CGPoint, right: CGFloat) -> CGPoint {
internal func * (left: CGPoint, right: CGFloat) -> CGPoint {
return CGPoint(x: left.x*right, y: left.y*right)
}
internal func *(left: CGPoint, right: CGSize) -> CGPoint {
internal func * (left: CGPoint, right: CGSize) -> CGPoint {
return CGPoint(x: left.x*right.width, y: left.y*right.width)
}
internal func *(left: CGFloat, right: CGPoint) -> CGPoint {
internal func * (left: CGFloat, right: CGPoint) -> CGPoint {
return right * left
}

Expand All @@ -128,14 +128,13 @@ internal func abs(_ p: CGPoint) -> CGPoint {
internal func * (left: CGSize, right: CGFloat) -> CGSize {
return CGSize(width: left.width*right, height: left.height*right)
}
internal func *(left: CGSize, right: CGSize) -> CGSize {
internal func * (left: CGSize, right: CGSize) -> CGSize {
return CGSize(width: left.width*right.width, height: left.height*right.width)
}
internal func /(left: CGSize, right: CGSize) -> CGSize {
internal func / (left: CGSize, right: CGSize) -> CGSize {
return CGSize(width: left.width/right.width, height: left.height/right.height)
}


internal func == (lhs: CATransform3D, rhs: CATransform3D) -> Bool {
var lhs = lhs
var rhs = rhs
Expand Down
8 changes: 4 additions & 4 deletions Sources/CascadePreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum CascadeDirection {
return { return $0.center.distance(center) > $1.center.distance(center) }
}
}

init?(_ string: String) {
switch string {
case "bottomToTop":
Expand All @@ -69,7 +69,7 @@ class CascadePreprocessor: BasePreprocessor {
process(views:fromViews)
process(views:toViews)
}

func process(views: [UIView]) {
for view in views {
guard let (deltaTime, direction, delayMatchedViews) = context[view]?.cascade else { continue }
Expand All @@ -87,7 +87,7 @@ class CascadePreprocessor: BasePreprocessor {
for (i, subview) in sortedSubviews.enumerated() {
let delay = TimeInterval(i) * deltaTime + initialDelay

func applyDelay(view:UIView) {
func applyDelay(view: UIView) {
if context.pairedView(for: view) == nil {
context[view]?.delay = delay
} else if delayMatchedViews, let paired = context.pairedView(for: view) {
Expand All @@ -98,7 +98,7 @@ class CascadePreprocessor: BasePreprocessor {
applyDelay(view: subview)
}
}

applyDelay(view: subview)
}
}
Expand Down
49 changes: 19 additions & 30 deletions Sources/Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Hero: HeroBaseController {

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

// MARK: Properties

/// destination view controller
Expand All @@ -61,7 +61,7 @@ public class Hero: HeroBaseController {
}
}
}

/// a UIViewControllerContextTransitioning object provided by UIKit,
/// might be nil when transitioning. This happens when calling heroReplaceViewController
fileprivate weak var transitionContext: UIViewControllerContextTransitioning?
Expand All @@ -80,19 +80,19 @@ public class Hero: HeroBaseController {

fileprivate var inNavigationController = false
fileprivate var inTabBarController = false
fileprivate var inContainerController:Bool {
fileprivate var inContainerController: Bool {
return inNavigationController || inTabBarController
}
fileprivate var toOverFullScreen:Bool {
fileprivate var toOverFullScreen: Bool {
return !inContainerController && toViewController!.modalPresentationStyle == .overFullScreen
}
fileprivate var fromOverFullScreen:Bool {
fileprivate var fromOverFullScreen: Bool {
return !inContainerController && fromViewController!.modalPresentationStyle == .overFullScreen
}

fileprivate var toView: UIView { return toViewController!.view }
fileprivate var fromView: UIView { return fromViewController!.view }

fileprivate override init() { super.init() }
}

Expand All @@ -103,7 +103,6 @@ public extension Hero {
defaultAnimation = .none
}


/// Set the default animation for next transition
/// This usually overrides rootView's heroModifiers during the transition
///
Expand All @@ -112,7 +111,6 @@ public extension Hero {
defaultAnimation = animation
}


/// Set the container color for next transition
///
/// - Parameter color: container color
Expand All @@ -130,7 +128,7 @@ internal extension Hero {
$0.heroWillStartTransition?()
$0.heroWillStartAnimatingTo?(viewController: tvc)
}

closureProcessForHeroDelegate(vc: tvc) {
$0.heroWillStartTransition?()
$0.heroWillStartAnimatingFrom?(viewController: fvc)
Expand All @@ -141,17 +139,17 @@ internal extension Hero {
fullScreenSnapshot = transitionContainer.window!.snapshotView(afterScreenUpdates: true)!
transitionContainer.window!.addSubview(fullScreenSnapshot)

if let oldSnapshots = fromViewController?.hero_storedSnapshots {
if let oldSnapshots = fromViewController?.heroStoredSnapshots {
for snapshot in oldSnapshots {
snapshot.removeFromSuperview()
}
fromViewController?.hero_storedSnapshots = nil
fromViewController?.heroStoredSnapshots = nil
}
if let oldSnapshots = toViewController?.hero_storedSnapshots {
if let oldSnapshots = toViewController?.heroStoredSnapshots {
for snapshot in oldSnapshots {
snapshot.removeFromSuperview()
}
toViewController?.hero_storedSnapshots = nil
toViewController?.heroStoredSnapshots = nil
}

prepareForTransition()
Expand Down Expand Up @@ -219,13 +217,13 @@ internal extension Hero {
context.unhide(rootView: toView)
context.removeSnapshots(rootView: toView)
context.storeViewAlpha(rootView: fromView)
fromViewController!.hero_storedSnapshots = context.snapshots(rootView: fromView)
fromViewController!.heroStoredSnapshots = context.snapshots(rootView: fromView)
} else if !finished && !presenting && fromOverFullScreen {
// cancelled dismissing a overFullScreen VC
context.unhide(rootView: fromView)
context.removeSnapshots(rootView: fromView)
context.storeViewAlpha(rootView: toView)
toViewController!.hero_storedSnapshots = context.snapshots(rootView: toView)
toViewController!.heroStoredSnapshots = context.snapshots(rootView: toView)
} else {
context.unhideAll()
context.removeAllSnapshots()
Expand All @@ -240,7 +238,7 @@ internal extension Hero {
// bug: http://openradar.appspot.com/radar?id=5320103646199808
UIApplication.shared.keyWindow!.addSubview(presenting ? fromView : toView)
}

// use temp variables to remember these values
// because we have to reset everything before calling
// any delegate or completion block
Expand Down Expand Up @@ -293,7 +291,7 @@ internal extension Hero {

internal extension Hero {

func shift(direction: HeroAnimationType.Direction, appearing:Bool, size: CGSize? = nil, transpose: Bool = false) -> CGPoint {
func shift(direction: HeroAnimationType.Direction, appearing: Bool, size: CGSize? = nil, transpose: Bool = false) -> CGPoint {
let size = size ?? container.bounds.size
let rtn: CGPoint
switch direction {
Expand Down Expand Up @@ -424,32 +422,23 @@ internal extension Hero {

// delegate helper
fileprivate extension Hero {
func closureProcessForHeroDelegate<T: UIViewController>(vc: T, closure: (HeroViewControllerDelegate)->()) {
func closureProcessForHeroDelegate<T: UIViewController>(vc: T, closure: (HeroViewControllerDelegate) -> Void) {
if let delegate = vc as? HeroViewControllerDelegate {
closure(delegate)
}

if let navigationController = vc as? UINavigationController,
let delegate = navigationController.topViewController as? HeroViewControllerDelegate {
closure(delegate)
}

if let tabBarController = vc as? UITabBarController,
let delegate = tabBarController.viewControllers?[tabBarController.selectedIndex] as? HeroViewControllerDelegate {
closure(delegate)
}
}
}










// MARK: UIKit Protocol Conformance

/*****************************
Expand Down
4 changes: 1 addition & 3 deletions Sources/HeroBaseController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,13 @@ public class HeroBaseController: NSObject {
}
}


internal var finishing: Bool = true

internal var processors: [HeroPreprocessor]!
internal var animators: [HeroAnimator]!
internal var plugins: [HeroPlugin]!

internal var animatingViews: [(fromViews:[UIView], toViews:[UIView])]!
internal var animatingViews: [(fromViews: [UIView], toViews: [UIView])]!

internal static var enabledPlugins: [HeroPlugin.Type] = []

Expand Down Expand Up @@ -284,7 +283,6 @@ internal extension HeroBaseController {
}
}


/// Actually animate the views
/// subclass should call `prepareForTransition` & `prepareForAnimation` before calling `animate`
func animate() {
Expand Down
Loading

0 comments on commit 8bea613

Please sign in to comment.