Skip to content

Commit

Permalink
✨ (GEK): Add reinforcer enabler
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Dec 22, 2023
1 parent 7dc280e commit 2911c71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct ActivityProgressBar: View {
.padding(6)
.onChange(of: self.viewModel.currentExerciseSharedData.state) { newValue in
if newValue == .completed {
withAnimation(.snappy.delay(5)) {
withAnimation(.snappy.delay(self.viewModel.isReinforcerEnabled ? 5 : 0.5)) {
self.currentColor = .green
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Lottie
import RobotKit
import SwiftUI

// swiftlint:disable cyclomatic_complexity void_function_in_ternary

extension LottieAnimation {
static var reinforcer: LottieAnimation {
LottieAnimation.named("reinforcer-spin-blink", bundle: .module)!
Expand Down Expand Up @@ -54,7 +56,7 @@ public struct ActivityView: View {
}
}
.id(self.viewModel.currentExerciseIndexInSequence)
.blur(radius: self.viewModel.isCurrentExerciseDisplayingReinforcer ? 20 : 0)
.blur(radius: self.viewModel.isCurrentExerciseCompleted && self.viewModel.isReinforcerEnabled ? 20 : 0)
.opacity(self.viewModel.isCurrentActivityCompleted ? 0 : 1)

self.lottieReinforcer
Expand All @@ -80,6 +82,13 @@ public struct ActivityView: View {
}
.disabled(self.viewModel.isFirstExercise)
}
ToolbarItem(placement: .topBarTrailing) {
Button {
self.viewModel.isReinforcerEnabled.toggle()
} label: {
Image(systemName: self.viewModel.isReinforcerEnabled ? "circle" : "circle.slash")
}
}
ToolbarItem(placement: .topBarTrailing) {
Button("Dismiss") {
self.dismiss()
Expand Down Expand Up @@ -130,15 +139,16 @@ public struct ActivityView: View {

@ViewBuilder
private var lottieReinforcer: some View {
let isLottieDisplayed = self.viewModel.isCurrentExerciseDisplayingReinforcer
let isLottieDisplayed = self.viewModel.isCurrentExerciseCompleted
let isReinforcerEnabled = self.viewModel.isReinforcerEnabled

if isLottieDisplayed {
if isLottieDisplayed, isReinforcerEnabled {
LottieView(
animation: .reinforcer,
speed: 0.25,
action: {
withAnimation {
self.viewModel.isCurrentExerciseDisplayingReinforcer = false
self.viewModel.isCurrentExerciseCompleted = false
}
}
)
Expand Down Expand Up @@ -168,7 +178,7 @@ public struct ActivityView: View {
.buttonStyle(.borderedProminent)
.tint(.green)
.padding()
.transition(.asymmetric(insertion: .opacity.animation(.snappy.delay(5)), removal: .identity))
.transition(.asymmetric(insertion: .opacity.animation(.snappy.delay(self.viewModel.isReinforcerEnabled ? 5 : 0.5)), removal: .identity))
}
}

Expand Down Expand Up @@ -250,6 +260,8 @@ public struct ActivityView: View {
}
}

// swiftlint:enable cyclomatic_complexity void_function_in_ternary

#Preview {
let activity = ContentKit.decodeActivity("activity-sample")
return ActivityView(viewModel: ActivityViewViewModel(activity: activity))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class ActivityViewViewModel: ObservableObject {
@Published var currentExercise: Exercise
@Published var currentExerciseInterface: Exercise.Interface
@Published var currentExerciseSharedData: ExerciseSharedData
@Published var isCurrentExerciseDisplayingReinforcer: Bool = false
@Published var isCurrentExerciseCompleted: Bool = false
@Published var isReinforcerEnabled: Bool = true
@Published var isCurrentActivityCompleted: Bool = false

// TODO(@ladislas/@hugo): Add method to change this boolean

Check warning on line 47 in Modules/GameEngineKit/Sources/_NewSystem/Views/Activity/ActivityViewViewModel.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas/@hugo): Add method ...) (todo)
Expand Down Expand Up @@ -101,7 +102,7 @@ public class ActivityViewViewModel: ObservableObject {
self.objectWillChange.send()
if self.currentExerciseSharedData.state == .completed {
withAnimation {
self.isCurrentExerciseDisplayingReinforcer = true
self.isCurrentExerciseCompleted = true
}
}
}
Expand Down

0 comments on commit 2911c71

Please sign in to comment.