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

NavigationLinks are now supported in SwiftUI! #116

Merged
merged 40 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2fe961b
[skip ci] navigation-links - Created a copy of consumer tests and nam…
Tyler-Keith-Thompson Aug 28, 2021
d14432e
[skip ci] navigation-links - inspection extensions now expose errors …
Tyler-Keith-Thompson Aug 28, 2021
5f1123d
[navigation-links] - Discovered an issue with our inspect methods and…
Tyler-Keith-Thompson Aug 28, 2021
62f12da
[navigation-links] - Yup, new testing exposed some important aspects …
Tyler-Keith-Thompson Aug 28, 2021
28f0497
[skip ci] navigation-links - Just fixing the tests that broke due to …
Tyler-Keith-Thompson Aug 28, 2021
8d22770
[navigation-links] - Fixed a test we missed when refactoring all the …
Tyler-Keith-Thompson Aug 28, 2021
fa84239
[navigation-links] - Commented out the bidirectional test that I have…
Tyler-Keith-Thompson Aug 28, 2021
a3d4213
[navigation-links] - Properly failing tests for nav links - TT
Tyler-Keith-Thompson Aug 28, 2021
58c49cd
[navigation-links] - Even *better* tests that can stand up to the rob…
Tyler-Keith-Thompson Aug 29, 2021
74bdd56
[navigation-links] - Added the first of many tests for skipping an it…
Tyler-Keith-Thompson Aug 29, 2021
23e74c5
[skip ci] navigation-links - Added test for skipping the first item i…
Tyler-Keith-Thompson Aug 29, 2021
d33f56b
[skip ci] navigation-links - Tested skipping 2 middle items - TT
Tyler-Keith-Thompson Aug 29, 2021
14f0199
[skip ci] navigation-links - Added test for skipping last item - TT
Tyler-Keith-Thompson Aug 29, 2021
e0d9012
[skip ci] navigation-links - Got a test that moves in both directions…
Tyler-Keith-Thompson Aug 29, 2021
bd14b3c
[skip ci] navigation-links - Wrote a test for persistWhenSkipped, but…
Tyler-Keith-Thompson Aug 30, 2021
4125768
[navigation-links] - Checks that the view to swap is unique - mz tt
morganzellers Aug 30, 2021
b736be4
[navigation-links] - Handling skipping views - mz tt
morganzellers Aug 30, 2021
c142f10
[navigation-links] - Adds backup publisher and handles backups - tt mz
morganzellers Aug 30, 2021
94ca418
[navigation-links] - Extract logic for activating view on backup to f…
morganzellers Aug 30, 2021
3a60bf2
[navigation-links] - Refactoring out ViewBuilder and environment obje…
morganzellers Aug 30, 2021
0291a33
[navigation-links] - Re-enable skipped test that passes - TT
Tyler-Keith-Thompson Aug 30, 2021
ef7cd5b
[navigation-links] - We made backUp work for nav stacks in all versio…
Tyler-Keith-Thompson Aug 30, 2021
21ce3c5
[navigation-links] - Extracting proceed in workflow function - mz tt rag
morganzellers Aug 30, 2021
b6ba808
[navigation-links] - removed persistence tests, we are deferring work…
Tyler-Keith-Thompson Aug 30, 2021
75cb170
[navigation-links] - Extracting function to clear queued expectations…
morganzellers Aug 30, 2021
0a904d0
[navigation-links] - Moving extracted function to XCTestCaseExtension…
morganzellers Aug 30, 2021
f20fc74
[navigation-links] - Added check for following WorkflowItems of all t…
morganzellers Aug 30, 2021
86b0880
[navigation-links] - Removing check for is Content when already check…
Richard-Gist Aug 30, 2021
d4310fb
[navigation-links] - Added a convenience method for embedding into a …
Tyler-Keith-Thompson Aug 30, 2021
61aaf68
Merge branch 'navigation-links' of github.com:wwt/SwiftCurrent into n…
Tyler-Keith-Thompson Aug 30, 2021
eab839b
[navigation-links] - Deleted entitlements, they are not needed - TT
Tyler-Keith-Thompson Aug 30, 2021
3adc0d9
[navigation-links] - Could not figure out how to test the thing Richa…
Tyler-Keith-Thompson Aug 30, 2021
6a7f764
[navigation-links] - sadly, we determined these to be untestable earl…
Tyler-Keith-Thompson Aug 30, 2021
e743dea
[navigation-links] - Added categories and guides to our Jazzy Docs - …
Tyler-Keith-Thompson Aug 31, 2021
76ae76d
[navigation-links] - Updated the guide in SwiftUI on working with Nav…
Tyler-Keith-Thompson Aug 31, 2021
8ac0473
[navigation-links] - Updated the tutorials and docs to point to the c…
Tyler-Keith-Thompson Aug 31, 2021
b0c734c
[navigation-links] - Added an abstract for SwiftUI to jazzy docs - TT
Tyler-Keith-Thompson Aug 31, 2021
75524ab
[navigation-links] - Added an abstract for creating workflows in Swif…
Tyler-Keith-Thompson Aug 31, 2021
04bfc45
Apply suggestions from code review
Tyler-Keith-Thompson Aug 31, 2021
f209260
[navigation-links] - Minor wording tweaks to our abstract on how to u…
Tyler-Keith-Thompson Aug 31, 2021
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
21 changes: 21 additions & 0 deletions Sources/SwiftCurrent_SwiftUI/Views/NavigationWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swiftlint:disable:this file_name
// NavigationWrapper.swift
// SwiftCurrent_SwiftUI
//
// Created by Tyler Thompson on 8/27/21.
// Copyright © 2021 WWT and Tyler Thompson. All rights reserved.
//

import SwiftUI

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
extension View {
func navLink<D: View>(to destination: D, isActive: Binding<Bool>) -> some View {
Tyler-Keith-Thompson marked this conversation as resolved.
Show resolved Hide resolved
background(
List {
NavigationLink(destination: destination,
isActive: isActive) { EmptyView() }
}.opacity(0.01)
)
}
}
4 changes: 0 additions & 4 deletions Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Tyler Thompson on 7/20/21.
// Copyright © 2021 WWT and Tyler Thompson. All rights reserved.
//

import SwiftUI
import SwiftCurrent

Expand All @@ -15,10 +14,8 @@ import UIKit

/**
A concrete type used to modify a `FlowRepresentable` in a workflow.

### Discussion
`WorkflowItem` gives you the ability to specify changes you'd like to apply to a specific `FlowRepresentable` when it is time to present it in a `Workflow`. You should create `WorkflowItem`s inside a `thenProceed(with:)` call on `WorkflowLauncher`.

#### Example
```swift
thenProceed(FirstView.self)
Expand Down Expand Up @@ -132,7 +129,6 @@ public struct WorkflowItem<F: FlowRepresentable & View, Wrapped: View, Content:

/**
Provides a way to apply modifiers to your `FlowRepresentable` view.

### Important: The most recently defined (or last) use of this, is the only one that applies modifiers, unlike onAbandon or onFinish.
*/
public func applyModifiers<V: View>(@ViewBuilder _ closure: @escaping (F) -> V) -> WorkflowItem<F, Wrapped, V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,65 @@
BlueprintName = "SwiftCurrent-SwiftUITests"
ReferencedContainer = "container:">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "GenericConstraintTests/testProceedingWhenInputIsAnyWorkflowPassedArgsWithClosureFlowPersistence_WorkflowCanProceedToNeverItem()">
Richard-Gist marked this conversation as resolved.
Show resolved Hide resolved
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testMovingBiDirectionallyInAWorkflow()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCanConvertAnyArgsToCorrectTypeForFirstItem()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCanFinishMultipleTimes()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCanHaveADelayedLaunch()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCanHaveAPassthroughRepresentable()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCanHaveAPassthroughRepresentableInTheMiddle()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCanHaveModifiers()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCanHaveMultipleOnAbandonCallbacks()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCanHaveMultipleOnFinishClosures()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowCorrectlyHandlesState()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowOnlyShowsOneViewAtATime()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowPassesArgumentsToAllItems()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowPassesArgumentsToTheFirstItem()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowPassesArgumentsToTheFirstItem_WhenThatFirstItemTakesInAnyWorkflowPassedArgs()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowPassesArgumentsToTheFirstItem_WhenThatFirstItemTakesInAnyWorkflowPassedArgs_AndTheLaunchArgsAreAnyWorkflowPassedArgs()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowRelaunchesWhenAbandoned_WithAConstantOfTrue()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowRelaunchesWhenSubsequentlyLaunched()">
</Test>
<Test
Identifier = "SwiftCurrent_NavigationLinkTests/testWorkflowSetsBindingBooleanToFalseWhenAbandoned()">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
</TestAction>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import SwiftCurrent

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class AnyFlowRepresentableViewTests: XCTestCase, View {
override func tearDownWithError() throws {
Richard-Gist marked this conversation as resolved.
Show resolved Hide resolved
while let e = Self.queuedExpectations.first {
wait(for: [e], timeout: TestConstant.timeout)
Self.queuedExpectations.removeFirst()
}
}

func testAnyFlowRepresentableViewDoesNotCreate_StrongRetainCycle() {
var afrv: AnyFlowRepresentableView?
weak var ref: AnyFlowRepresentableView?
Expand Down
7 changes: 7 additions & 0 deletions Tests/SwiftCurrent_SwiftUITests/AnyWorkflowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import SwiftCurrent_SwiftUI

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class AnyWorkflowTests: XCTestCase, View {
override func tearDownWithError() throws {
while let e = Self.queuedExpectations.first {
wait(for: [e], timeout: TestConstant.timeout)
Self.queuedExpectations.removeFirst()
}
}

func testAbandonDoesNotBLOWUP() {
let wf = Workflow(FR.self)
AnyWorkflow(wf).abandon()
Expand Down
13 changes: 11 additions & 2 deletions Tests/SwiftCurrent_SwiftUITests/GenericConstraintTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ extension FlowRepresentable {

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class GenericConstraintTests: XCTestCase, View {
override func tearDownWithError() throws {
while let e = Self.queuedExpectations.first {
wait(for: [e], timeout: TestConstant.timeout)
Self.queuedExpectations.removeFirst()
}
}

// MARK: Generic Initializer Tests

// MARK: Input Type == Never
Expand Down Expand Up @@ -1580,9 +1587,11 @@ final class GenericConstraintTests: XCTestCase, View {
XCTAssertNoThrow(try view.find(FR0.self).actualView().proceedInWorkflow())
try view.actualView().inspectWrapped { view in
XCTAssertEqual(try view.find(FR1.self).actualView().persistence, .persistWhenSkipped)
try view.actualView().inspectWrapped { view in
try view.actualView().inspect { view in
XCTAssertNoThrow(try view.find(FR1.self).actualView().proceedInWorkflow())
XCTAssertNoThrow(try view.find(FR2.self))
try view.actualView().inspectWrapped { view in
XCTAssertNoThrow(try view.find(FR2.self))
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions Tests/SwiftCurrent_SwiftUITests/PersistenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import SwiftCurrent

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class PersistenceTests: XCTestCase, View {
override func tearDownWithError() throws {
while let e = Self.queuedExpectations.first {
wait(for: [e], timeout: TestConstant.timeout)
Self.queuedExpectations.removeFirst()
}
}

// MARK: RemovedAfterProceedingTests
func testRemovedAfterProceeding_OnFirstItemInAWorkflow() throws {
struct FR1: View, FlowRepresentable, Inspectable {
Expand Down
15 changes: 9 additions & 6 deletions Tests/SwiftCurrent_SwiftUITests/SkipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import SwiftCurrent

@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *)
final class SkipTests: XCTestCase, View {
override func tearDownWithError() throws {
while let e = Self.queuedExpectations.first {
wait(for: [e], timeout: TestConstant.timeout)
Self.queuedExpectations.removeFirst()
}
}

func testSkippingFirstItemInAWorkflow() throws {
// NOTE: Workflows in the past had issues with 4+ items, so this is to cover our bases. SwiftUI also has a nasty habit of behaving a little differently as number of views increase.
struct FR1: View, FlowRepresentable, Inspectable {
Expand Down Expand Up @@ -140,12 +147,8 @@ final class SkipTests: XCTestCase, View {
XCTAssertNoThrow(try fr2.find(FR2.self).actualView().proceedInWorkflow())
try fr2.actualView().inspectWrapped { fr3 in
XCTAssertNoThrow(try fr3.find(FR3.self).actualView().proceedInWorkflow())
try fr3.actualView().inspectWrapped { fr4 in
XCTAssertThrowsError(try fr4.find(FR4.self))
try fr3.actualView().inspect { fr3 in
XCTAssertNoThrow(try fr3.find(FR3.self))
}
}
XCTAssertThrowsError(try fr3.find(FR4.self))
XCTAssertNoThrow(try fr3.find(FR3.self))
}
}
}
Expand Down
Loading