Skip to content

Commit

Permalink
Observable state WorkflowSwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
watt committed Jun 19, 2024
1 parent 0222d2d commit 2d6af7e
Show file tree
Hide file tree
Showing 44 changed files with 5,190 additions and 251 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/swift.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@ jobs:
-destination "$IOS_DESTINATION" \
build test | bundle exec xcpretty
xcodegen:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

- name: Switch Xcode
run: sudo xcode-select -s /Applications/Xcode_${XCODE_VERSION}.app

- name: Install XcodeGen
run: brew install xcodegen

- name: Generate Xcode project
run: xcodegen generate

- name: ObservableScreen - iOS
run: |
xcodebuild \
-project Workflow.xcodeproj \
-scheme "ObservableScreen" \
-destination "$IOS_DESTINATION" \
-skipMacroValidation \
build
- name: ObservableScreen - macOS
run: |
xcodebuild \
-project Workflow.xcodeproj \
-scheme "ObservableScreen" \
-destination "platform=macOS" \
-skipMacroValidation \
build
spm:
runs-on: macos-latest

Expand All @@ -66,13 +99,15 @@ jobs:
xcodebuild \
-scheme "Workflow-Package" \
-destination "$IOS_DESTINATION" \
-skipMacroValidation \
test
- name: Swift Package Manager - macOS
run: |
xcodebuild \
-scheme "Workflow-Package" \
-destination "platform=macOS" \
-skipMacroValidation \
test
tutorial:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ xcuserdata/
# Sample workspace
SampleApp.xcworkspace

# XcodeGen
Workflow.xcodeproj/
/TestingSupport/AppHost/App/Info.plist

# ios-snapshot-test-case Failure Diffs
FailureDiffs/

Samples/**/*Info.plist
!Samples/Tutorial/AppHost/Configuration/Info.plist
!Samples/Tutorial/AppHost/TutorialTests/Info.plist
!Samples/AsyncWorker/AsyncWorker/Info.plist
!Samples/AsyncWorker/AsyncWorker/Info.plist
3 changes: 2 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# file config

--swiftversion 5.7
--swiftversion 5.9
--exclude Pods,Tooling,**Dummy.swift

# format config
Expand All @@ -24,6 +24,7 @@
--enable spaceInsideBraces
--enable specifiers
--enable trailingSpace # https://google.github.io/swift/#horizontal-whitespace
--enable wrapMultilineStatementBraces

--allman false
--binarygrouping none
Expand Down
9 changes: 0 additions & 9 deletions Development.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ Pod::Spec.new do |s|
test_spec.source_files = 'WorkflowTesting/Tests/**/*.swift'
end

s.app_spec 'SampleSwiftUIApp' do |app_spec|
app_spec.ios.deployment_target = WORKFLOW_IOS_DEPLOYMENT_TARGET
app_spec.dependency 'WorkflowSwiftUI'
app_spec.pod_target_xcconfig = {
'IFNFOPLIST_FILE' => '${PODS_ROOT}/../Samples/SampleSwiftUIApp/SampleSwiftUIApp/Configuration/Info.plist'
}
app_spec.source_files = 'Samples/SampleSwiftUIApp/SampleSwiftUIApp/**/*.swift'
end

s.app_spec 'SampleTicTacToe' do |app_spec|
app_spec.source_files = 'Samples/TicTacToe/Sources/**/*.swift'
app_spec.resources = 'Samples/TicTacToe/Resources/**/*'
Expand Down
9 changes: 9 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Part of the distributed code is also derived in part from
https://github.com/pointfreeco/swift-composable-architecture, licensed under MIT
(https://github.com/pointfreeco/swift-composable-architecture/blob/main/LICENSE).
Copyright (c) 2020 Point-Free, Inc.

Part of the distributed code is also derived in part from
https://github.com/apple/swift licensed under Apache
(https://github.com/apple/swift/blob/main/LICENSE.txt). Copyright 2024 Apple,
Inc.
43 changes: 40 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// swift-tools-version:5.7
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import CompilerPluginSupport
import PackageDescription

let package = Package(
Expand Down Expand Up @@ -58,7 +59,12 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/ReactiveCocoa/ReactiveSwift.git", from: "7.1.1"),
.package(url: "https://github.com/ReactiveX/RxSwift.git", from: "6.6.0"),
.package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.44.14"),
.package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.54.0"),
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.4.0"),
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.1.4"),
],
targets: [
// MARK: Workflow
Expand Down Expand Up @@ -96,11 +102,42 @@ let package = Package(
dependencies: ["WorkflowUI", "WorkflowReactiveSwift"],
path: "WorkflowUI/Tests"
),

// MARK: WorkflowSwiftUI

.target(
name: "WorkflowSwiftUI",
dependencies: ["Workflow"],
dependencies: [
"Workflow",
"WorkflowUI",
"WorkflowSwiftUIMacros",
.product(name: "CasePaths", package: "swift-case-paths"),
.product(name: "IdentifiedCollections", package: "swift-identified-collections"),
.product(name: "Perception", package: "swift-perception"),
],
path: "WorkflowSwiftUI/Sources"
),
.testTarget(
name: "WorkflowSwiftUITests",
dependencies: ["WorkflowSwiftUI"],
path: "WorkflowSwiftUI/Tests"
),
.macro(
name: "WorkflowSwiftUIMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
path: "WorkflowSwiftUIMacros/Sources"
),
.testTarget(
name: "WorkflowSwiftUIMacrosTests",
dependencies: [
"WorkflowSwiftUIMacros",
.product(name: "MacroTesting", package: "swift-macro-testing"),
],
path: "WorkflowSwiftUIMacros/Tests"
),

// MARK: WorkflowReactiveSwift

Expand Down
3 changes: 1 addition & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For Squares, membership is managed through the `Workflow Swift Owners` registry

> ⚠️ [Optional] To avoid possible headaches when publishing podspecs, validation can be performed before updating the Workflow version number(s). To do this, run the following in the root directory of this repo:
> ```bash
> bundle exec pod lib lint Workflow.podspec ViewEnvironment.podspec ViewEnvironmentUI.podspec WorkflowTesting.podspec WorkflowReactiveSwift.podspec WorkflowUI.podspec WorkflowRxSwift.podspec WorkflowReactiveSwiftTesting.podspec WorkflowRxSwiftTesting.podspec WorkflowSwiftUI.podspec WorkflowSwiftUIExperimental.podspec WorkflowCombine.podspec WorkflowCombineTesting.podspec WorkflowConcurrency.podspec WorkflowConcurrencyTesting.podspec
> bundle exec pod lib lint Workflow.podspec ViewEnvironment.podspec ViewEnvironmentUI.podspec WorkflowTesting.podspec WorkflowReactiveSwift.podspec WorkflowUI.podspec WorkflowRxSwift.podspec WorkflowReactiveSwiftTesting.podspec WorkflowRxSwiftTesting.podspec WorkflowSwiftUIExperimental.podspec WorkflowCombine.podspec WorkflowCombineTesting.podspec WorkflowConcurrency.podspec WorkflowConcurrencyTesting.podspec
> ```
> You may need to `--include-podspecs` for pods that have changed and are depended on by other of the pods.
Expand All @@ -43,7 +43,6 @@ For Squares, membership is managed through the `Workflow Swift Owners` registry
bundle exec pod trunk push WorkflowRxSwift.podspec --synchronous
bundle exec pod trunk push WorkflowReactiveSwiftTesting.podspec --synchronous
bundle exec pod trunk push WorkflowRxSwiftTesting.podspec --synchronous
bundle exec pod trunk push WorkflowSwiftUI.podspec --synchronous
bundle exec pod trunk push WorkflowSwiftUIExperimental.podspec --synchronous
bundle exec pod trunk push WorkflowCombine.podspec --synchronous
bundle exec pod trunk push WorkflowCombineTesting.podspec --synchronous
Expand Down
31 changes: 31 additions & 0 deletions Samples/ObservableScreen/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import UIKit
import Workflow
import WorkflowUI

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let root = WorkflowHostingController(
workflow: MultiCounterWorkflow().mapRendering(MultiCounterScreen.init)
)
root.view.backgroundColor = .systemBackground

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = root
window?.makeKeyAndVisible()

return true
}

func applicationWillResignActive(_ application: UIApplication) {}

func applicationDidEnterBackground(_ application: UIApplication) {}

func applicationWillEnterForeground(_ application: UIApplication) {}

func applicationDidBecomeActive(_ application: UIApplication) {}

func applicationWillTerminate(_ application: UIApplication) {}
}
16 changes: 16 additions & 0 deletions Samples/ObservableScreen/Sources/CounterScreen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import SwiftUI
import ViewEnvironment
import WorkflowSwiftUI
import WorkflowUI

struct CounterScreen: ObservableScreen, Screen {
var model: Model

typealias State = CounterWorkflow.State
typealias Action = CounterWorkflow.Action
typealias Model = ActionModel<State, Action>

static func makeView(store: Store<Model>) -> some View {
CounterView(store: store, key: "root")
}
}
58 changes: 58 additions & 0 deletions Samples/ObservableScreen/Sources/CounterView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import SwiftUI
import ViewEnvironment
import WorkflowSwiftUI

struct CounterView: View {
typealias Model = ActionModel<CounterWorkflow.State, CounterWorkflow.Action>

let store: Store<Model>
let key: String

var body: some View {
let _ = Self._printChanges()
WithPerceptionTracking {
let _ = print("Evaluated CounterView[\(key)] body")
HStack {
Text(store.info.name)

Spacer()

Button {
store.send(.decrement)
} label: {
Image(systemName: "minus")
}

Text("\(store.boundedCount)")
.monospacedDigit()

Button {
store.send(.increment)
} label: {
Image(systemName: "plus")
}

if let maxValue = store.maxValue {
Text("(max \(maxValue))")
}
}
}
}
}

#if DEBUG

#Preview {
CounterScreen.observableScreenPreview(
state: .init(
count: 0,
info: .init(
name: "Preview counter",
stepSize: 1
)
)
)
.padding()
}

#endif
Loading

0 comments on commit 2d6af7e

Please sign in to comment.