-
Notifications
You must be signed in to change notification settings - Fork 19
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 #72 from wwt/swiftui
BETA RELEASE - SwiftUI support
- Loading branch information
Showing
31 changed files
with
2,251 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
SDK_PATH=`xcrun --sdk iphonesimulator --show-sdk-path` | ||
sourcekitten doc --spm --module-name SwiftCurrent -- -Xswiftc "-sdk" -Xswiftc "$SDK_PATH" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator" > swiftcurrent-docs.json | ||
sourcekitten doc --module-name SwiftCurrent_UIKit -- -workspace ./SwiftCurrent.xcworkspace -scheme SwiftCurrent_UIKit -destination "platform=iOS Simulator,name=iPhone 12" > swiftcurrentuikit-docs.json | ||
jazzy --config .github/.jazzy.yaml --podspec SwiftCurrent.podspec --sourcekitten-sourcefile swiftcurrent-docs.json,swiftcurrentuikit-docs.json | ||
sourcekitten doc --spm --module-name SwiftCurrent_SwiftUI -- -Xswiftc "-sdk" -Xswiftc "$SDK_PATH" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios14.0-simulator" > swiftcurrent-swiftui-docs.json | ||
jazzy --config .github/.jazzy.yaml --podspec SwiftCurrent.podspec --sourcekitten-sourcefile swiftcurrent-docs.json,swiftcurrentuikit-docs.json,swiftcurrent-swiftui-docs.json | ||
rm swiftcurrent-docs.json | ||
rm swiftcurrentuikit-docs.json | ||
rm swiftcurrent-swiftui-docs.json | ||
open docs/index.html |
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
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
16 changes: 16 additions & 0 deletions
16
Sources/SwiftCurrent_SwiftUI/Extensions/AnyWorkflowExtensions.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,16 @@ | ||
// swiftlint:disable:this file_name | ||
// AnyWorkflowExtensions.swift | ||
// SwiftCurrent | ||
// | ||
// Created by Tyler Thompson on 7/12/21. | ||
// Copyright © 2021 WWT and Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import SwiftCurrent | ||
|
||
extension AnyWorkflow { | ||
/// Called when the workflow should be terminated, and the app should return to the point before the workflow was launched. | ||
public func abandon() { | ||
orchestrationResponder?.abandon(self, onFinish: nil) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Sources/SwiftCurrent_SwiftUI/Extensions/WorkflowExtensions.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,18 @@ | ||
// swiftlint:disable:this file_name | ||
// WorkflowExtensions.swift | ||
// SwiftCurrent | ||
// | ||
// Created by Tyler Thompson on 7/13/21. | ||
// Copyright © 2021 WWT and Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import SwiftCurrent | ||
import SwiftUI | ||
|
||
@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *) | ||
extension Workflow where F: FlowRepresentable & View { | ||
/// Called when the workflow should be terminated, and the app should return to the point before the workflow was launched. | ||
public func abandon() { | ||
AnyWorkflow(self).abandon() | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
Sources/SwiftCurrent_SwiftUI/Models/WorkflowViewModel.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,67 @@ | ||
// | ||
// WorkflowViewModel.swift | ||
// SwiftCurrent_SwiftUI | ||
// | ||
// Created by Megan Wiemer on 7/13/21. | ||
// Copyright © 2021 WWT and Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import SwiftCurrent | ||
import SwiftUI | ||
|
||
@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *) | ||
final class WorkflowViewModel: ObservableObject { | ||
@Published var body = AnyView(EmptyView()) | ||
var isLaunched: Binding<Bool>? | ||
var onAbandon = [() -> Void]() | ||
} | ||
|
||
@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *) | ||
extension WorkflowViewModel: OrchestrationResponder { | ||
func launch(to destination: AnyWorkflow.Element) { | ||
extractView(from: destination).model = self | ||
} | ||
|
||
func proceed(to destination: AnyWorkflow.Element, from source: AnyWorkflow.Element) { | ||
extractView(from: destination).model = self | ||
} | ||
|
||
func backUp(from source: AnyWorkflow.Element, to destination: AnyWorkflow.Element) { | ||
extractView(from: destination).model = self | ||
} | ||
|
||
func abandon(_ workflow: AnyWorkflow, onFinish: (() -> Void)?) { | ||
isLaunched?.wrappedValue = false | ||
onAbandon.forEach { $0() } | ||
} | ||
|
||
func complete(_ workflow: AnyWorkflow, passedArgs: AnyWorkflow.PassedArgs, onFinish: ((AnyWorkflow.PassedArgs) -> Void)?) { | ||
if workflow.lastLoadedItem?.value.metadata.persistence == .removedAfterProceeding { | ||
if let lastPresentableItem = workflow.lastPresentableItem { | ||
extractView(from: lastPresentableItem).model = self | ||
} else { | ||
isLaunched?.wrappedValue = false | ||
} | ||
} | ||
onFinish?(passedArgs) | ||
} | ||
|
||
private func extractView(from element: AnyWorkflow.Element) -> AnyFlowRepresentableView { | ||
guard let instance = element.value.instance as? AnyFlowRepresentableView else { | ||
fatalError("Could not cast \(String(describing: element.value.instance)) to expected type: AnyFlowRepresentableView") | ||
} | ||
return instance | ||
} | ||
} | ||
|
||
extension AnyWorkflow { | ||
fileprivate var lastLoadedItem: AnyWorkflow.Element? { | ||
last { $0.value.instance != nil } | ||
} | ||
|
||
fileprivate var lastPresentableItem: AnyWorkflow.Element? { | ||
last { | ||
$0.value.instance != nil && $0.value.metadata.persistence != .removedAfterProceeding | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Sources/SwiftCurrent_SwiftUI/TypeErased/AnyFlowRepresentableView.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,36 @@ | ||
// | ||
// AnyFlowRepresentableView.swift | ||
// SwiftCurrent_SwiftUI | ||
// | ||
// Created by Megan Wiemer on 7/13/21. | ||
// Copyright © 2021 WWT and Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import SwiftCurrent | ||
import SwiftUI | ||
|
||
@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *) | ||
final class AnyFlowRepresentableView: AnyFlowRepresentable { | ||
var model: WorkflowViewModel? { | ||
didSet { | ||
setViewOnModel() | ||
} | ||
} | ||
private var setViewOnModel = { } | ||
|
||
init<FR: FlowRepresentable & View>(type: FR.Type, args: AnyWorkflow.PassedArgs) { | ||
super.init(type, args: args) | ||
guard let instance = underlyingInstance as? FR else { | ||
fatalError("Could not cast \(String(describing: underlyingInstance)) to expected type: \(FR.self)") | ||
} | ||
setViewOnModel = { [weak self] in | ||
self?.model?.body = AnyView(instance) | ||
} | ||
} | ||
|
||
func changeUnderlyingView<V: View>(to view: V) { | ||
setViewOnModel = { [weak self] in | ||
self?.model?.body = AnyView(view) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Sources/SwiftCurrent_SwiftUI/ViewInspector/Inspection.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,22 @@ | ||
// | ||
// Inspection.swift | ||
// SwiftCurrent | ||
// | ||
// Created by Tyler Thompson on 7/12/21. | ||
// Copyright © 2021 WWT and Tyler Thompson. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import Combine | ||
|
||
// Necessary for ViewInspector tests | ||
@available(iOS 14.0, macOS 11, tvOS 14.0, watchOS 7.0, *) | ||
final class Inspection<V> where V: View { | ||
let notice = PassthroughSubject<UInt, Never>() | ||
var callbacks = [UInt: (V) -> Void]() | ||
func visit(_ view: V, _ line: UInt) { | ||
if let callback = callbacks.removeValue(forKey: line) { | ||
callback(view) | ||
} | ||
} | ||
} |
Oops, something went wrong.