1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import SwiftUI
- struct HUDView: View {
- @Binding var showHUD: Bool
- @State var textLabel: String
- @State var image: String
- var body: some View {
- Button(action: {
- withAnimation {
- self.showHUD = false
- }
- }) {
- Label(textLabel, systemImage: image)
- .foregroundColor(.white)
- .padding(.horizontal, 10)
- .padding(14)
- .background(
- Blur(style: .regular)
- .clipShape(Capsule())
- .shadow(color: Color(.black).opacity(0.22), radius: 12, x: 0, y: 5)
- )
- }.buttonStyle(PlainButtonStyle())
- }
- }
- struct Blur: UIViewRepresentable {
- var style: UIBlurEffect.Style
- func makeUIView(context: Context) -> UIVisualEffectView {
- let effectView = UIVisualEffectView(effect: UIBlurEffect(style: style))
- effectView.backgroundColor = NCBrandColor.shared.brand
- return effectView
- }
- func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
- uiView.effect = UIBlurEffect(style: style)
- }
- }
- struct ContentView: View {
- @State private var showHUD = false
- @Namespace var hudAnimation
- func dismissHUDAfterTime() {
- DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
- self.showHUD = false
- }
- }
- var body: some View {
- GeometryReader { geo in
- ZStack(alignment: .top) {
- NavigationView {
- Button("Save image") {
- self.showHUD.toggle()
- }
- .navigationTitle("Content View")
- }
- HUDView(showHUD: $showHUD, textLabel: NSLocalizedString("_wait_", comment: ""), image: "doc.badge.arrow.up")
- .offset(y: showHUD ? (geo.size.height / 2) : -200)
- .animation(.easeOut)
- }
- }
- }
- }
- struct HUDView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
|