mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Minimal Settings screen UI (#85)
* #37 Remove sign out button from home screen * #37 Move crash button visibility flag to BuildSettings, import BuildSettings from test targets * #37 Add log out button into the settings screen * #37 Add version into the settings screen * #37 enhance bug report parameters * #37 Remove sign out button from home screen * #37 Move crash button visibility flag to BuildSettings, import BuildSettings from test targets * #37 Add log out button into the settings screen * #37 Add version into the settings screen * #37 enhance bug report parameters * #37 Add changelog * #37 Fix code smells and PR remarks
This commit is contained in:
@@ -21,6 +21,10 @@ struct SettingsCoordinatorParameters {
|
||||
let bugReportService: BugReportServiceProtocol
|
||||
}
|
||||
|
||||
enum SettingsCoordinatorAction {
|
||||
case logout
|
||||
}
|
||||
|
||||
final class SettingsCoordinator: Coordinator, Presentable {
|
||||
|
||||
// MARK: - Properties
|
||||
@@ -39,6 +43,7 @@ final class SettingsCoordinator: Coordinator, Presentable {
|
||||
|
||||
// Must be used only internally
|
||||
var childCoordinators: [Coordinator] = []
|
||||
var callback: ((SettingsCoordinatorAction) -> Void)?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
@@ -60,6 +65,8 @@ final class SettingsCoordinator: Coordinator, Presentable {
|
||||
self.presentBugReportScreen()
|
||||
case .crash:
|
||||
self.parameters.bugReportService.crash()
|
||||
case .logout:
|
||||
self.callback?(.logout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ import Foundation
|
||||
enum SettingsViewModelAction {
|
||||
case reportBug
|
||||
case crash
|
||||
case logout
|
||||
}
|
||||
|
||||
// MARK: View
|
||||
|
||||
struct SettingsViewState: BindableState {
|
||||
var crashButtonVisible: Bool
|
||||
var bindings: SettingsViewStateBindings
|
||||
}
|
||||
|
||||
@@ -39,4 +39,5 @@ struct SettingsViewStateBindings {
|
||||
enum SettingsViewAction {
|
||||
case reportBug
|
||||
case crash
|
||||
case logout
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class SettingsViewModel: SettingsViewModelType, SettingsViewModelProtocol {
|
||||
|
||||
init() {
|
||||
let bindings = SettingsViewStateBindings()
|
||||
super.init(initialViewState: .init(crashButtonVisible: true, bindings: bindings))
|
||||
super.init(initialViewState: .init(bindings: bindings))
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -45,6 +45,8 @@ class SettingsViewModel: SettingsViewModelType, SettingsViewModelProtocol {
|
||||
callback?(.reportBug)
|
||||
case .crash:
|
||||
callback?(.crash)
|
||||
case .logout:
|
||||
callback?(.logout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ import SwiftUI
|
||||
struct Settings: View {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@State private var showingLogoutConfirmation = false
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@@ -28,24 +30,45 @@ struct Settings: View {
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Button { context.send(viewAction: .reportBug) } label: {
|
||||
Text(ElementL10n.sendBugReport)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 16)
|
||||
.accessibilityIdentifier("reportBugButton")
|
||||
Section {
|
||||
Button { context.send(viewAction: .reportBug) } label: {
|
||||
Text(ElementL10n.sendBugReport)
|
||||
}
|
||||
.foregroundColor(Color.element.primaryContent)
|
||||
.accessibilityIdentifier("reportBugButton")
|
||||
|
||||
if context.viewState.crashButtonVisible {
|
||||
Button { context.send(viewAction: .crash) } label: {
|
||||
Text("Crash the app")
|
||||
if BuildSettings.settingsCrashButtonVisible {
|
||||
Button("Crash the app",
|
||||
role: .destructive) { context.send(viewAction: .crash)
|
||||
}
|
||||
.accessibilityIdentifier("crashButton")
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
Button { showingLogoutConfirmation = true } label: {
|
||||
Text(ElementL10n.actionSignOut)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 16)
|
||||
.accessibilityIdentifier("crashButton")
|
||||
.foregroundColor(Color.element.primaryContent)
|
||||
.accessibilityIdentifier("logoutButton")
|
||||
.confirmationDialog(ElementL10n.actionSignOutConfirmationSimple,
|
||||
isPresented: $showingLogoutConfirmation,
|
||||
titleVisibility: .visible) {
|
||||
Button(ElementL10n.actionSignOut,
|
||||
role: .destructive) { context.send(viewAction: .logout)
|
||||
}
|
||||
}
|
||||
} footer: {
|
||||
versionText
|
||||
}
|
||||
}
|
||||
.navigationTitle(ElementL10n.settings)
|
||||
}
|
||||
|
||||
var versionText: some View {
|
||||
Text(ElementL10n.settingsVersion + ": " + ElementInfoPlist.cfBundleShortVersionString + " (" + ElementInfoPlist.cfBundleVersion + ")")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
Reference in New Issue
Block a user