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

Adds support for persistWhenSkipped in SwiftUI #125

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Sources/SwiftCurrent_SwiftUI/Models/WorkflowViewModel.swift
Expand Up @@ -16,6 +16,8 @@ final class WorkflowViewModel: ObservableObject {
let onAbandonPublisher = PassthroughSubject<Void, Never>()
let onFinishPublisher = CurrentValueSubject<AnyWorkflow.PassedArgs?, Never>(nil)
let onBackUpPublisher = PassthroughSubject<AnyWorkflow.Element, Never>()
let proceedPublisher = CurrentValueSubject<AnyWorkflow.Element?, Never>(nil)
let launchPublisher = CurrentValueSubject<AnyWorkflow.Element?, Never>(nil)

@Binding var isLaunched: Bool
private let launchArgs: AnyWorkflow.PassedArgs
Expand All @@ -30,15 +32,20 @@ final class WorkflowViewModel: ObservableObject {
extension WorkflowViewModel: OrchestrationResponder {
func launch(to destination: AnyWorkflow.Element) {
body = destination
launchPublisher.send(destination)
}

func proceed(to destination: AnyWorkflow.Element, from source: AnyWorkflow.Element) {
// DispatchQueue.main.asyncAfter(deadline: .now().advanced(by: .seconds(1))) {
body = destination
// }
proceedPublisher.send(destination)
}

func backUp(from source: AnyWorkflow.Element, to destination: AnyWorkflow.Element) {
body = destination
onBackUpPublisher.send(source)
// onBackUpPublisher.send(destination)
}

func abandon(_ workflow: AnyWorkflow, onFinish: (() -> Void)?) {
Expand Down
25 changes: 24 additions & 1 deletion Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift
Expand Up @@ -63,7 +63,9 @@ public struct WorkflowItem<F: FlowRepresentable & View, Wrapped: View, Content:
}
}
.onReceive(model.$body, perform: activateIfNeeded)
.onReceive(model.$body, perform: proceedInWorkflow)
// .onReceive(model.$body, perform: proceedInWorkflow)
.onReceive(model.proceedPublisher, perform: registeredProceedInWorkflow)
.onReceive(model.launchPublisher, perform: proceedInWorkflow)
.onReceive(model.onBackUpPublisher, perform: backUpInWorkflow)
.onReceive(inspection.notice) { inspection.visit(self, $0) }
}
Expand Down Expand Up @@ -167,6 +169,12 @@ public struct WorkflowItem<F: FlowRepresentable & View, Wrapped: View, Content:
}
}

private func registeredProceedInWorkflow(element: AnyWorkflow.Element?) {
// if element?.value.metadata.persistence == .persistWhenSkipped, elementRef == nil {
proceedInWorkflow(element: element)
// }
}

private func backUpInWorkflow(element: AnyWorkflow.Element?) {
// We have found no satisfactory way to test this...we haven't even really found unsatisfactory ways to test it.
// See: https://github.com/nalexn/ViewInspector/issues/131
Expand All @@ -176,6 +184,17 @@ public struct WorkflowItem<F: FlowRepresentable & View, Wrapped: View, Content:
}

private func proceedInWorkflow(element: AnyWorkflow.Element?) {
//
// print("Element is: \(element?.value.instance?.underlyingInstance ?? "Nil")")
// print("Element.next is: \(element?.next?.value.instance?.underlyingInstance ?? "Nil")")
// print("Element.previous is: \(element?.previous?.value.instance?.underlyingInstance ?? "Nil")")
// print("Content is: \(Content.self)")
// print("elementRef is: \(_elementRef.wrappedValue?.value.instance?.underlyingInstance ?? "Nil")")
// print("elementRef.next is: \(elementRef?.next?.value.instance?.underlyingInstance ?? "Nil")")
// print("elementRef.previous is: \(elementRef?.previous?.value.instance?.underlyingInstance ?? "Nil")")
// print("Wrapped is: \(Wrapped.self)")
print("====================")

if let body = element?.extractErasedView() as? Content, elementRef === element || elementRef == nil {
elementRef = element
content = body
Expand All @@ -184,6 +203,10 @@ public struct WorkflowItem<F: FlowRepresentable & View, Wrapped: View, Content:
content = nil
elementRef = nil
}

if persistence == .persistWhenSkipped {
isActive = true
}
}
}

Expand Down
@@ -0,0 +1,224 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "D94B382E-71A6-4C83-92B8-7C2328597DE8"
type = "3"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "31C30199-AB6D-4774-887C-A7506C88F63C"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "51"
endingLineNumber = "51"
landmarkName = "body"
landmarkType = "24">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po print(&quot;body.content.navlink - For \(F.self) -- \(content) |||to||| \(type(of: nextView))&quot;)">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "155D1CBC-C307-4DAC-A50F-EF2384C61D33"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "60"
endingLineNumber = "60"
landmarkName = "body"
landmarkType = "24">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po print(&quot;body.content - For \(F.self) -- \(content)&quot;)">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "B6F1E7E7-A734-43BE-BBD4-04BD7B32B9C3"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "196"
endingLineNumber = "196"
landmarkName = "proceedInWorkflow(element:)"
landmarkType = "7">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po print(&quot;proceedInWorkflow - for \(F.self) -- elementRef is: \(_elementRef)&quot;)">
</ActionContent>
</BreakpointActionProxy>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po print(&quot;proceedInWorkflow - For \(F.self) -- content is: \(_content)&quot;)">
</ActionContent>
</BreakpointActionProxy>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po print(&quot;proceedInWorkflow - For \(F.self) -- element is \(element?.value.instance?.underlyingInstance)&quot;)">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "AF424A30-2B6E-4433-AF21-615C4DC58C92"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "199"
endingLineNumber = "199"
landmarkName = "proceedInWorkflow(element:)"
landmarkType = "7">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po print(&quot;HIT if let body&quot;)">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "723EC12B-6175-49F5-A9AA-1A2CEFFF9C31"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "203"
endingLineNumber = "203"
landmarkName = "proceedInWorkflow(element:)"
landmarkType = "7">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po print(&quot;HIT else if persistence&quot;)">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "552791D1-AEE2-4F0B-BCD6-34CD44960D94"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "Sources/SwiftCurrent_SwiftUI/Models/WorkflowViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "40"
endingLineNumber = "40"
landmarkName = "proceed(to:from:)"
landmarkType = "7">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po print(&quot;proceed.was: \(body?.value.instance?.underlyingInstance ?? &quot;Nil&quot;) || and is now: \(destination.value.instance?.underlyingInstance ?? &quot;Nil&quot;)&quot;)">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "05212694-FD13-4AD2-A1C9-DE37BE2EE35D"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "200"
endingLineNumber = "200"
landmarkName = "proceedInWorkflow(element:)"
landmarkType = "7">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "B19BC4A4-D35B-4535-A497-4FBEDFF61AE8"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "Yes"
filePath = "Sources/SwiftCurrent_SwiftUI/Views/WorkflowItem.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "174"
endingLineNumber = "174"
landmarkName = "registeredProceedInWorkflow(element:)"
landmarkType = "7">
<Actions>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po F.self">
</ActionContent>
</BreakpointActionProxy>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po element?.value.instance?.underlyingInstance">
</ActionContent>
</BreakpointActionProxy>
<BreakpointActionProxy
ActionExtensionID = "Xcode.BreakpointAction.DebuggerCommand">
<ActionContent
consoleCommand = "po &quot;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&quot;">
</ActionContent>
</BreakpointActionProxy>
</Actions>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>