diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d064054..abe24162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Sources/Preprocessors/CascadePreprocessor.swift b/Sources/Preprocessors/CascadePreprocessor.swift index 689b36d6..17fefc19 100644 --- a/Sources/Preprocessors/CascadePreprocessor.swift +++ b/Sources/Preprocessors/CascadePreprocessor.swift @@ -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 diff --git a/Sources/Preprocessors/DefaultAnimationPreprocessor.swift b/Sources/Preprocessors/DefaultAnimationPreprocessor.swift index 00e754ad..622e2bac 100644 --- a/Sources/Preprocessors/DefaultAnimationPreprocessor.swift +++ b/Sources/Preprocessors/DefaultAnimationPreprocessor.swift @@ -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) @@ -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 } diff --git a/Sources/Transition/HeroTransition.swift b/Sources/Transition/HeroTransition.swift index 8fbfe413..fc5d2167 100644 --- a/Sources/Transition/HeroTransition.swift +++ b/Sources/Transition/HeroTransition.swift @@ -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 {