-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* viewstore and withviewstore implementation * update environment examples * remove deprecated api * [ci enable] [run test] [upload] remove print
- Loading branch information
1 parent
2dc7bb1
commit 57a73bd
Showing
14 changed files
with
3,186 additions
and
17 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
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,62 @@ | ||
// | ||
// BasicUsageView.swift | ||
// Examples | ||
// | ||
// Created by daniel.istyana on 25/07/23. | ||
// | ||
|
||
import SwiftUI | ||
import RxComposableArchitecture | ||
|
||
struct BasicUsageView: View { | ||
let store: StoreOf<Basic> | ||
|
||
var body: some View { | ||
WithViewStore(self.store) { viewStore in | ||
VStack { | ||
Text("This is a demo for Basic usage State, Action, Reducer, and how to bind it to the UI using SwiftUI") | ||
.padding() | ||
Spacer() | ||
HStack(spacing: 48) { | ||
Button { | ||
viewStore.send(.didTapPlus) | ||
} label: { | ||
Label { | ||
Text("+") | ||
.font(.title3) | ||
} icon: { | ||
Image(systemName: "plus") | ||
} | ||
.labelStyle(.titleOnly) | ||
|
||
} | ||
|
||
Text("\(viewStore.number)") | ||
.font(.largeTitle) | ||
|
||
|
||
Button { | ||
viewStore.send(.didTapMinus) | ||
} label: { | ||
Label { | ||
Text("-") | ||
.font(.title3) | ||
} icon: { | ||
Image(systemName: "plus") | ||
} | ||
.labelStyle(.titleOnly) | ||
|
||
} | ||
} | ||
Spacer() | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
struct BasicUsageView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
BasicUsageView(store: Store(initialState: Basic.State(number: 0), reducer: Basic())) | ||
} | ||
} |
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
154 changes: 154 additions & 0 deletions
154
Examples/Examples/2-Environment/EnvironmentRouteView.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,154 @@ | ||
// | ||
// EnvironmentRouteView.swift | ||
// Examples | ||
// | ||
// Created by daniel.istyana on 26/07/23. | ||
// | ||
|
||
import RxComposableArchitecture | ||
import SwiftUI | ||
|
||
struct EnvironmentRouteView: View { | ||
var body: some View { | ||
List(EnvironmentRouteVC.Route.allCases, id: \.self) { route in | ||
NavigationLink(route.rawValue) { | ||
switch route { | ||
case .live: | ||
EnvironmentDemoView( | ||
store: Store( | ||
initialState: Environment.State(), | ||
reducer: Environment() | ||
.dependency(\.envVCEnvironment, .live) | ||
) | ||
) | ||
case .mockSuccess: | ||
EnvironmentDemoView( | ||
store: Store( | ||
initialState: Environment.State(), | ||
reducer: Environment() | ||
.dependency(\.envVCEnvironment, .mockSuccess) | ||
) | ||
) | ||
case .mockFailed: | ||
EnvironmentDemoView( | ||
store: Store( | ||
initialState: Environment.State(), | ||
reducer: Environment() | ||
.dependency(\.envVCEnvironment, .mockFailed) | ||
) | ||
) | ||
case .mockRandom: | ||
EnvironmentDemoView( | ||
store: Store( | ||
initialState: Environment.State(), | ||
reducer: Environment() | ||
.dependency(\.envVCEnvironment, .mockRandom) | ||
) | ||
) | ||
} | ||
} | ||
} | ||
.navigationTitle("Environment") | ||
} | ||
} | ||
|
||
struct EnvironmentDemoView: View { | ||
let store: StoreOf<Environment> | ||
var body: some View { | ||
WithViewStore(self.store) { viewStore in | ||
VStack { | ||
Text("In this example, you will learn how to use Environment. You'll also learn how to use side effect (such as networking and analytics) Because we can initialize the environment in init, you can easily swap the environment from the EnvironmentRoute.swift. You can try to change from .live to .mock") | ||
|
||
HStack { | ||
Text(viewStore.text) | ||
.font(.title3) | ||
|
||
if viewStore.isLoading { | ||
Spacer() | ||
ProgressView() | ||
} else { | ||
Spacer() | ||
} | ||
} | ||
.padding(.top) | ||
|
||
Button { | ||
viewStore.send(.refresh) | ||
} label: { | ||
Text("Reload") | ||
.font(.largeTitle) | ||
} | ||
|
||
RoundedRectangle(cornerRadius: 8) | ||
.frame(height: 3) | ||
|
||
if let date = viewStore.currentDate { | ||
HStack { | ||
Text(DateFormatter.convertToString(date: date)) | ||
.font(.title3) | ||
Spacer() | ||
} | ||
} | ||
|
||
Button { | ||
viewStore.send(.getCurrentDate) | ||
} label: { | ||
Text("Get New Date") | ||
.font(.largeTitle) | ||
} | ||
|
||
|
||
.frame(height: 3) | ||
|
||
if viewStore.uuidString.isEmpty { | ||
HStack { | ||
Text("None") | ||
.font(.title3) | ||
Spacer() | ||
} | ||
} else { | ||
HStack { | ||
Text(viewStore.uuidString) | ||
Spacer() | ||
} | ||
} | ||
|
||
Button { | ||
viewStore.send(.generateUUID) | ||
} label: { | ||
Text("Get New UUID") | ||
.font(.largeTitle) | ||
} | ||
} | ||
.alert( | ||
isPresented: viewStore.binding( | ||
get: \.isShowingAlert, | ||
send: { _ in Environment.Action.dismissAlert } | ||
), content: { | ||
Alert(title: Text("Test"), message: Text("Test")) | ||
} | ||
) | ||
.padding() | ||
} | ||
} | ||
} | ||
|
||
struct EnvironmentRouteView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
EnvironmentDemoView( | ||
store: Store( | ||
initialState: Environment.State(), | ||
reducer: Environment() | ||
) | ||
) | ||
} | ||
} | ||
|
||
extension DateFormatter { | ||
static func convertToString(date: Date) -> String { | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateStyle = .full | ||
dateFormatter.timeStyle = .full | ||
return dateFormatter.string(from: date) | ||
} | ||
} |
Oops, something went wrong.