Skip to content

Commit

Permalink
225
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Mar 7, 2023
1 parent d1dfc6e commit efb98ec
Show file tree
Hide file tree
Showing 21 changed files with 1,931 additions and 0 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2A3BE9F22994469500351060"
BuildableName = "Inventory.app"
BlueprintName = "Inventory"
ReferencedContainer = "container:Inventory.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2A3BEA022994469600351060"
BuildableName = "InventoryTests.xctest"
BlueprintName = "InventoryTests"
ReferencedContainer = "container:Inventory.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2A3BE9F22994469500351060"
BuildableName = "Inventory.app"
BlueprintName = "Inventory"
ReferencedContainer = "container:Inventory.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2A3BE9F22994469500351060"
BuildableName = "Inventory.app"
BlueprintName = "Inventory"
ReferencedContainer = "container:Inventory.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
101 changes: 101 additions & 0 deletions 0225-composable-navigation-pt4/Inventory/Inventory/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import ComposableArchitecture
import SwiftUI

struct AppFeature: Reducer {
struct State: Equatable {
var firstTab = FirstTabFeature.State()
var inventory = InventoryFeature.State()
var selectedTab: Tab = .one
var thirdTab = ThirdTabFeature.State()
}
enum Action: Equatable {
case firstTab(FirstTabFeature.Action)
case inventory(InventoryFeature.Action)
case selectedTabChanged(Tab)
case thirdTab(ThirdTabFeature.Action)
}
var body: some ReducerOf<Self> {
Reduce<State, Action> { state, action in
switch action {
case let .firstTab(.delegate(action)):
switch action {
case .switchToInventoryTab:
state.selectedTab = .inventory
return .none
}

case let .selectedTabChanged(tab):
state.selectedTab = tab
return .none

case .firstTab, .inventory, .thirdTab:
return .none
}
}
Scope(state: \.firstTab, action: /Action.firstTab) {
FirstTabFeature()
}
Scope(state: \.inventory, action: /Action.inventory) {
InventoryFeature()
}
Scope(state: \.thirdTab, action: /Action.thirdTab) {
ThirdTabFeature()
}
}
}

enum Tab {
case one, inventory, three
}

struct ContentView: View {
//@State var selectedTab: Tab = .one
let store: StoreOf<AppFeature>
// Store<AppFeature.State, AppFeature.Action>

var body: some View {
WithViewStore(self.store, observe: \.selectedTab) { viewStore in
TabView(selection: viewStore.binding(send: AppFeature.Action.selectedTabChanged)) {
FirstTabView(
store: self.store.scope(
state: \.firstTab,
action: AppFeature.Action.firstTab
)
)
.tabItem { Text("One") }
.tag(Tab.one)

NavigationStack {
InventoryView(
store: self.store.scope(
state: \.inventory,
action: AppFeature.Action.inventory
)
)
}
.tabItem { Text("Inventory") }
.tag(Tab.inventory)

ThirdTabView(
store: self.store.scope(
state: \.thirdTab,
action: AppFeature.Action.thirdTab
)
)
.tabItem { Text("Three") }
.tag(Tab.three)
}
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(
store: Store(
initialState: AppFeature.State(),
reducer: AppFeature()
)
)
}
}
38 changes: 38 additions & 0 deletions 0225-composable-navigation-pt4/Inventory/Inventory/FirstTab.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import ComposableArchitecture
import SwiftUI

struct FirstTabFeature: Reducer {
struct State: Equatable {}
enum Action: Equatable {
case goToInventoryButtonTapped
case delegate(Delegate)

enum Delegate: Equatable {
case switchToInventoryTab
}
}

func reduce(into state: inout State, action: Action) -> Effect<Action> {
switch action {
case .delegate:
return .none

case .goToInventoryButtonTapped:
return .send(.delegate(.switchToInventoryTab))
}
}
}

struct FirstTabView: View {
let store: StoreOf<FirstTabFeature>

var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
Button {
viewStore.send(.goToInventoryButtonTapped)
} label: {
Text("Go to inventory")
}
}
}
}
Loading

0 comments on commit efb98ec

Please sign in to comment.