Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep using default navigation animation direction with RTL languages #520

Merged
merged 7 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The changelog for `Hero`. Also see the [releases](https://github.com/HeroTransit

### Changed

- Added support for right to left languages.
[#520](https://github.com/HeroTransitions/Hero/pull/520) by [@ManueGE](https://github.com/ManueGE)

- The hidden state of subviews are now taken into account in optimized snapshot type for `UIImageView`.
[#521](https://github.com/HeroTransitions/Hero/pull/521) by [@ManueGE](https://github.com/ManueGE)

Expand Down
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
31 changes: 29 additions & 2 deletions Sources/Preprocessors/DefaultAnimationPreprocessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,35 @@ 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
}
}

public enum Strategy {
case forceLeftToRight, forceRightToLeft, userInterface
func defaultDirection(presenting: Bool) -> Direction {
switch self {
case .forceLeftToRight:
return presenting ? .left : .right
case .forceRightToLeft:
return presenting ? .right : .left
case .userInterface:
return presenting ? .leading : .trailing
}
}
}

case auto
case push(direction: Direction)
case pull(direction: Direction)
Expand Down Expand Up @@ -249,9 +274,11 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
if animators.contains(where: { $0.canAnimate(view: toView, appearing: true) || $0.canAnimate(view: fromView, appearing: false) }) {
defaultAnimation = .none
} else if inNavigationController {
defaultAnimation = presenting ? .push(direction:.left) : .pull(direction:.right)
let direction = hero.defaultAnimationDirectionStrategy.defaultDirection(presenting: presenting)
defaultAnimation = .push(direction: direction)
} else if inTabBarController {
defaultAnimation = presenting ? .slide(direction:.left) : .slide(direction:.right)
let direction = hero.defaultAnimationDirectionStrategy.defaultDirection(presenting: presenting)
defaultAnimation = .slide(direction: direction)
} else {
defaultAnimation = .fade
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Transition/HeroTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ open class HeroTransition: NSObject {
public var containerColor: UIColor = .black
public var isUserInteractionEnabled = false
public var viewOrderingStrategy: HeroViewOrderingStrategy = .auto
public var defaultAnimationDirectionStrategy: HeroDefaultAnimationType.Strategy = .forceLeftToRight

public internal(set) var state: HeroTransitionState = .possible {
didSet {
Expand Down