Skip to content

Commit

Permalink
💄 (GEK): Refactor ActivityView for better UX
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Nov 25, 2024
1 parent b3eb4a6 commit 29a8181
Showing 1 changed file with 62 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 29a8181

Please sign in to comment.