HUDView.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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(.white)
  36. .padding(.horizontal, 10)
  37. .padding(14)
  38. .background(
  39. Blur(style: .regular)
  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. let effectView = UIVisualEffectView(effect: UIBlurEffect(style: style))
  50. effectView.backgroundColor = NCBrandColor.shared.brand
  51. return effectView
  52. }
  53. func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
  54. uiView.effect = UIBlurEffect(style: style)
  55. }
  56. }
  57. struct ContentView: View {
  58. @State private var showHUD = false
  59. @Namespace var hudAnimation
  60. func dismissHUDAfterTime() {
  61. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  62. self.showHUD = false
  63. }
  64. }
  65. var body: some View {
  66. GeometryReader { geo in
  67. ZStack(alignment: .top) {
  68. NavigationView {
  69. Button("Save image") {
  70. self.showHUD.toggle()
  71. }
  72. .navigationTitle("Content View")
  73. }
  74. HUDView(showHUD: $showHUD, textLabel: NSLocalizedString("_wait_", comment: ""), image: "doc.badge.arrow.up")
  75. .offset(y: showHUD ? (geo.size.height / 2) : -200)
  76. .animation(.easeOut)
  77. }
  78. }
  79. }
  80. }
  81. struct HUDView_Previews: PreviewProvider {
  82. static var previews: some View {
  83. ContentView()
  84. }
  85. }