From 29a8181f822a93a84b72f049586937554e052642 Mon Sep 17 00:00:00 2001 From: Hugo Pezziardi Date: Mon, 25 Nov 2024 17:58:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20(GEK):=20Refactor=20ActivityView?= =?UTF-8?q?=20for=20better=20UX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Activity/ActivityView.swift | 144 ++++++++---------- 1 file changed, 62 insertions(+), 82 deletions(-) diff --git a/Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift b/Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift index e5a884525..435debf86 100644 --- a/Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift +++ b/Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift @@ -73,17 +73,56 @@ public struct ActivityView: View { } if self.viewModel.isReinforcerAnimationVisible { - self.reinforcerAnimationView + LottieView( + animation: .reinforcer, + speed: 0.2 + ) + .frame(maxWidth: .infinity) + .transition( + .asymmetric( + insertion: .opacity.animation(.snappy.delay(0.75)), + removal: .identity + ) + ) + .onAppear { + self.robot.run(self.reinforcer) + } + + if case .completed = self.viewModel.currentExerciseSharedData.state, self.viewModel.isReinforcerAnimationVisible { + VStack(spacing: 30) { + Spacer() + + Button { + self.continueExercise() + } label: { + ContinueButtonLabel() + } + + Button(String(l10n.GameEngineKit.ActivityView.hideReinforcerToShowAnswersButton.characters)) { + withAnimation { + self.viewModel.isReinforcerAnimationVisible = false + } + } + .buttonStyle(.bordered) + .padding(.bottom, 50) + } .frame(maxWidth: .infinity) + .transition( + .asymmetric( + insertion: .opacity.animation(.snappy.delay(self.viewModel.delayAfterReinforcerAnimation)), + removal: .identity + ) + ) + } } - HStack { - if case .completed = self.viewModel.currentExerciseSharedData.state { - if self.viewModel.isReinforcerAnimationVisible { - self.hideReinforcerToShowAnswersButton - } - self.continueButton + if case .completed = self.viewModel.currentExerciseSharedData.state, !self.viewModel.isReinforcerAnimationVisible { + Button(String(l10n.GameEngineKit.ActivityView.continueButton.characters)) { + self.continueExercise() } + .buttonStyle(.borderedProminent) + .tint(.green) + .padding() } } .frame(maxWidth: .infinity) @@ -208,81 +247,6 @@ public struct ActivityView: View { } } - private var reinforcerAnimationView: some View { - LottieView( - animation: .reinforcer, - speed: 0.2 - ) - .onAppear { - self.robot.run(self.reinforcer) - } - .transition( - .asymmetric( - insertion: .opacity.animation(.snappy.delay(0.75)), - removal: .identity - ) - ) - } - - private var continueButton: some View { - Button(String(l10n.GameEngineKit.ActivityView.continueButton.characters)) { - if self.viewModel.isLastExercise { - self.viewModel.scorePanelEnabled ? self.viewModel.moveToActivityEnd() : self.dismiss() - self.saveActivityCompletion() - - AnalyticsManager.logEventActivityEnd( - id: self.viewModel.currentActivity.id, - name: self.viewModel.currentActivity.name, - carereceiverIDs: self.carereceiverManager.currentCarereceivers.value.compactMap(\.id).joined(separator: ","), - reason: .activityCompleted - ) - } else { - self.viewModel.moveToNextExercise() - } - } - .buttonStyle(.borderedProminent) - .tint(.green) - .padding() - .transition( - .asymmetric( - insertion: .opacity.animation(.snappy.delay(self.viewModel.delayAfterReinforcerAnimation)), - removal: .identity - ) - ) - } - - private var finishButton: some View { - Button(String(l10n.GameEngineKit.ActivityView.finishButton.characters)) { - // TODO(@macteuts): Move the following out of then View if relevant - self.viewModel.currentExerciseSharedData.state = .completed(level: .excellent) - } - .buttonStyle(.bordered) - .tint(.gray) - .padding() - .transition( - .asymmetric( - insertion: .opacity.animation(.snappy.delay(2)), - removal: .identity - ) - ) - } - - private var hideReinforcerToShowAnswersButton: some View { - Button(String(l10n.GameEngineKit.ActivityView.hideReinforcerToShowAnswersButton.characters)) { - withAnimation { - self.viewModel.isReinforcerAnimationVisible = false - } - } - .buttonStyle(.bordered) - .padding() - .transition( - .asymmetric( - insertion: .opacity.animation(.snappy.delay(self.viewModel.delayAfterReinforcerAnimation)), - removal: .identity - ) - ) - } - @ViewBuilder private func currentExerciseInterface() -> some View { switch self.viewModel.currentExerciseInterface { @@ -419,6 +383,22 @@ public struct ActivityView: View { } } + private func continueExercise() { + if self.viewModel.isLastExercise { + self.viewModel.scorePanelEnabled ? self.viewModel.moveToActivityEnd() : self.dismiss() + self.saveActivityCompletion() + + AnalyticsManager.logEventActivityEnd( + id: self.viewModel.currentActivity.id, + name: self.viewModel.currentActivity.name, + carereceiverIDs: self.carereceiverManager.currentCarereceivers.value.compactMap(\.id).joined(separator: ","), + reason: .activityCompleted + ) + } else { + self.viewModel.moveToNextExercise() + } + } + private func saveActivityCompletion() { let caregiverID = self.caregiverManagerViewModel.currentCaregiver?.id let carereceiverIDs = self.carereceiverManagerViewModel.currentCarereceivers.compactMap(\.id)