Skip to content

Commit a5b96e3

Browse files
authored
Add traitCollection.push(state:) (pointfreeco#3603)
* Add `traitCollection.push(state:)` * wip * Fix
1 parent db3ed65 commit a5b96e3

File tree

6 files changed

+57
-27
lines changed

6 files changed

+57
-27
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let package = Package(
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
29-
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.2.2"),
29+
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.3.0"),
3030
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
3131
.package(url: "https://github.com/pointfreeco/swift-sharing", "0.1.2"..<"3.0.0"),
3232
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let package = Package(
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
29-
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.2.2"),
29+
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.3.0"),
3030
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
3131
.package(url: "https://github.com/pointfreeco/swift-sharing", "0.1.2"..<"3.0.0"),
3232
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),

Sources/ComposableArchitecture/Documentation.docc/Extensions/UIKit.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ integrate into application code written in UIKit.
1616

1717
### Presenting alerts and action sheets
1818

19-
- ``UIKit/UIAlertController/init(store:)``
19+
- ``UIKit/UIAlertController``
20+
21+
### Stack-based navigation
22+
23+
- ``UIKitNavigation/NavigationStackController``
24+
- ``UIKitNavigation/UIPushAction``
2025

2126
### Combine integration
2227

Sources/ComposableArchitecture/TestStore.swift

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -729,30 +729,24 @@ public final class TestStore<State: Equatable, Action> {
729729
line: UInt,
730730
column: UInt
731731
) {
732-
// NB: This existential opening can go away if we can constrain 'State: Equatable' at the
733-
// 'TestStore' level, but for some reason this breaks DocC.
734-
if self.sharedChangeTracker.hasChanges, let stateType = State.self as? any Equatable.Type {
735-
func open<EquatableState: Equatable>(_: EquatableState.Type) {
736-
let store = self as! TestStore<EquatableState, Action>
737-
try? store.expectedStateShouldMatch(
738-
preamble: "Test store finished before asserting against changes to shared state",
739-
postamble: """
732+
if sharedChangeTracker.hasChanges {
733+
try? expectedStateShouldMatch(
734+
preamble: "Test store finished before asserting against changes to shared state",
735+
postamble: """
740736
Invoke "TestStore.assert" at the end of this test to assert against changes to shared \
741737
state.
742738
""",
743-
expected: store.state,
744-
actual: store.state,
745-
updateStateToExpectedResult: nil,
746-
skipUnnecessaryModifyFailure: true,
747-
fileID: fileID,
748-
filePath: filePath,
749-
line: line,
750-
column: column
751-
)
752-
}
753-
open(stateType)
754-
self.sharedChangeTracker.reset()
739+
expected: state,
740+
actual: state,
741+
updateStateToExpectedResult: nil,
742+
skipUnnecessaryModifyFailure: true,
743+
fileID: fileID,
744+
filePath: filePath,
745+
line: line,
746+
column: column
747+
)
755748
}
749+
sharedChangeTracker.reset()
756750
}
757751

758752
/// Overrides the store's dependencies for a given operation.

Sources/ComposableArchitecture/UIKit/NavigationStackControllerUIKit.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import UIKit
33

44
extension NavigationStackController {
5-
65
/// Drives a navigation stack controller with a store.
76
///
87
/// See the dedicated article on <doc:Navigation> for more information on the library's
@@ -69,4 +68,36 @@
6968
}
7069
}
7170
}
71+
72+
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
73+
@MainActor
74+
extension UIPushAction {
75+
/// Pushes an element of ``StackState`` onto the current navigation stack.
76+
///
77+
/// This is the UIKit equivalent of
78+
/// ``SwiftUI/NavigationLink/init(state:label:fileID:filePath:line:column:)``.
79+
///
80+
/// - Parameters:
81+
/// - state: An element of stack state.
82+
/// - fileID: The source `#fileID` associated with the push.
83+
/// - filePath: The source `#filePath` associated with the push.
84+
/// - line: The source `#line` associated with the push.
85+
/// - column: The source `#column` associated with the push.
86+
public func callAsFunction<Element: Hashable>(
87+
state: Element,
88+
fileID: StaticString = #fileID,
89+
filePath: StaticString = #filePath,
90+
line: UInt = #line,
91+
column: UInt = #column
92+
) {
93+
@Dependency(\.stackElementID) var stackElementID
94+
self(
95+
value: StackState.Component(id: stackElementID(), element: state),
96+
fileID: fileID,
97+
filePath: filePath,
98+
line: line,
99+
column: column
100+
)
101+
}
102+
}
72103
#endif

0 commit comments

Comments
 (0)