Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hugo/feature/Improve Continue button experience #1594

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Leka - iOS Monorepo
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

import LocalizationKit
import SwiftUI

// MARK: - ActivityView.ContinueButtonLabel

extension ActivityView {
struct ContinueButtonLabel: View {
var body: some View {
Text(l10n.GameEngineKit.ActivityView.continueButton)
.font(.title.bold())
.foregroundColor(.white)
.frame(width: 330, height: 80)
.background(Capsule().fill(.green).shadow(radius: 1))
}
}
}

#Preview {
ActivityView.ContinueButtonLabel()
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,56 @@
}

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 @@ -179,7 +218,7 @@

@Environment(\.dismiss) var dismiss

// TODO: (@ladislas) was @ObservedObject, check why

Check warning on line 221 in Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) was @ObservedObjec...) (todo)
@StateObject var viewModel: ActivityViewViewModel

// MARK: Private
Expand Down Expand Up @@ -208,81 +247,6 @@
}
}

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 @@
}
}

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 All @@ -432,4 +412,4 @@
NavigationStack {
ActivityView(activity: Activity.mock)
}
}

Check warning on line 415 in Modules/GameEngineKit/Sources/OldSystem/Views/Activity/ActivityView.swift

View workflow job for this annotation

GitHub Actions / swiftlint

File should contain 400 lines or less: currently contains 415 (file_length)
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ActivityViewViewModel: ObservableObject {
}

var delayAfterReinforcerAnimation: Double {
self.isReinforcerAnimationEnabled ? 5 : 0.5
self.isReinforcerAnimationEnabled ? 3.5 : 0.5
}

var isProgressBarVisible: Bool {
Expand Down
Loading