-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from erikdrobne/feature/transition-provider
Feature/transition provider
- Loading branch information
Showing
14 changed files
with
98 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Sources/SwiftUICoordinator/Transition/TransitionProvidable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// TransitionProvidable.swift | ||
// | ||
// | ||
// Created by Erik Drobne on 12. 10. 23. | ||
// | ||
|
||
import Foundation | ||
|
||
@MainActor | ||
public protocol TransitionProvidable { | ||
/// An array of transitions wrapped in weak references. | ||
var transitions: [WeakTransition] { get } | ||
} |
20 changes: 20 additions & 0 deletions
20
Sources/SwiftUICoordinator/Transition/TransitionProvider.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// TransitionProvider.swift | ||
// | ||
// | ||
// Created by Erik Drobne on 12. 10. 23. | ||
// | ||
|
||
import Foundation | ||
|
||
@MainActor | ||
public struct TransitionProvider: TransitionProvidable { | ||
public private(set) var transitions: [WeakTransition] | ||
/// A private array of transitions ensuring to retain them in memory as long as needed. | ||
private var _transitions: [Transitionable] | ||
|
||
public init(transitions: [Transitionable]) { | ||
self._transitions = transitions | ||
self.transitions = transitions.map { WeakTransition($0) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Tests/SwiftUICoordinatorTests/TransitionProviderTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// TransitionProviderTests.swift | ||
// | ||
// | ||
// Created by Erik Drobne on 23. 10. 23. | ||
// | ||
|
||
import XCTest | ||
@testable import SwiftUICoordinator | ||
|
||
@MainActor | ||
class TransitionProviderTests: XCTestCase { | ||
|
||
func test_transitionProviderInitialization() { | ||
let transitions = [MockTransition(), MockTransition()] | ||
let sut = TransitionProvider(transitions: transitions) | ||
|
||
XCTAssertEqual(sut.transitions.count, transitions.count) | ||
XCTAssertNotNil(sut.transitions.first?.transition) | ||
} | ||
|
||
func test_weakTransitionDoesNotRetain() { | ||
var transition: Transitionable? = MockTransition() | ||
let weakTransition: WeakTransition? = WeakTransition(transition!) | ||
|
||
XCTAssertNotNil(weakTransition?.transition) | ||
transition = nil | ||
XCTAssertNil(weakTransition?.transition) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters