-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ScaleableWaitingIndicator control as an animated resizable indication that the app is waiting on a task to finish.
- Loading branch information
1 parent
b5533d5
commit 92de0ba
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
59 changes: 59 additions & 0 deletions
59
Sources/SwiftUIKit/Components/ScaleableWaitingIndicator.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// GamepadWaitingIndicator.swift | ||
// ReedWriteCycle (iOS) | ||
// | ||
// Created by Kevin Mullins on 11/16/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// A View that displays an animated waiting indicator that can be scaled to any size desired. | ||
public struct ScaleableWaitingIndicator: View { | ||
|
||
// MARK: - Properties | ||
/// The `StrokeStyle` of the control. | ||
public var style = StrokeStyle (lineWidth: 6, lineCap: .round) | ||
|
||
/// The color of the control. | ||
public var color = Color.white | ||
|
||
/// If `true` the control is animated. | ||
@State public var animate = false | ||
|
||
// MARK: - Initializers | ||
/// Creates a new instance. | ||
/// - Parameters: | ||
/// - style: The `StrokeStyle` of the control. | ||
/// - color: The color of the control. | ||
public init(style: StrokeStyle = StrokeStyle (lineWidth: 6, lineCap: .round), color: SwiftUI.Color = Color.white) { | ||
self.style = style | ||
self.color = color | ||
} | ||
|
||
// MARK: - Control Body | ||
/// The body of the control. | ||
public var body: some View { | ||
ZStack { | ||
Circle() | ||
.trim(from: 0, to: 0.2) | ||
.stroke (AngularGradient(gradient: .init(colors: [color]), center: .center), | ||
style: style) | ||
.rotationEffect(Angle(degrees: animate ? 360 : 8)) | ||
.animation(Animation.linear(duration: 0.7).repeatForever(autoreverses: false), value: animate) | ||
Circle() | ||
.trim(from: 0.5, to: 0.7) | ||
.stroke (AngularGradient(gradient: .init(colors: [color]), center: .center), | ||
style: style) | ||
. rotationEffect (Angle (degrees: animate ? 368: 0)) | ||
.animation(Animation.linear(duration: 0.7).repeatForever(autoreverses: false), value: animate) | ||
}.onAppear () { | ||
self.animate.toggle() | ||
} | ||
} | ||
|
||
} | ||
|
||
#Preview { | ||
ScaleableWaitingIndicator() | ||
.background(Color.black) | ||
} |
This file contains 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