Skip to content

Commit

Permalink
Rename NavigationTransition to NavigationTransitionProtocol (#142)
Browse files Browse the repository at this point in the history
Due to the recent iOS 18 update introducing a protocol named `NavigationTransition`, there was a naming conflict with our existing protocol used for smooth animation navigation in SwiftUI. To resolve this, I renamed our protocol to `NavigationTransitionProtocol` and updated all references accordingly. This change ensures compatibility with iOS 18 and avoids potential issues or confusion in the codebase. Merging this update will maintain seamless functionality across all SwiftUI navigation animations.
  • Loading branch information
Mohsenkhodadadzadeh authored Nov 1, 2024
1 parent ddc7d42 commit 76ae9c6
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Examples/Demo/Demo/Custom Transitions/Flip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ extension AnyNavigationTransition {
}
}

struct Flip: NavigationTransition {
struct Flip: NavigationTransitionProtocol {
var axis: Axis

var body: some NavigationTransition {
var body: some NavigationTransitionProtocol {
MirrorPush {
Rotate3D(.degrees(180), axis: axis == .horizontal ? (x: 1, y: 0, z: 0) : (x: 0, y: 1, z: 0))
}
Expand Down
4 changes: 2 additions & 2 deletions Examples/Demo/Demo/Custom Transitions/Swing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ extension AnyNavigationTransition {
}
}

struct Swing: NavigationTransition {
var body: some NavigationTransition {
struct Swing: NavigationTransitionProtocol {
var body: some NavigationTransitionProtocol {
Slide(axis: .horizontal)
MirrorPush {
let angle = 70.0
Expand Down
4 changes: 2 additions & 2 deletions Examples/Demo/Demo/Custom Transitions/Zoom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ extension AnyNavigationTransition {
}
}

struct Zoom: NavigationTransition {
var body: some NavigationTransition {
struct Zoom: NavigationTransitionProtocol {
var body: some NavigationTransitionProtocol {
MirrorPush {
Scale(0.5)
OnInsertion {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ The library ships with some **standard transitions** out of the box:
In addition to these, you can create fully [**custom transitions**](https://davdroman.github.io/swiftui-navigation-transitions/main/documentation/navigationtransitions/custom-transitions/) in just a few lines of SwiftUI-like code!

```swift
struct Swing: NavigationTransition {
var body: some NavigationTransition {
struct Swing: NavigationTransitionProtocol {
var body: some NavigationTransitionProtocol {
Slide(axis: .horizontal)
MirrorPush {
let angle = 70.0
Expand Down
2 changes: 1 addition & 1 deletion Sources/NavigationTransition/AnyNavigationTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct AnyNavigationTransition {
package let handler: Handler
package var animation: Animation? = .default

public init(_ transition: some NavigationTransition) {
public init(_ transition: some NavigationTransitionProtocol) {
self.isDefault = false
self.handler = .transient(transition.transition(from:to:for:in:))
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/NavigationTransition/Combined.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extension AnyNavigationTransition {
public func combined(with other: Self) -> Self {
switch (self.handler, other.handler) {
case (.transient(let lhsHandler), .transient(let rhsHandler)):
struct Erased: NavigationTransition {
struct Erased: NavigationTransitionProtocol {
let handler: AnyNavigationTransition.TransientHandler

@inlinable
Expand All @@ -30,7 +30,7 @@ extension AnyNavigationTransition {
}
}

public struct Combined<TransitionA: NavigationTransition, TransitionB: NavigationTransition>: NavigationTransition {
public struct Combined<TransitionA: NavigationTransitionProtocol, TransitionB: NavigationTransitionProtocol>: NavigationTransitionProtocol {
private let transitionA: TransitionA
private let transitionB: TransitionB

Expand Down
4 changes: 2 additions & 2 deletions Sources/NavigationTransition/Fade.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension AnyNavigationTransition {
}

/// A transition that fades the pushed view in, fades the popped view out, or cross-fades both views.
public struct Fade: NavigationTransition {
public struct Fade: NavigationTransitionProtocol {
public enum Style {
case `in`
case out
Expand All @@ -21,7 +21,7 @@ public struct Fade: NavigationTransition {
self.style = style
}

public var body: some NavigationTransition {
public var body: some NavigationTransitionProtocol {
switch style {
case .in:
MirrorPush {
Expand Down
2 changes: 1 addition & 1 deletion Sources/NavigationTransition/Identity.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// For internal use only.
struct Identity: NavigationTransition {
struct Identity: NavigationTransitionProtocol {
init() {}

func transition(
Expand Down
8 changes: 4 additions & 4 deletions Sources/NavigationTransition/Mirror.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import AtomicTransition

/// Used to define a transition that executes on push, and executes the mirrored version of said transition on pop.
public struct MirrorPush<Transition: MirrorableAtomicTransition>: NavigationTransition {
public struct MirrorPush<Transition: MirrorableAtomicTransition>: NavigationTransitionProtocol {
private let transition: Transition

public init(@AtomicTransitionBuilder transition: () -> Transition) {
self.transition = transition()
}

public var body: some NavigationTransition {
public var body: some NavigationTransitionProtocol {
OnPush {
transition
}
Expand All @@ -22,14 +22,14 @@ extension MirrorPush: Equatable where Transition: Equatable {}
extension MirrorPush: Hashable where Transition: Hashable {}

/// Used to define a transition that executes on pop, and executes the mirrored version of said transition on push.
public struct MirrorPop<Transition: MirrorableAtomicTransition>: NavigationTransition {
public struct MirrorPop<Transition: MirrorableAtomicTransition>: NavigationTransitionProtocol {
private let transition: Transition

public init(@AtomicTransitionBuilder transition: () -> Transition) {
self.transition = transition()
}

public var body: some NavigationTransition {
public var body: some NavigationTransitionProtocol {
OnPush {
transition.mirrored()
}
Expand Down
70 changes: 35 additions & 35 deletions Sources/NavigationTransition/NavigationTransitionBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
@resultBuilder
public enum NavigationTransitionBuilder {
#if compiler(>=5.7)
public static func buildPartialBlock<T1: NavigationTransition>(first: T1) -> T1 {
public static func buildPartialBlock<T1: NavigationTransitionProtocol>(first: T1) -> T1 {
first
}

public static func buildPartialBlock<T1: NavigationTransition, T2: NavigationTransition>(accumulated: T1, next: T2) -> Combined<T1, T2> {
public static func buildPartialBlock<T1: NavigationTransitionProtocol, T2: NavigationTransitionProtocol>(accumulated: T1, next: T2) -> Combined<T1, T2> {
Combined(accumulated, next)
}
#else
public static func buildBlock<
T1: NavigationTransition
T1: NavigationTransitionProtocol
>(
_ t1: T1
) -> T1 {
t1
}

public static func buildBlock<
T1: NavigationTransition,
T2: NavigationTransition
T1: NavigationTransitionProtocol,
T2: NavigationTransitionProtocol
>(
_ t1: T1,
_ t2: T2
Expand All @@ -28,9 +28,9 @@ public enum NavigationTransitionBuilder {
}

public static func buildBlock<
T1: NavigationTransition,
T2: NavigationTransition,
T3: NavigationTransition
T1: NavigationTransitionProtocol,
T2: NavigationTransitionProtocol,
T3: NavigationTransitionProtocol
>(
_ t1: T1,
_ t2: T2,
Expand All @@ -40,10 +40,10 @@ public enum NavigationTransitionBuilder {
}

public static func buildBlock<
T1: NavigationTransition,
T2: NavigationTransition,
T3: NavigationTransition,
T4: NavigationTransition
T1: NavigationTransitionProtocol,
T2: NavigationTransitionProtocol,
T3: NavigationTransitionProtocol,
T4: NavigationTransitionProtocol
>(
_ t1: T1,
_ t2: T2,
Expand All @@ -54,11 +54,11 @@ public enum NavigationTransitionBuilder {
}

public static func buildBlock<
T1: NavigationTransition,
T2: NavigationTransition,
T3: NavigationTransition,
T4: NavigationTransition,
T5: NavigationTransition
T1: NavigationTransitionProtocol,
T2: NavigationTransitionProtocol,
T3: NavigationTransitionProtocol,
T4: NavigationTransitionProtocol,
T5: NavigationTransitionProtocol
>(
_ t1: T1,
_ t2: T2,
Expand All @@ -70,12 +70,12 @@ public enum NavigationTransitionBuilder {
}

public static func buildBlock<
T1: NavigationTransition,
T2: NavigationTransition,
T3: NavigationTransition,
T4: NavigationTransition,
T5: NavigationTransition,
T6: NavigationTransition
T1: NavigationTransitionProtocol,
T2: NavigationTransitionProtocol,
T3: NavigationTransitionProtocol,
T4: NavigationTransitionProtocol,
T5: NavigationTransitionProtocol,
T6: NavigationTransitionProtocol
>(
_ t1: T1,
_ t2: T2,
Expand All @@ -88,13 +88,13 @@ public enum NavigationTransitionBuilder {
}

public static func buildBlock<
T1: NavigationTransition,
T2: NavigationTransition,
T3: NavigationTransition,
T4: NavigationTransition,
T5: NavigationTransition,
T6: NavigationTransition,
T7: NavigationTransition
T1: NavigationTransitionProtocol,
T2: NavigationTransitionProtocol,
T3: NavigationTransitionProtocol,
T4: NavigationTransitionProtocol,
T5: NavigationTransitionProtocol,
T6: NavigationTransitionProtocol,
T7: NavigationTransitionProtocol
>(
_ t1: T1,
_ t2: T2,
Expand All @@ -108,24 +108,24 @@ public enum NavigationTransitionBuilder {
}
#endif

public static func buildOptional<T: NavigationTransition>(_ component: T?) -> _OptionalTransition<T> {
public static func buildOptional<T: NavigationTransitionProtocol>(_ component: T?) -> _OptionalTransition<T> {
if let component {
return _OptionalTransition(component)
} else {
return _OptionalTransition(nil)
}
}

public static func buildEither<TrueTransition: NavigationTransition, FalseTransition: NavigationTransition>(first component: TrueTransition) -> _ConditionalTransition<TrueTransition, FalseTransition> {
public static func buildEither<TrueTransition: NavigationTransitionProtocol, FalseTransition: NavigationTransitionProtocol>(first component: TrueTransition) -> _ConditionalTransition<TrueTransition, FalseTransition> {
_ConditionalTransition(trueTransition: component)
}

public static func buildEither<TrueTransition: NavigationTransition, FalseTransition: NavigationTransition>(second component: FalseTransition) -> _ConditionalTransition<TrueTransition, FalseTransition> {
public static func buildEither<TrueTransition: NavigationTransitionProtocol, FalseTransition: NavigationTransitionProtocol>(second component: FalseTransition) -> _ConditionalTransition<TrueTransition, FalseTransition> {
_ConditionalTransition(falseTransition: component)
}
}

public struct _OptionalTransition<Transition: NavigationTransition>: NavigationTransition {
public struct _OptionalTransition<Transition: NavigationTransitionProtocol>: NavigationTransitionProtocol {
private let transition: Transition?

init(_ transition: Transition?) {
Expand All @@ -142,7 +142,7 @@ public struct _OptionalTransition<Transition: NavigationTransition>: NavigationT
}
}

public struct _ConditionalTransition<TrueTransition: NavigationTransition, FalseTransition: NavigationTransition>: NavigationTransition {
public struct _ConditionalTransition<TrueTransition: NavigationTransitionProtocol, FalseTransition: NavigationTransitionProtocol>: NavigationTransitionProtocol {
private typealias Transition = _Either<TrueTransition, FalseTransition>
private let transition: Transition

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UIKit
///
/// Although the library ships with a set of predefined transitions (e.g. ``Slide``, one can also create
/// entirely new, fully customizable transitions by conforming to this protocol.
public protocol NavigationTransition {
public protocol NavigationTransitionProtocol {
/// Typealias for `AnimatorTransientView`.
typealias TransientView = AnimatorTransientView
/// Typealias for `NavigationTransitionOperation`.
Expand Down Expand Up @@ -54,7 +54,7 @@ public protocol NavigationTransition {
var body: Body { get }
}

extension NavigationTransition where Body: NavigationTransition {
extension NavigationTransitionProtocol where Body: NavigationTransitionProtocol {
/// Invokes ``body``'s implementation of ``transition(from:to:for:in:)-211yh``.
@inlinable
public func transition(
Expand All @@ -67,7 +67,7 @@ extension NavigationTransition where Body: NavigationTransition {
}
}

extension NavigationTransition where Body == Never {
extension NavigationTransitionProtocol where Body == Never {
/// A non-existent body.
///
/// > Warning: Do not invoke this property directly. It will trigger a fatal error at runtime.
Expand Down
4 changes: 2 additions & 2 deletions Sources/NavigationTransition/On.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AtomicTransition

/// Used to define a transition that executes only on push.
public struct OnPush<Transition: AtomicTransition>: NavigationTransition {
public struct OnPush<Transition: AtomicTransition>: NavigationTransitionProtocol {
private let transition: Transition

public init(@AtomicTransitionBuilder transition: () -> Transition) {
Expand All @@ -28,7 +28,7 @@ extension OnPush: Equatable where Transition: Equatable {}
extension OnPush: Hashable where Transition: Hashable {}

/// Used to define a transition that executes only on pop.
public struct OnPop<Transition: AtomicTransition>: NavigationTransition {
public struct OnPop<Transition: AtomicTransition>: NavigationTransitionProtocol {
private let transition: Transition

public init(@AtomicTransitionBuilder transition: () -> Transition) {
Expand Down
8 changes: 4 additions & 4 deletions Sources/NavigationTransition/Pick.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Used to isolate the push portion of a full `NavigationTransition` and execute it on push, ignoring the pop portion.
public struct PickPush<Transition: NavigationTransition>: NavigationTransition {
/// Used to isolate the push portion of a full `NavigationTransitionProtocol` and execute it on push, ignoring the pop portion.
public struct PickPush<Transition: NavigationTransitionProtocol>: NavigationTransitionProtocol {
private let transition: Transition

public init(@NavigationTransitionBuilder transition: () -> Transition) {
Expand All @@ -24,8 +24,8 @@ public struct PickPush<Transition: NavigationTransition>: NavigationTransition {
extension PickPush: Equatable where Transition: Equatable {}
extension PickPush: Hashable where Transition: Hashable {}

/// Used to isolate the pop portion of a full `NavigationTransition` and execute it on pop, ignoring the push portion.
public struct PickPop<Transition: NavigationTransition>: NavigationTransition {
/// Used to isolate the pop portion of a full `NavigationTransitionProtocol` and execute it on pop, ignoring the push portion.
public struct PickPop<Transition: NavigationTransitionProtocol>: NavigationTransitionProtocol {
private let transition: Transition

public init(@NavigationTransitionBuilder transition: () -> Transition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UIKit
/// This protocol variant is used to implement transitions that need to interact with raw UIKit transitioning entities.
///
/// - Warning: Usage of this initializer is highly discouraged unless you know what you're doing.
/// Conform to ``NavigationTransition`` instead to ensure correct transition behavior.
/// Conform to ``NavigationTransitionProtocol`` instead to ensure correct transition behavior.
public protocol PrimitiveNavigationTransition {
/// Typealias for `NavigationTransitionOperation`.
typealias TransitionOperation = NavigationTransitionOperation
Expand Down
4 changes: 2 additions & 2 deletions Sources/NavigationTransition/Slide.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension AnyNavigationTransition {
/// This transition:
/// - Pushes views right-to-left and pops views left-to-right when `axis` is `horizontal`.
/// - Pushes views bottom-to-top and pops views top-to-bottom when `axis` is `vertical`.
public struct Slide: NavigationTransition {
public struct Slide: NavigationTransitionProtocol {
private let axis: Axis

public init(axis: Axis) {
Expand All @@ -38,7 +38,7 @@ public struct Slide: NavigationTransition {
self.init(axis: .horizontal)
}

public var body: some NavigationTransition {
public var body: some NavigationTransitionProtocol {
switch axis {
case .horizontal:
MirrorPush {
Expand Down
Loading

0 comments on commit 76ae9c6

Please sign in to comment.