Last active
August 27, 2020 17:41
-
-
Save Inncoder/17d6a89ad77f4ae82d31347465868010 to your computer and use it in GitHub Desktop.
Typing indicator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // TypingIndicator.swift | |
| // TypingIndicator | |
| // | |
| // Created by Inncoder on 19/08/2020. | |
| // Copyright © 2020 Inncoder AS. All rights reserved. | |
| // | |
| import SwiftUI | |
| struct TypingIndicator: View { | |
| @State private var numberOfTheAnimationgBall = 3 | |
| var body: some View { | |
| HStack(alignment: .firstTextBaseline) { | |
| ForEach(0..<3) { i in | |
| Capsule() | |
| .foregroundColor((self.numberOfTheAnimationgBall == i) ? .blue : Color(UIColor.darkGray)) | |
| .frame(width: self.ballSize, height: (self.numberOfTheAnimationgBall == i) ? self.ballSize/3 : self.ballSize) | |
| } | |
| } | |
| .animation(Animation.spring(response: 0.5, dampingFraction: 0.7, blendDuration: 0.1).speed(2)) | |
| .onAppear { | |
| Timer.scheduledTimer(withTimeInterval: self.speed, repeats: true) { _ in | |
| var randomNumb: Int | |
| repeat { | |
| randomNumb = Int.random(in: 0...2) | |
| } while randomNumb == self.numberOfTheAnimationgBall | |
| self.numberOfTheAnimationgBall = randomNumb | |
| } | |
| } | |
| } | |
| // MAKR: - Drawing Constants | |
| let ballSize: CGFloat = 20 | |
| let speed: Double = 0.3 | |
| } | |
| struct TypingIndicator_Previews: PreviewProvider { | |
| static var previews: some View { | |
| TypingIndicator() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment