HUDView.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // HUDView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 02/01/23.
  6. // Copyright © 2023 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import SwiftUI
  24. struct HUDView: View {
  25. @Binding var showHUD: Bool
  26. @State var textLabel: String
  27. @State var image: String
  28. var body: some View {
  29. Button(action: {
  30. withAnimation {
  31. self.showHUD = false
  32. }
  33. }) {
  34. Label(textLabel, systemImage: image)
  35. .foregroundColor(.gray)
  36. .padding(.horizontal, 10)
  37. .padding(14)
  38. .background(
  39. Blur(style: .systemMaterial)
  40. .clipShape(Capsule())
  41. .shadow(color: Color(.black).opacity(0.22), radius: 12, x: 0, y: 5)
  42. )
  43. }.buttonStyle(PlainButtonStyle())
  44. }
  45. }
  46. struct Blur: UIViewRepresentable {
  47. var style: UIBlurEffect.Style
  48. func makeUIView(context: Context) -> UIVisualEffectView {
  49. return UIVisualEffectView(effect: UIBlurEffect(style: style))
  50. }
  51. func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
  52. uiView.effect = UIBlurEffect(style: style)
  53. }
  54. }
  55. struct ContentView: View {
  56. @State private var showHUD = false
  57. @Namespace var hudAnimation
  58. func dismissHUDAfterTime() {
  59. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  60. self.showHUD = false
  61. }
  62. }
  63. var body: some View {
  64. GeometryReader { geo in
  65. ZStack(alignment: .top) {
  66. NavigationView {
  67. Button("Save image") {
  68. self.showHUD.toggle()
  69. }
  70. .navigationTitle("Content View")
  71. }
  72. HUDView(showHUD: $showHUD, textLabel: NSLocalizedString("_wait_", comment: ""), image: "doc.badge.arrow.up")
  73. .offset(y: showHUD ? (geo.size.height / 2) : -200)
  74. .animation(.easeOut)
  75. }
  76. }
  77. }
  78. }
  79. struct HUDView_Previews: PreviewProvider {
  80. static var previews: some View {
  81. ContentView()
  82. }
  83. }