Fix ordering, add pragmas, fix visibility on a few functions, remove default param on state.

This commit is contained in:
David Langley
2021-09-08 11:43:57 +01:00
parent c6996cf62d
commit 13a9d82486
6 changed files with 52 additions and 31 deletions
@@ -46,7 +46,7 @@ final class TemplateUserProfileCoordinator: Coordinator {
templateUserProfileViewController = VectorHostingController(rootView: view)
}
// MARK: - Public methods
// MARK: - Public
func start() {
templateUserProfileViewModel.completion = { [weak self] result in
guard let self = self else { return }
@@ -19,5 +19,5 @@ import Foundation
struct TemplateUserProfileViewState {
let avatar: AvatarInputType?
let displayName: String?
var presence: TemplateUserProfilePresence = .offline
var presence: TemplateUserProfilePresence
}
@@ -19,20 +19,12 @@ import SwiftUI
@available(iOS 14.0, *)
struct TemplateUserProfile: View {
// MARK: - Properties
// MARK: Public
@Environment(\.theme) var theme: ThemeSwiftUI
@ObservedObject var viewModel: TemplateUserProfileViewModel
var leftButton: some View {
Button(VectorL10n.cancel) {
viewModel.proccess(viewAction: .cancel)
}
}
var rightButton: some View {
Button(VectorL10n.done) {
viewModel.proccess(viewAction: .cancel)
}
}
var body: some View {
VStack {
@@ -57,8 +49,24 @@ struct TemplateUserProfile: View {
.navigationTitle(viewModel.viewState.displayName ?? "")
.navigationBarItems(leading: leftButton, trailing: rightButton)
}
// MARK: Private
private var leftButton: some View {
Button(VectorL10n.cancel) {
viewModel.proccess(viewAction: .cancel)
}
}
private var rightButton: some View {
Button(VectorL10n.done) {
viewModel.proccess(viewAction: .cancel)
}
}
}
// MARK: - Previews
@available(iOS 14.0, *)
struct TemplateUserProfile_Previews: PreviewProvider {
static var previews: some View {
@@ -19,6 +19,10 @@ import SwiftUI
@available(iOS 14.0, *)
struct TemplateUserProfileHeader: View {
// MARK: - Properties
// MARK: Public
@Environment(\.theme) var theme: ThemeSwiftUI
let avatar: AvatarInputType?
let displayName: String?
@@ -43,6 +47,8 @@ struct TemplateUserProfileHeader: View {
}
}
// MARK: - Previews
@available(iOS 14.0, *)
struct TemplateUserProfileHeader_Previews: PreviewProvider {
static var previews: some View {
@@ -19,18 +19,10 @@ import SwiftUI
@available(iOS 14.0, *)
struct TemplateUserProfilePresenceView: View {
let presense: TemplateUserProfilePresence
// MARK: - Properties
var foregroundColor: Color {
switch presense {
case .online:
return .green
case .idle:
return .orange
case .offline:
return .gray
}
}
// MARK: Public
let presense: TemplateUserProfilePresence
var body: some View {
HStack {
@@ -44,8 +36,23 @@ struct TemplateUserProfilePresenceView: View {
.foregroundColor(foregroundColor)
.padding(0)
}
// MARK: Private
private var foregroundColor: Color {
switch presense {
case .online:
return .green
case .idle:
return .orange
case .offline:
return .gray
}
}
}
// MARK: - Previews
@available(iOS 14.0, *)
struct TemplateUserProfilePresenceView_Previews: PreviewProvider {
static var previews: some View {
@@ -31,10 +31,6 @@ class TemplateUserProfileViewModel: ObservableObject, TemplateUserProfileViewMod
var completion: ((TemplateUserProfileViewModelResult) -> Void)?
private static func defaultState(userService: TemplateUserProfileServiceProtocol) -> TemplateUserProfileViewState {
return TemplateUserProfileViewState(avatar: userService.avatarData, displayName: userService.displayName)
}
// MARK: - Setup
init(userService: TemplateUserProfileServiceProtocol, initialState: TemplateUserProfileViewState? = nil) {
self.userService = userService
@@ -47,7 +43,11 @@ class TemplateUserProfileViewModel: ObservableObject, TemplateUserProfileViewMod
.store(in: &cancellables)
}
// MARK: - Public methods
private static func defaultState(userService: TemplateUserProfileServiceProtocol) -> TemplateUserProfileViewState {
return TemplateUserProfileViewState(avatar: userService.avatarData, displayName: userService.displayName, presence: .offline)
}
// MARK: - Public
func proccess(viewAction: TemplateUserProfileViewAction) {
switch viewAction {
case .cancel:
@@ -57,7 +57,7 @@ class TemplateUserProfileViewModel: ObservableObject, TemplateUserProfileViewMod
}
}
// MARK: - Private methods
// MARK: - Private
/**
Send state actions to mutate the state.
*/