From e1c662030f3b3b513cd6b69792f63fcae4c15727 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 29 Aug 2023 16:29:42 +1000 Subject: [PATCH] minor refactor --- Session/Onboarding/LandingView.swift | 46 ++++++++++++---------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/Session/Onboarding/LandingView.swift b/Session/Onboarding/LandingView.swift index 323d95367..4fa2b8841 100644 --- a/Session/Onboarding/LandingView.swift +++ b/Session/Onboarding/LandingView.swift @@ -8,9 +8,7 @@ import SessionUtilitiesKit struct LandingView: View { @EnvironmentObject var host: HostWrapper - - @State var numberOfBubblesShown: Int = 0 - + var body: some View { ZStack(alignment: .center) { if #available(iOS 14.0, *) { @@ -33,24 +31,7 @@ struct LandingView: View { Spacer(minLength: 0) .frame(maxHeight: 2 * Values.mediumSpacing) - FakeChat($numberOfBubblesShown) - .onAppear { - guard numberOfBubblesShown < 4 else { return } - - Timer.scheduledTimerOnMainThread(withTimeInterval: 0.2, repeats: false) { _ in - withAnimation(.spring().speed(0.68)) { - numberOfBubblesShown = 1 - } - Timer.scheduledTimerOnMainThread(withTimeInterval: 1.5, repeats: true) { timer in - withAnimation(.spring().speed(0.68)) { - numberOfBubblesShown += 1 - if numberOfBubblesShown >= 4 { - timer.invalidate() - } - } - } - } - } + FakeChat() Spacer(minLength: 0) .frame(maxHeight: Values.massiveSpacing) @@ -192,7 +173,7 @@ struct ChatBubble: View { } struct FakeChat: View { - @Binding var numberOfBubblesShown: Int + @State var numberOfBubblesShown: Int = 0 let chatBubbles: [ChatBubble] = [ ChatBubble(text: "onboarding_chat_bubble_1".localized(), outgoing: false), @@ -201,10 +182,6 @@ struct FakeChat: View { ChatBubble(text: "onboarding_chat_bubble_4".localized(), outgoing: true), ] - init(_ numberOfBubblesShown: Binding) { - self._numberOfBubblesShown = numberOfBubblesShown - } - var body: some View { VStack( alignment: .leading, @@ -235,6 +212,23 @@ struct FakeChat: View { alignment: .bottom ) .padding(.horizontal, 36) + .onAppear { + guard numberOfBubblesShown < 4 else { return } + + Timer.scheduledTimerOnMainThread(withTimeInterval: 0.2, repeats: false) { _ in + withAnimation(.spring().speed(0.68)) { + numberOfBubblesShown = 1 + } + Timer.scheduledTimerOnMainThread(withTimeInterval: 1.5, repeats: true) { timer in + withAnimation(.spring().speed(0.68)) { + numberOfBubblesShown += 1 + if numberOfBubblesShown >= 4 { + timer.invalidate() + } + } + } + } + } } }