Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct RefreshButton: View {
- @ObservedObject var model: RefreshButtonModel
- let action: () -> Void
- private let animationDuration = 1.0
- private var foreverAnimation: Animation {
- Animation.linear(duration: self.animationDuration)
- .repeatForever(autoreverses: false)
- }
- private var refreshImage: some View {
- Image(systemName: "arrow.counterclockwise.circle")
- .font(.system(.title))
- }
- private var rotatingRefreshImage: some View {
- refreshImage
- .rotationEffect(.degrees(self.model.isRotating ? 0 : 360))
- .onAppear {
- withAnimation(self.foreverAnimation) {
- self.model.isRotating = true
- }
- }
- }
- var body: some View {
- Button(action: {
- self.model.showRotatingButton = true
- self.action()
- }, label: {
- if self.model.showRotatingButton {
- rotatingRefreshImage
- } else {
- refreshImage
- }
- })
- .frame(width: 44, height: 44)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement