Skip to content

Commit

Permalink
Merge pull request #13 from mvolpato/master
Browse files Browse the repository at this point in the history
Addresses XCode warnings and issue #10

Great, thanks @mvolpato ! 👍
  • Loading branch information
Toine Heuvelmans authored May 27, 2019
2 parents c1681ea + 540c6a4 commit 2a3e3b9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,19 @@ extension InteractiveZoomTransitionController : SharedElementProvider {

let initialFrame: CGRect
let targetFrame: CGRect

// Get top margin, depending on possible safe area
var yMargin = CollectionViewController.margin

if #available(iOS 11.0, *) {
yMargin += toViewController.collectionView.safeAreaInsets.top
}

if isPresenting {
initialFrame = fromViewController.targetFrame
targetFrame = CGRect(origin: CGPoint(x: CollectionViewController.margin, y: CollectionViewController.margin), size: header.image.frame.size)
targetFrame = CGRect(origin: CGPoint(x: CollectionViewController.margin, y: yMargin), size: header.image.frame.size)
} else {
initialFrame = CGRect(origin: CGPoint(x: CollectionViewController.margin, y: CollectionViewController.margin), size: header.image.frame.size)
initialFrame = CGRect(origin: CGPoint(x: CollectionViewController.margin, y: yMargin), size: header.image.frame.size)
targetFrame = toViewController.targetFrame
}

Expand Down
18 changes: 9 additions & 9 deletions Transition/Classes/Helpers/AnimationRange+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,40 @@ public enum AnimationRangePosition {
}

public extension AnimationRangePosition {
public var reversed: AnimationRangePosition {
var reversed: AnimationRangePosition {
switch self {
case .contains: return .contains
case .isBefore: return .isAfter
case .isAfter: return .isBefore
}
}
public func reversed(_ shouldReverse: Bool) -> AnimationRangePosition {
func reversed(_ shouldReverse: Bool) -> AnimationRangePosition {
return shouldReverse ? reversed : self
}
}


public extension AnimationRange {

public var length: AnimationFraction {
var length: AnimationFraction {
return end - start
}

/// Returns true if the range contains the fraction
public func contains(_ fraction: AnimationFraction) -> Bool {
func contains(_ fraction: AnimationFraction) -> Bool {
return position(fraction) == .contains
}
/// Returns true if the range is positioned before the fraction
public func isBefore(_ fraction: AnimationFraction) -> Bool {
func isBefore(_ fraction: AnimationFraction) -> Bool {
return position(fraction) == .isBefore
}
/// Returns true if the range is positioned after the fraction
public func isAfter(_ fraction: AnimationFraction) -> Bool {
func isAfter(_ fraction: AnimationFraction) -> Bool {
return position(fraction) == .isAfter
}

/// Returns the position of the range relative to the given fraction
public func position(_ fraction: AnimationFraction) -> AnimationRangePosition {
func position(_ fraction: AnimationFraction) -> AnimationRangePosition {

if end < fraction {
return .isBefore
Expand All @@ -75,7 +75,7 @@ public extension AnimationRange {

/// Returns the distance (either measured from end or start, if the range is before or after respectively) relative to the fraction.
/// Returns 0 if the range contains the fraction
public func distance(to fraction: AnimationFraction) -> AnimationFraction {
func distance(to fraction: AnimationFraction) -> AnimationFraction {
switch position(fraction) {
case .isBefore: return fraction - end
case .isAfter: return start - fraction
Expand All @@ -87,7 +87,7 @@ public extension AnimationRange {
/// If the position is before `fraction`, it'll return 1.
/// If the position is after `fraction`, it'll return 0.
/// Otherwise it maps fraction to the range.
public func relativeFractionComplete(to fraction: AnimationFraction) -> AnimationFraction {
func relativeFractionComplete(to fraction: AnimationFraction) -> AnimationFraction {
switch position(fraction) {
case .isBefore: return 1.0
case .isAfter: return 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public extension UIViewControllerContextTransitioning {
one presenting the "to” view controller or is the one being replaced by the "to”
view controller.
*/
public var fromViewController: UIViewController! {
var fromViewController: UIViewController! {
return self.viewController(forKey: .from)
}

/**
Identifies the view controller that is visible at the end of a completed transition.
This view controller is the one being presented.
*/
public var toViewController: UIViewController! {
var toViewController: UIViewController! {
return self.viewController(forKey: .to)
}

Expand All @@ -50,15 +50,15 @@ public extension UIViewControllerContextTransitioning {
Identifies the view that is shown at the beginning of the transition (and at the end
of a canceled transition). This view is typically the presenting view controller’s view.
*/
public var fromView: UIView! {
var fromView: UIView! {
return self.view(forKey: .from) ?? fromViewController.view
}

/**
Identifies the view that is shown at the end of a completed transition. This view is
typically the presented view controller’s view but may also be an ancestor of that view.
*/
public var toView: UIView! {
var toView: UIView! {
return self.view(forKey: .to) ?? toViewController.view
}
}
Expand All @@ -70,7 +70,7 @@ public extension UIViewControllerContextTransitioning {
This installs the to and from view when necessary, based on the operation.
It returns the top-most view which is either the fromView or toView.
*/
@discardableResult public func defaultViewSetup(for operation: TransitionOperation) -> UIView? {
@discardableResult func defaultViewSetup(for operation: TransitionOperation) -> UIView? {
switch operation {
case .navigation(let navigationOperation): return defaultViewSetup(for: navigationOperation)
case .modal(let modalOperation): return defaultViewSetup(for: modalOperation)
Expand All @@ -79,7 +79,7 @@ public extension UIViewControllerContextTransitioning {
}
}

public func defaultViewSetup(for navigationOperation: UINavigationController.Operation) -> UIView? {
func defaultViewSetup(for navigationOperation: UINavigationController.Operation) -> UIView? {
switch navigationOperation {
case .push:
containerView.addSubview(toView)
Expand All @@ -93,7 +93,7 @@ public extension UIViewControllerContextTransitioning {
return navigationOperation == .push ? toView : fromView
}

public func defaultViewSetup(for modalOperation: UIViewControllerModalOperation) -> UIView? {
func defaultViewSetup(for modalOperation: UIViewControllerModalOperation) -> UIView? {
switch modalOperation {
case .present:
containerView.addSubview(toView)
Expand All @@ -107,7 +107,7 @@ public extension UIViewControllerContextTransitioning {
return modalOperation == .present ? toView : fromView
}

public func defaultViewSetup(for tabBarOperation: UITabBarControllerOperation) -> UIView? {
func defaultViewSetup(for tabBarOperation: UITabBarControllerOperation) -> UIView? {
guard tabBarOperation != .none else { return nil }
containerView.addSubview(toView)
toView.frame = finalFrame(for: toViewController)
Expand Down
2 changes: 1 addition & 1 deletion Transition/Classes/Transition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public extension Transition {

/// The effective duration is the duration, influenced by the presence of any timingParameter (in animation or interaction)
/// that has an implicit duration due to a spring timing curve configuration.
public var effectiveDuration: TimeInterval {
var effectiveDuration: TimeInterval {
/// First check if there's any animationLayer that has an implicit duration (due to spring timing parameters) that
/// would effectively stretch up the total duration (i.e. lasting beyond transition.duration).
let animationLayersDuration = animation.layers.reduce(duration) { (currentDuration, animationLayer) -> TimeInterval in
Expand Down
6 changes: 3 additions & 3 deletions Transition/Classes/TransitionDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,17 @@ fileprivate extension TransitionDriver {
return uniqueParticipatingViewControllers.compactMap { $0 as? TransitionPhaseDelegate }
}

fileprivate func willTransition(with sharedElement: SharedElement?) {
func willTransition(with sharedElement: SharedElement?) {
guard let fromViewController = context.fromViewController, let toViewController = context.toViewController else { return }
uniqueTransitionPhaseDelegates.forEach { $0.willTransition(from: fromViewController, to: toViewController, with: sharedElement) }
}

fileprivate func didTransition(with sharedElement: SharedElement?) {
func didTransition(with sharedElement: SharedElement?) {
guard let fromViewController = context.fromViewController, let toViewController = context.toViewController else { return }
uniqueTransitionPhaseDelegates.forEach { $0.didTransition(from: fromViewController, to: toViewController, with: sharedElement) }
}

fileprivate func cancelledTransition(with sharedElement: SharedElement?) {
func cancelledTransition(with sharedElement: SharedElement?) {
guard let fromViewController = context.fromViewController, let toViewController = context.toViewController else { return }
uniqueTransitionPhaseDelegates.forEach { $0.cancelledTransition(from: fromViewController, to: toViewController, with: sharedElement) }
}
Expand Down
2 changes: 1 addition & 1 deletion Transition/Classes/TransitionOperationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ public class TransitionOperationContext {
* view controller of the window, a parent view controller that is marked as defining the current context,
* or the last view controller that was presented. This view controller may or may not be the same as the one in the source parameter."
*/
internal(set) var sourceViewController: UIViewController?
var sourceViewController: UIViewController?
}

0 comments on commit 2a3e3b9

Please sign in to comment.