Pārlūkot izejas kodu

Merge pull request #1056 from MikePlante1/reduce-motion

Utilize the reduce motion accessibility setting
Deniz Cengiz 1 mēnesi atpakaļ
vecāks
revīzija
5d0b686d03

+ 25 - 16
Trio/Sources/Modules/Onboarding/View/Animations/LogoBurstSplash.swift

@@ -16,6 +16,8 @@ struct LogoBurstSplash<Content: View>: View {
     @State private var viewOpacity: Double = 1.0
     @State private var splashScale: CGFloat = 1.0
 
+    @Environment(\.accessibilityReduceMotion) var reduceMotion
+
     init(isActive: Binding<Bool>, @ViewBuilder content: () -> Content) {
         _isActive = isActive
         self.content = content()
@@ -58,32 +60,39 @@ struct LogoBurstSplash<Content: View>: View {
                             .scaleEffect(isPulsing ? 1.1 : logoScale)
                             .opacity(logoOpacity)
                             .rotationEffect(.degrees(logoRotation))
-                            .animation(.easeInOut(duration: 1.0), value: logoScale)
+                            .animation(reduceMotion ? nil : .easeInOut(duration: 1.0), value: logoScale)
                             .animation(.easeInOut(duration: 1.0), value: logoOpacity)
-                            .animation(.linear(duration: 2.0), value: logoRotation)
+                            .animation(reduceMotion ? nil : .linear(duration: 2.0), value: logoRotation)
                             .animation(
-                                .easeInOut(duration: 0.8).repeatForever(autoreverses: true),
+                                reduceMotion ? nil : .easeInOut(duration: 0.8).repeatForever(autoreverses: true),
                                 value: isPulsing
                             )
                     }
                     .scaleEffect(splashScale)
                     .opacity(viewOpacity)
                     .onAppear {
-                        shapes = BurstShape.createBurst(count: 250, in: geo.frame(in: .local))
-
-                        withAnimation {
-                            isPulsing = true
-                            logoOpacity = 1
+                        if reduceMotion {
+                            withAnimation(.easeInOut(duration: 1.0)) {
+                                logoOpacity = 1
+                            }
                             logoScale = 1
-                            logoRotation = 360
-                        }
+                        } else {
+                            shapes = BurstShape.createBurst(count: 250, in: geo.frame(in: .local))
+
+                            withAnimation(.easeInOut(duration: 1.0)) {
+                                isPulsing = true
+                                logoOpacity = 1
+                                logoScale = 1
+                                logoRotation = 360
+                            }
 
-                        DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
-                            isPulsing = false
-                        }
+                            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
+                                isPulsing = false
+                            }
 
-                        DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
-                            exploded = true
+                            DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
+                                exploded = true
+                            }
                         }
 
                         DispatchQueue.main.asyncAfter(deadline: .now() + 2.5) {
@@ -96,7 +105,7 @@ struct LogoBurstSplash<Content: View>: View {
                         DispatchQueue.main.asyncAfter(deadline: .now() + 2.8) {
                             withAnimation(.easeIn(duration: 0.6)) {
                                 viewOpacity = 0
-                                splashScale = 0.1
+                                if !reduceMotion { splashScale = 0.1 }
                             }
                         }
 

+ 9 - 0
Trio/Sources/Modules/Onboarding/View/Animations/PulsingLogoAnimation.swift

@@ -11,6 +11,7 @@ struct PulsingLogoAnimation: View {
     @State private var opacity = 0.0
     @State private var rotation = 0.0
     @State private var isPulsing = false
+    @Environment(\.accessibilityReduceMotion) var reduceMotion
 
     var body: some View {
         Image("trioCircledNoBackground")
@@ -22,6 +23,14 @@ struct PulsingLogoAnimation: View {
             .rotationEffect(.degrees(rotation))
             .scaleEffect(isPulsing ? 1.1 : 1.0)
             .onAppear {
+                if reduceMotion {
+                    scale = 1.0
+                    withAnimation(.easeInOut(duration: 1.0)) {
+                        opacity = 1.0
+                    }
+                    return
+                }
+
                 withAnimation(.easeInOut(duration: 1.0)) {
                     scale = 1.0
                     opacity = 1.0

+ 17 - 7
Trio/Sources/Modules/Onboarding/View/OnboardingRootView.swift

@@ -296,6 +296,19 @@ struct OnboardingStepContent: View {
     @Binding var currentTargetBehaviorSubstep: TargetBehaviorSubstep
     @Bindable var state: Onboarding.StateModel
     var navigationDirection: OnboardingNavigationDirection
+    @Environment(\.accessibilityReduceMotion) var reduceMotion
+
+    private var transition: AnyTransition {
+        if reduceMotion {
+            return .opacity
+        }
+        switch navigationDirection {
+        case .forward:
+            return .asymmetric(insertion: .move(edge: .trailing), removal: .move(edge: .leading))
+        case .backward:
+            return .asymmetric(insertion: .move(edge: .leading), removal: .move(edge: .trailing))
+        }
+    }
 
     var body: some View {
         ScrollViewReader { scrollProxy in
@@ -377,11 +390,7 @@ struct OnboardingStepContent: View {
                                 CompletedStepView(isOnboardingCompleted: true, currentChapter: nil)
                             }
                         }
-                        .transition(
-                            navigationDirection == .forward
-                                ? .asymmetric(insertion: .move(edge: .trailing), removal: .move(edge: .leading))
-                                : .asymmetric(insertion: .move(edge: .leading), removal: .move(edge: .trailing))
-                        )
+                        .transition(transition)
                         .padding(.horizontal)
                         .id(currentStep.id)
                     }
@@ -464,13 +473,14 @@ struct OnboardingNavigationButtons: View {
     @Bindable var state: Onboarding.StateModel
     var shouldDisableNextButton: Bool
     var navigationDirectionChanged: (OnboardingNavigationDirection) -> Void
+    @Environment(\.accessibilityReduceMotion) var reduceMotion
 
     var body: some View {
         HStack {
             if currentStep != .welcome {
                 Button(action: {
                     navigationDirectionChanged(.backward)
-                    withAnimation {
+                    withAnimation(reduceMotion ? .easeInOut(duration: 0.25) : .default) {
                         handleBackNavigation()
                     }
                 }) {
@@ -487,7 +497,7 @@ struct OnboardingNavigationButtons: View {
 
             Button(action: {
                 navigationDirectionChanged(.forward)
-                withAnimation {
+                withAnimation(reduceMotion ? .easeInOut(duration: 0.25) : .default) {
                     handleNextNavigation()
                 }
             }) {