Skip to content

Commit

Permalink
Add .leading and .trailing animation direction
Browse files Browse the repository at this point in the history
Also added `.leadingToTrailing` and `trailingToLeading` Cascade direction
  • Loading branch information
ManueGE committed Aug 30, 2018
1 parent faae3a1 commit ea114d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Sources/Preprocessors/CascadePreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,22 @@ public enum CascadeDirection {
self = .rightToLeft
case "topToBottom":
self = .topToBottom
case "leadingToTrailing":
self = .leadingToTrailing
case "trailingToLeading":
self = .trailingToLeading
default:
return nil
}
}

public static var leadingToTrailing: CascadeDirection {
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? .leftToRight : .rightToLeft
}

public static var trailingToLeading: CascadeDirection {
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? .rightToLeft : .leftToRight
}

private func topToBottomComperator(lhs: UIView, rhs: UIView) -> Bool {
return lhs.frame.minY < rhs.frame.minY
Expand Down
22 changes: 12 additions & 10 deletions Sources/Preprocessors/DefaultAnimationPreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ public enum HeroDefaultAnimationType {
case "right": return .right
case "up": return .up
case "down": return .down
case "leading": return .leading
case "trailing": return .trailing
default: return nil
}
}

public static var leading: Direction {
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? .left : .right
}

public static var trailing: Direction {
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? .right : .left
}
}
case auto
case push(direction: Direction)
Expand Down Expand Up @@ -249,17 +259,9 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
if animators.contains(where: { $0.canAnimate(view: toView, appearing: true) || $0.canAnimate(view: fromView, appearing: false) }) {
defaultAnimation = .none
} else if inNavigationController {
if UIApplication.shared.userInterfaceLayoutDirection == .leftToRight {
defaultAnimation = presenting ? .push(direction:.left) : .pull(direction:.right)
} else {
defaultAnimation = presenting ? .push(direction:.right) : .pull(direction:.left)
}
defaultAnimation = presenting ? .push(direction:.leading) : .pull(direction:.trailing)
} else if inTabBarController {
if UIApplication.shared.userInterfaceLayoutDirection == .leftToRight {
defaultAnimation = presenting ? .slide(direction:.left) : .slide(direction:.right)
} else {
defaultAnimation = presenting ? .slide(direction:.right) : .slide(direction:.left)
}
defaultAnimation = presenting ? .push(direction:.leading) : .pull(direction:.trailing)
} else {
defaultAnimation = .fade
}
Expand Down

0 comments on commit ea114d3

Please sign in to comment.