From 4f3a17670aa2602e420e3c2b516d0c71677fef85 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 22 Aug 2023 11:05:35 +1000 Subject: [PATCH] 15s animation on loading screen --- Session/Onboarding/LoadingView.swift | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Session/Onboarding/LoadingView.swift b/Session/Onboarding/LoadingView.swift index 321ff599e..485c921f6 100644 --- a/Session/Onboarding/LoadingView.swift +++ b/Session/Onboarding/LoadingView.swift @@ -8,13 +8,12 @@ import SignalUtilitiesKit struct LoadingView: View { @EnvironmentObject var host: HostWrapper - @State var percentage: Double = 0 + @State var percentage: Double = 0.0 private let flow: Onboarding.Flow public init(flow: Onboarding.Flow) { self.flow = flow - progress() } var body: some View { @@ -35,6 +34,9 @@ struct LoadingView: View { CircularProgressView($percentage) .padding(.horizontal, Values.massiveSpacing) .padding(.bottom, Values.mediumSpacing) + .onAppear { + progress() + } Text("onboarding_load_account_waiting".localized()) .bold() @@ -54,15 +56,15 @@ struct LoadingView: View { } private func progress() { - guard percentage < 1 else { return } - print(percentage) - Timer.scheduledTimer( + Timer.scheduledTimerOnMainThread( withTimeInterval: 0.15, - repeats: false, - block: { _ in - percentage += 0.01 - progress() - }) + repeats: true + ) { timer in + self.percentage += 0.01 + if percentage >= 1 { + timer.invalidate() + } + } } }