From 6c1dca4c8e97fa57763b5700a94b953859353949 Mon Sep 17 00:00:00 2001 From: Jan Cortiel Date: Mon, 22 Jul 2024 12:08:48 +0200 Subject: [PATCH] #263: Fixed an iOS TaskDetailsView Style --- .../Views/ObservationErrorListView.swift | 64 +++++++++---------- .../Views/TaskDetails/TaskDetailsView.swift | 45 +++++++------ 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/iosApp/iosApp/Views/ObservationErrorListView.swift b/iosApp/iosApp/Views/ObservationErrorListView.swift index ee712075..0f2c2995 100644 --- a/iosApp/iosApp/Views/ObservationErrorListView.swift +++ b/iosApp/iosApp/Views/ObservationErrorListView.swift @@ -10,7 +10,7 @@ import shared import SwiftUI struct ObservationErrorListView: View { - let taskObservationErrors: [String] + let taskObservationErrors: [String] let taskObservationErrorActions: [String] @State private var scrollViewContentSize: CGSize = .zero @@ -18,47 +18,47 @@ struct ObservationErrorListView: View { private let navigationStrings = "Navigation" var body: some View { - if !taskObservationErrors.isEmpty { - ScrollView { - VStack { - ForEach(taskObservationErrors, id: \.self) { error in - HStack { - Image(systemName: "exclamationmark.triangle") - .font(.more.headline) - .foregroundColor(.more.important) - .padding(.trailing, 4) - BasicText(text: "\(error.localize(withComment: "Error message", useTable: errorStrings))!") + if !taskObservationErrors.isEmpty || !taskObservationErrorActions.isEmpty { + VStack { + if !taskObservationErrors.isEmpty { + ScrollView { + VStack { + ForEach(taskObservationErrors, id: \.self) { error in + HStack { + Image(systemName: "exclamationmark.triangle") + .font(.more.headline) + .foregroundColor(.more.important) + .padding(.trailing, 4) + BasicText(text: "\(error.localize(withComment: "Error message", useTable: errorStrings))!") + } + .padding(.bottom) + } } - .padding(.bottom) } + .frame(maxHeight: 100) } - } - if taskObservationErrorActions.isEmpty { - Divider() - } - } - - if !taskObservationErrorActions.isEmpty { - if taskObservationErrorActions - .contains(Observation_.companion.ERROR_DEVICE_NOT_CONNECTED) { - MoreActionButton(disabled: .constant(false)) { - ViewManager.shared.showBLEView(state: true) - } label: { - HStack { - Image(systemName: "applewatch") - .foregroundColor(.more.white) - .padding(.trailing, 4) - Text(String.localize(forKey: "Devices", withComment: "Lists all connected or needed devices.", inTable: navigationStrings)) + if !taskObservationErrorActions.isEmpty { + if taskObservationErrorActions + .contains(Observation_.companion.ERROR_DEVICE_NOT_CONNECTED) { + MoreActionButton(disabled: .constant(false)) { + ViewManager.shared.showBLEView(state: true) + } label: { + HStack { + Image(systemName: "applewatch") + .foregroundColor(.more.white) + .padding(.trailing, 4) + Text(String.localize(forKey: "Devices", withComment: "Lists all connected or needed devices.", inTable: navigationStrings)) + } + } } } } - - Divider() } } } #Preview { - ObservationErrorListView(taskObservationErrors: [], taskObservationErrorActions: [Observation_.companion.ERROR_DEVICE_NOT_CONNECTED]) + ObservationErrorListView(taskObservationErrors: ["Error"], taskObservationErrorActions: [Observation_.companion.ERROR_DEVICE_NOT_CONNECTED]) + } diff --git a/iosApp/iosApp/Views/TaskDetails/TaskDetailsView.swift b/iosApp/iosApp/Views/TaskDetails/TaskDetailsView.swift index 1f56f1a8..f2f32b1e 100644 --- a/iosApp/iosApp/Views/TaskDetails/TaskDetailsView.swift +++ b/iosApp/iosApp/Views/TaskDetails/TaskDetailsView.swift @@ -30,7 +30,7 @@ struct TaskDetailsView: View { var body: some View { MoreMainBackgroundView(contentPadding: 0) { - VStack(spacing: 20) { + VStack { VStack { HStack { Title2(titleText: viewModel.taskDetailsModel?.observationTitle ?? "") @@ -61,30 +61,35 @@ struct TaskDetailsView: View { DatapointsCollection(datapoints: $viewModel.dataCount, running: detailsModel.state == .running) } Spacer() - - ObservationErrorListView(taskObservationErrors: viewModel.taskObservationErrors, taskObservationErrorActions: viewModel.taskObservationErrorAction) - .background( - GeometryReader { geo -> Color in - DispatchQueue.main.async { - scrollViewContentSize = geo.size + + VStack { + ObservationErrorListView(taskObservationErrors: viewModel.taskObservationErrors, taskObservationErrorActions: viewModel.taskObservationErrorAction) + .background( + GeometryReader { geo -> Color in + DispatchQueue.main.async { + scrollViewContentSize = geo.size + } + return Color.clear } - return Color.clear + ) + .frame(maxWidth: .infinity, maxHeight: 100) + + if !detailsModel.hidden { + if let scheduleId = navigationModalState.navigationState(for: .taskDetails)?.scheduleId { + Divider() + ObservationButton( + observationActionDelegate: viewModel, + scheduleId: scheduleId, + observationType: detailsModel.observationType, + state: detailsModel.state, + disabled: !detailsModel.state.active() || !viewModel.taskObservationErrors.isEmpty) + .padding(.bottom) } - ) - .frame(maxWidth: .infinity, maxHeight: 150) - - if !detailsModel.hidden { - if let scheduleId = navigationModalState.navigationState(for: .taskDetails)?.scheduleId { - ObservationButton( - observationActionDelegate: viewModel, - scheduleId: scheduleId, - observationType: detailsModel.observationType, - state: detailsModel.state, - disabled: !detailsModel.state.active() || !viewModel.taskObservationErrors.isEmpty) } } + } - Spacer() + } .customNavigationTitle(with: NavigationScreen.taskDetails.localize(useTable: navigationStrings, withComment: "Task Detail")) .onAppear {