mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-23 01:52:44 +02:00
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:
+2
@@ -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:
|
||||
|
||||
+2
@@ -17,5 +17,7 @@
|
||||
import Foundation
|
||||
|
||||
enum TemplateUserProfileStateAction {
|
||||
case incrementCount
|
||||
case decrementCount
|
||||
case updatePresence(TemplateUserProfilePresence)
|
||||
}
|
||||
|
||||
+2
@@ -17,6 +17,8 @@
|
||||
import Foundation
|
||||
|
||||
enum TemplateUserProfileViewAction {
|
||||
case incrementCount
|
||||
case decrementCount
|
||||
case cancel
|
||||
case done
|
||||
}
|
||||
|
||||
+1
@@ -20,4 +20,5 @@ struct TemplateUserProfileViewState: BindableState {
|
||||
let avatar: AvatarInputProtocol?
|
||||
let displayName: String?
|
||||
var presence: TemplateUserProfilePresence
|
||||
var count: Int
|
||||
}
|
||||
|
||||
+2
@@ -25,6 +25,8 @@ protocol TemplateUserProfileServiceProtocol: Avatarable {
|
||||
var presenceSubject: CurrentValueSubject<TemplateUserProfilePresence, Never> { get }
|
||||
}
|
||||
|
||||
// MARK: Avatarable
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
extension TemplateUserProfileServiceProtocol {
|
||||
var mxContentUri: String? {
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-2
@@ -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)
|
||||
}
|
||||
|
||||
+10
-1
@@ -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)")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user