Merge branch 'langleyd/4781_swiftui_template_examples' of https://github.com/vector-im/element-ios into langleyd/4781_swiftui_template_example2

This commit is contained in:
David Langley
2021-09-20 17:28:16 +01:00
11 changed files with 34 additions and 9 deletions
@@ -48,7 +48,9 @@ final class TemplateUserProfileCoordinator: Coordinator {
// MARK: - Public
func start() {
MXLog.debug("[TemplateUserProfileCoordinator] did start.")
templateUserProfileViewModel.completion = { [weak self] result in
MXLog.debug("[TemplateUserProfileCoordinator] TemplateUserProfileViewModel did complete with result: \(result).")
guard let self = self else { return }
switch result {
case .cancel, .done:
@@ -17,5 +17,7 @@
import Foundation
enum TemplateUserProfileStateAction {
case incrementCount
case decrementCount
case updatePresence(TemplateUserProfilePresence)
}
@@ -17,6 +17,8 @@
import Foundation
enum TemplateUserProfileViewAction {
case incrementCount
case decrementCount
case cancel
case done
}
@@ -20,4 +20,5 @@ struct TemplateUserProfileViewState: BindableState {
let avatar: AvatarInputProtocol?
let displayName: String?
var presence: TemplateUserProfilePresence
var count: Int
}
@@ -25,6 +25,8 @@ protocol TemplateUserProfileServiceProtocol: Avatarable {
var presenceSubject: CurrentValueSubject<TemplateUserProfilePresence, Never> { get }
}
// MARK: Avatarable
@available(iOS 14.0, *)
extension TemplateUserProfileServiceProtocol {
var mxContentUri: String? {
@@ -41,13 +41,13 @@ class TemplateUserProfileUITests: MockScreenTest {
func verifyTemplateUserProfilePresence(presence: TemplateUserProfilePresence) {
let presenceText = app.staticTexts["presenceText"]
XCTAssert(presenceText.exists)
XCTAssert(presenceText.label == presence.title)
XCTAssertEqual(presenceText.label, presence.title)
}
func verifyTemplateUserProfileLongName(name: String) {
let displayNameText = app.staticTexts["displayNameText"]
XCTAssert(displayNameText.exists)
XCTAssert(displayNameText.label == name)
XCTAssertEqual(displayNameText.label, name)
}
}
@@ -38,10 +38,16 @@ struct TemplateUserProfile: View {
presence: viewModel.viewState.presence
)
Divider()
VStack{
Text("More great user content!")
HStack{
Text("Counter: \(viewModel.viewState.count)")
.font(theme.fonts.title2)
.foregroundColor(theme.colors.secondaryContent)
Button("-") {
viewModel.send(viewAction: .decrementCount)
}
Button("+") {
viewModel.send(viewAction: .incrementCount)
}
}
.frame(maxHeight: .infinity)
}
@@ -52,7 +52,8 @@ class TemplateUserProfileViewModel: TemplateUserProfileViewModelType, TemplateUs
return TemplateUserProfileViewState(
avatar: templateUserProfileService.avatarData,
displayName: templateUserProfileService.displayName,
presence: templateUserProfileService.presenceSubject.value
presence: templateUserProfileService.presenceSubject.value,
count: 0
)
}
@@ -71,6 +72,10 @@ class TemplateUserProfileViewModel: TemplateUserProfileViewModelType, TemplateUs
cancel()
case .done:
done()
case .incrementCount:
dispatch(action: .incrementCount)
case .decrementCount:
dispatch(action: .decrementCount)
}
}
@@ -78,6 +83,10 @@ class TemplateUserProfileViewModel: TemplateUserProfileViewModelType, TemplateUs
switch action {
case .updatePresence(let presence):
state.presence = presence
case .incrementCount:
state.count += 1
case .decrementCount:
state.count -= 1
}
UILog.debug("[TemplateUserProfileViewModel] reducer with action \(action) produced state: \(state)")
}