From 44386582cc7540ddcc5ae54a5d760b2be69917d3 Mon Sep 17 00:00:00 2001 From: Daniil Manin Date: Wed, 7 Oct 2020 18:50:44 +0700 Subject: [PATCH] add separate struct/files for each indicators add folder source path in podspec --- ActivityIndicatorView.podspec | 3 +- .../project.pbxproj | 48 ++++++++++++ Source/Indicators/ArcsIndicatorView.swift | 55 ++++++++++++++ Source/Indicators/DefaultIndicatorView.swift | 55 ++++++++++++++ .../Indicators/EqualizerIndicatorView.swift | 50 +++++++++++++ .../FlickeringDotsIndicatorView.swift | 58 +++++++++++++++ Source/Indicators/GradientIndicatorView.swift | 43 +++++++++++ .../Indicators/GrowingArcIndicatorView.swift | 74 +++++++++++++++++++ .../GrowingCircleIndicatorView.swift | 33 +++++++++ .../Indicators/OpacityDotsIndicatorView.swift | 56 ++++++++++++++ .../RotatingDotsIndicatorView.swift | 51 +++++++++++++ .../Indicators/ScalingDotsIndicatorView.swift | 52 +++++++++++++ 12 files changed, 577 insertions(+), 1 deletion(-) create mode 100644 Source/Indicators/ArcsIndicatorView.swift create mode 100644 Source/Indicators/DefaultIndicatorView.swift create mode 100644 Source/Indicators/EqualizerIndicatorView.swift create mode 100644 Source/Indicators/FlickeringDotsIndicatorView.swift create mode 100644 Source/Indicators/GradientIndicatorView.swift create mode 100644 Source/Indicators/GrowingArcIndicatorView.swift create mode 100644 Source/Indicators/GrowingCircleIndicatorView.swift create mode 100644 Source/Indicators/OpacityDotsIndicatorView.swift create mode 100644 Source/Indicators/RotatingDotsIndicatorView.swift create mode 100644 Source/Indicators/ScalingDotsIndicatorView.swift diff --git a/ActivityIndicatorView.podspec b/ActivityIndicatorView.podspec index 8e9da88..7fab38a 100644 --- a/ActivityIndicatorView.podspec +++ b/ActivityIndicatorView.podspec @@ -19,6 +19,7 @@ Pod::Spec.new do |s| s.source_files = [ 'Source/*.h', - 'Source/*.swift' + 'Source/*.swift', + 'Source/Indicators/*.swift' ] end diff --git a/ActivityIndicatorView.xcodeproj/project.pbxproj b/ActivityIndicatorView.xcodeproj/project.pbxproj index 639ac7a..71809c5 100644 --- a/ActivityIndicatorView.xcodeproj/project.pbxproj +++ b/ActivityIndicatorView.xcodeproj/project.pbxproj @@ -9,6 +9,16 @@ /* Begin PBXBuildFile section */ 5B56E7DB2428A1D900A5AF97 /* ActivityIndicatorView.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B56E7D82428A1D900A5AF97 /* ActivityIndicatorView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5B56E7DC2428A1D900A5AF97 /* ActivityIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B56E7D92428A1D900A5AF97 /* ActivityIndicatorView.swift */; }; + A7423F46252DC96E000D014D /* GrowingArcIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F45252DC96E000D014D /* GrowingArcIndicatorView.swift */; }; + A7423F5B252DCD76000D014D /* DefaultIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F5A252DCD76000D014D /* DefaultIndicatorView.swift */; }; + A7423F63252DD0D8000D014D /* ArcsIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F62252DD0D8000D014D /* ArcsIndicatorView.swift */; }; + A7423F6B252DD2F5000D014D /* RotatingDotsIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F6A252DD2F5000D014D /* RotatingDotsIndicatorView.swift */; }; + A7423F71252DD554000D014D /* FlickeringDotsIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F70252DD554000D014D /* FlickeringDotsIndicatorView.swift */; }; + A7423F7C252DD872000D014D /* ScalingDotsIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F7B252DD872000D014D /* ScalingDotsIndicatorView.swift */; }; + A7423F83252DDC15000D014D /* OpacityDotsIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F82252DDC15000D014D /* OpacityDotsIndicatorView.swift */; }; + A7423F89252DDD67000D014D /* EqualizerIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F88252DDD67000D014D /* EqualizerIndicatorView.swift */; }; + A7423F8F252DDF18000D014D /* GrowingCircleIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F8E252DDF18000D014D /* GrowingCircleIndicatorView.swift */; }; + A7423F95252DDFD4000D014D /* GradientIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7423F94252DDFD4000D014D /* GradientIndicatorView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -16,6 +26,16 @@ 5B56E7D92428A1D900A5AF97 /* ActivityIndicatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivityIndicatorView.swift; sourceTree = ""; }; 5B56E7DA2428A1D900A5AF97 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5BA1FA342424A5CE00EE4184 /* ActivityIndicatorView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ActivityIndicatorView.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + A7423F45252DC96E000D014D /* GrowingArcIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GrowingArcIndicatorView.swift; sourceTree = ""; }; + A7423F5A252DCD76000D014D /* DefaultIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultIndicatorView.swift; sourceTree = ""; }; + A7423F62252DD0D8000D014D /* ArcsIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArcsIndicatorView.swift; sourceTree = ""; }; + A7423F6A252DD2F5000D014D /* RotatingDotsIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RotatingDotsIndicatorView.swift; sourceTree = ""; }; + A7423F70252DD554000D014D /* FlickeringDotsIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlickeringDotsIndicatorView.swift; sourceTree = ""; }; + A7423F7B252DD872000D014D /* ScalingDotsIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScalingDotsIndicatorView.swift; sourceTree = ""; }; + A7423F82252DDC15000D014D /* OpacityDotsIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpacityDotsIndicatorView.swift; sourceTree = ""; }; + A7423F88252DDD67000D014D /* EqualizerIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EqualizerIndicatorView.swift; sourceTree = ""; }; + A7423F8E252DDF18000D014D /* GrowingCircleIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GrowingCircleIndicatorView.swift; sourceTree = ""; }; + A7423F94252DDFD4000D014D /* GradientIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientIndicatorView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -32,6 +52,7 @@ 5B56E7D72428A1D900A5AF97 /* Source */ = { isa = PBXGroup; children = ( + A7423F77252DD82F000D014D /* Indicators */, 5B56E7D82428A1D900A5AF97 /* ActivityIndicatorView.h */, 5B56E7D92428A1D900A5AF97 /* ActivityIndicatorView.swift */, 5B56E7DA2428A1D900A5AF97 /* Info.plist */, @@ -55,6 +76,23 @@ name = Products; sourceTree = ""; }; + A7423F77252DD82F000D014D /* Indicators */ = { + isa = PBXGroup; + children = ( + A7423F62252DD0D8000D014D /* ArcsIndicatorView.swift */, + A7423F5A252DCD76000D014D /* DefaultIndicatorView.swift */, + A7423F45252DC96E000D014D /* GrowingArcIndicatorView.swift */, + A7423F6A252DD2F5000D014D /* RotatingDotsIndicatorView.swift */, + A7423F70252DD554000D014D /* FlickeringDotsIndicatorView.swift */, + A7423F7B252DD872000D014D /* ScalingDotsIndicatorView.swift */, + A7423F82252DDC15000D014D /* OpacityDotsIndicatorView.swift */, + A7423F88252DDD67000D014D /* EqualizerIndicatorView.swift */, + A7423F8E252DDF18000D014D /* GrowingCircleIndicatorView.swift */, + A7423F94252DDFD4000D014D /* GradientIndicatorView.swift */, + ); + path = Indicators; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -135,7 +173,17 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A7423F6B252DD2F5000D014D /* RotatingDotsIndicatorView.swift in Sources */, + A7423F63252DD0D8000D014D /* ArcsIndicatorView.swift in Sources */, + A7423F95252DDFD4000D014D /* GradientIndicatorView.swift in Sources */, + A7423F8F252DDF18000D014D /* GrowingCircleIndicatorView.swift in Sources */, + A7423F89252DDD67000D014D /* EqualizerIndicatorView.swift in Sources */, 5B56E7DC2428A1D900A5AF97 /* ActivityIndicatorView.swift in Sources */, + A7423F7C252DD872000D014D /* ScalingDotsIndicatorView.swift in Sources */, + A7423F83252DDC15000D014D /* OpacityDotsIndicatorView.swift in Sources */, + A7423F46252DC96E000D014D /* GrowingArcIndicatorView.swift in Sources */, + A7423F71252DD554000D014D /* FlickeringDotsIndicatorView.swift in Sources */, + A7423F5B252DCD76000D014D /* DefaultIndicatorView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/Indicators/ArcsIndicatorView.swift b/Source/Indicators/ArcsIndicatorView.swift new file mode 100644 index 0000000..b5fc8e3 --- /dev/null +++ b/Source/Indicators/ArcsIndicatorView.swift @@ -0,0 +1,55 @@ +// +// ArcsIndicatorView.swift +// ActivityIndicatorView +// +// Created by Daniil Manin on 10/7/20. +// Copyright © 2020 Exyte. All rights reserved. +// + +import SwiftUI + +struct ArcsIndicatorView: View { + + private let count: Int = 3 + + var body: some View { + GeometryReader { geometry in + ForEach(0.. Path in + var p = Path() + p.addArc(center: CGPoint(x: size.width / 2, y: size.height / 2), + radius: size.width / 2 - CGFloat(index) * CGFloat(count), + startAngle: .degrees(0), + endAngle: .degrees(Double(Int.random(in: 120...300))), + clockwise: true) + return p.strokedPath(.init(lineWidth: 2)) + } + .frame(width: size.width, height: size.height) + .rotationEffect(.degrees(rotation)) + .onAppear { + rotation = 0 + withAnimation(animation) { + rotation = 360 + } + } + } +} diff --git a/Source/Indicators/DefaultIndicatorView.swift b/Source/Indicators/DefaultIndicatorView.swift new file mode 100644 index 0000000..9ee447b --- /dev/null +++ b/Source/Indicators/DefaultIndicatorView.swift @@ -0,0 +1,55 @@ +// +// DefaultIndicatorView.swift +// ActivityIndicatorView +// +// Created by Daniil Manin on 10/7/20. +// Copyright © 2020 Exyte. All rights reserved. +// + +import SwiftUI + +struct DefaultIndicatorView: View { + + private let count: Int = 8 + + public var body: some View { + GeometryReader { geometry in + ForEach(0.. Path { + + let h = p * 2 + var length = h * maxLength + if h > 1 && h < lag + 1 { + length = maxLength + } + if h > lag + 1 { + let coeff = 1 / (1 - lag) + let n = h - 1 - lag + length = (1 - n * coeff) * maxLength + } + + let first = Double.pi / 2 + let second = 4 * Double.pi - first + + var end = h * first + if h > 1 { + end = first + (h - 1) * second + } + + let start = end + length + + var p = Path() + p.addArc(center: CGPoint(x: rect.size.width/2, y: rect.size.width/2), + radius: rect.size.width/2, + startAngle: Angle(radians: start), + endAngle: Angle(radians: end), + clockwise: true) + return p + } +} diff --git a/Source/Indicators/GrowingCircleIndicatorView.swift b/Source/Indicators/GrowingCircleIndicatorView.swift new file mode 100644 index 0000000..204a95d --- /dev/null +++ b/Source/Indicators/GrowingCircleIndicatorView.swift @@ -0,0 +1,33 @@ +// +// GrowingCircleIndicatorView.swift +// ActivityIndicatorView +// +// Created by Daniil Manin on 10/7/20. +// Copyright © 2020 Exyte. All rights reserved. +// + +import SwiftUI + +struct GrowingCircleIndicatorView: View { + + @State private var scale: CGFloat = 0 + @State private var opacity: Double = 0 + + var body: some View { + let animation = Animation + .easeIn(duration: 1.1) + .repeatForever(autoreverses: false) + + return Circle() + .scaleEffect(scale) + .opacity(opacity) + .onAppear { + scale = 0 + opacity = 1 + withAnimation(animation) { + scale = 1 + opacity = 0 + } + } + } +} diff --git a/Source/Indicators/OpacityDotsIndicatorView.swift b/Source/Indicators/OpacityDotsIndicatorView.swift new file mode 100644 index 0000000..12e868e --- /dev/null +++ b/Source/Indicators/OpacityDotsIndicatorView.swift @@ -0,0 +1,56 @@ +// +// OpacityDotsIndicatorView.swift +// ActivityIndicatorView +// +// Created by Daniil Manin on 10/7/20. +// Copyright © 2020 Exyte. All rights reserved. +// + +import SwiftUI + +struct OpacityDotsIndicatorView: View { + + private let count: Int = 3 + private let inset: Int = 4 + + var body: some View { + GeometryReader { geometry in + ForEach(0..