another.im-ios/old/View/UIToolkit/View+Loader.swift
2024-08-11 13:09:29 +02:00

41 lines
1.1 KiB
Swift

import Foundation
import SwiftUI
public extension View {
func loadingIndicator(_ isShowing: Bool) -> some View {
modifier(LoadingIndicator(isShowing: isShowing))
}
}
struct LoadingIndicator: ViewModifier {
var isShowing: Bool
func body(content: Content) -> some View {
ZStack {
content
if isShowing {
loadingView
}
}
}
private var loadingView: some View {
GeometryReader { proxyReader in
ZStack {
Color.Material.Elements.active.opacity(0.3)
.frame(maxWidth: .infinity, maxHeight: .infinity)
// loader
ProgressView()
.progressViewStyle(
CircularProgressViewStyle(tint: .Material.Elements.active)
)
.position(x: proxyReader.size.width / 2, y: proxyReader.size.height / 2)
.controlSize(.large)
}
}
.ignoresSafeArea()
.transition(AnyTransition.opacity.animation(.easeInOut(duration: 0.1)))
}
}