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

WorkflowSwiftUI Perception #276

Draft
wants to merge 20 commits into
base: tomb/swiftui-testbed-workflowswiftui
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions Development.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ Pod::Spec.new do |s|
app_spec.source_files = 'Samples/SwiftUITestbed/Sources/**/*.swift'
app_spec.dependency 'MarketWorkflowUI', '80.0.0'
app_spec.dependency 'WorkflowSwiftUIExperimental'

# app spec SPM dependencies not supported yet
# app_spec.spm_dependency(
# :url => 'https://github.com/pointfreeco/swift-composable-architecture',
# :requirement => {:kind => 'upToNextMajorVersion', :minimumVersion => '1.9.0'},
# :products => ['ComposableArchitecture']
# )

end

s.test_spec 'SwiftUITestbedTests' do |test_spec|
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source 'https://rubygems.org'

gem 'cocoapods-trunk', '>=1.6.0'
gem 'cocoapods'
gem 'cocoapods', git: 'https://github.com/watt/cocoapods', branch: 'podspec-spm'
gem 'cocoapods-core', git: 'https://github.com/watt/cocoapods-core', branch: 'podspec-spm'

gem 'cocoapods-generate'
104 changes: 64 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,41 +1,34 @@
GEM
remote: https://rubygems.org/
GIT
remote: https://github.com/watt/cocoapods
revision: d8cd134e64ea6ba275366ffd62c52a0b219cdb56
branch: podspec-spm
specs:
CFPropertyList (3.0.5)
rexml
activesupport (6.1.7.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.1.0)
cocoapods (1.11.2)
cocoapods (1.15.0)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.11.2)
cocoapods-core (= 1.15.0)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.4.0, < 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.4.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 1.0, < 3.0)
xcodeproj (>= 1.21.0, < 2.0)
cocoapods-core (1.11.2)
activesupport (>= 5.0, < 7)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)

GIT
remote: https://github.com/watt/cocoapods-core
revision: 10b4e89e768016159026182b3349af3a2936070e
branch: podspec-spm
specs:
cocoapods-core (1.15.0)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
Expand All @@ -44,10 +37,37 @@ GEM
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)

GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.7)
base64
nkf
rexml
activesupport (7.1.3.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
base64 (0.2.0)
bigdecimal (3.1.6)
claide (1.1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-disable-podfile-validations (0.2.0)
cocoapods-downloader (1.6.3)
cocoapods-generate (2.2.3)
cocoapods-downloader (2.1)
cocoapods-generate (2.2.5)
cocoapods-disable-podfile-validations (>= 0.1.1, < 0.3.0)
cocoapods-plugins (1.0.0)
nap
Expand All @@ -57,46 +77,50 @@ GEM
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.2.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
drb (2.2.1)
escape (0.0.4)
ethon (0.15.0)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.15.5)
ffi (1.16.3)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.14.1)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
json (2.6.1)
minitest (5.19.0)
json (2.7.1)
minitest (5.22.2)
molinillo (0.8.0)
mutex_m (0.2.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.6)
rexml (3.2.5)
nkf (0.2.0)
public_suffix (4.0.7)
rexml (3.2.6)
ruby-macho (2.5.1)
typhoeus (1.4.0)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.21.0)
xcodeproj (1.24.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
zeitwerk (2.6.11)

PLATFORMS
ruby

DEPENDENCIES
cocoapods
cocoapods!
cocoapods-core!
cocoapods-generate
cocoapods-trunk (>= 1.6.0)

BUNDLED WITH
2.1.4
2.5.6
71 changes: 71 additions & 0 deletions Samples/SwiftUITestbed/Sources/CounterScreen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import SwiftUI
import MarketUI
import MarketWorkflowUI
import ViewEnvironment
import WorkflowUI
import Perception

struct CounterScreen: SwiftUIScreen, Screen {
var model: Model

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

static func makeView(store: Store<Model>) -> some View {
CounterScreenView(store: store)
}
}

extension CounterScreen: MarketBackStackContentScreen {
func backStackItem(in environment: ViewEnvironment) -> MarketUI.MarketNavigationItem {
MarketNavigationItem(
title: .text(.init(regular: "Counters")),
backButton: .automatic()
)
}

var backStackIdentifier: AnyHashable? { nil }
}

struct CounterScreenView: View {
typealias Model = StoreModel<CounterWorkflow.State, CounterWorkflow.Action>

let store: Store<Model>

var body: some View {
WithPerceptionTracking {
let _ = Self._printChanges()
CounterView(store: store, index: 0)
}
}
}

struct CounterView: View {
typealias Model = StoreModel<CounterWorkflow.State, CounterWorkflow.Action>
let store: Store<Model>
let index: Int

var body: some View {
WithPerceptionTracking {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume eventually, folks won't need to do this – we'll lift it a layer up?

let _ = print("Evaluating CounterView[\(index)].body")
HStack {
Button {
store.send(.decrement)
} label: {
Image(systemName: "minus")
}

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

Button {
store.send(.increment)
} label: {
Image(systemName: "plus")
}
}
.padding()
}
}
}
57 changes: 57 additions & 0 deletions Samples/SwiftUITestbed/Sources/CounterWorkflow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Workflow
import ComposableArchitecture

struct CounterWorkflow: Workflow {

var resetToken: ResetToken

@ObservableState
struct State {
var count = 0
}

enum Action: WorkflowAction {
typealias WorkflowType = CounterWorkflow

case increment
case decrement

func apply(toState state: inout CounterWorkflow.State) -> CounterWorkflow.Output? {
switch self {
case .increment:
state.count += 1
case .decrement:
state.count -= 1
}
return nil
}
}

typealias Output = Never

func makeInitialState() -> State {
State(count: resetToken.initialValue)
}

func workflowDidChange(from previousWorkflow: CounterWorkflow, state: inout State) {
if resetToken != previousWorkflow.resetToken {
// this state reset will totally invalidate the body even if `count` doesn't change
state = State(count: resetToken.initialValue)
}
}

typealias Rendering = StoreModel<State, Action>
typealias Model = StoreModel<State, Action>

func render(state: State, context: RenderContext<CounterWorkflow>) -> StoreModel<State, Action> {
// print("CounterWorkflow.render")
return context.makeStoreModel(state: state)
}
}

extension CounterWorkflow {
struct ResetToken: Equatable {
let id = UUID()
var initialValue = 0
}
}
Loading
Loading