BallScaleRippleMultiple.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // BallScaleRippleMultiple.swift
  3. // LoaderUI
  4. //
  5. // Created by Vinh Nguyen on 5/18/20.
  6. // Copyright © 2020 Vinh Nguyen. All rights reserved.
  7. //
  8. import SwiftUI
  9. public struct BallScaleRippleMultiple: View {
  10. private let beginTimes = [0, 0.2, 0.4]
  11. private let duration = 1.25
  12. private let timingFunction = TimingFunction.timingCurve(c0x: 0.21, c0y: 0.53, c1x: 0.56, c1y: 0.8)
  13. private let keyTimes = [0, 0.7, 1]
  14. private let scaleValues: [CGFloat] = [0.1, 1, 1]
  15. private let opacityValues = [1, 0.7, 0]
  16. public var body: some View {
  17. GeometryReader(content: self.render)
  18. }
  19. public init() { }
  20. func render(geometry: GeometryProxy) -> some View {
  21. let dimension = min(geometry.size.width, geometry.size.height)
  22. let timingFunctions = Array(repeating: timingFunction, count: keyTimes.count - 1)
  23. return
  24. ZStack {
  25. ForEach(0..<3, id: \.self) { index in
  26. KeyframeAnimationController(beginTime: self.beginTimes[index],
  27. duration: self.duration,
  28. timingFunctions: timingFunctions,
  29. keyTimes: self.keyTimes) {
  30. Ring()
  31. .scaleEffect(self.scaleValues[$0])
  32. .opacity(self.opacityValues[$0])
  33. }
  34. }
  35. }
  36. .frame(width: dimension, height: dimension, alignment: .center)
  37. }
  38. }
  39. struct BallScaleRippleMultiple_Previews: PreviewProvider {
  40. static var previews: some View {
  41. BallScaleRippleMultiple()
  42. }
  43. }