NCHUDView.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 NCHUDView: View {
  25. @Binding var showHUD: Bool
  26. @State var textLabel: String
  27. @State var image: String
  28. @State var color: UIColor
  29. var body: some View {
  30. Button(action: {
  31. withAnimation {
  32. self.showHUD = false
  33. }
  34. }) {
  35. Label(textLabel, systemImage: image)
  36. .foregroundColor(.white)
  37. .padding(.horizontal, 10)
  38. .padding(14)
  39. .background(
  40. Blur(style: .regular, color: color)
  41. .clipShape(Capsule())
  42. .shadow(color: Color(.black).opacity(0.22), radius: 12, x: 0, y: 5)
  43. )
  44. }.buttonStyle(PlainButtonStyle())
  45. }
  46. }
  47. struct Blur: UIViewRepresentable {
  48. var style: UIBlurEffect.Style
  49. var color: UIColor
  50. func makeUIView(context: Context) -> UIVisualEffectView {
  51. let effectView = UIVisualEffectView(effect: UIBlurEffect(style: style))
  52. effectView.backgroundColor = color
  53. return effectView
  54. }
  55. func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
  56. uiView.effect = UIBlurEffect(style: style)
  57. }
  58. }
  59. struct ContentView: View {
  60. @State private var showHUD = false
  61. @State var color: UIColor
  62. @Namespace var hudAnimation
  63. func dismissHUDAfterTime() {
  64. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  65. self.showHUD = false
  66. }
  67. }
  68. var body: some View {
  69. GeometryReader { geo in
  70. ZStack(alignment: .top) {
  71. NavigationView {
  72. Button("Save image") {
  73. self.showHUD.toggle()
  74. }
  75. .navigationTitle("Content View")
  76. }
  77. NCHUDView(showHUD: $showHUD, textLabel: NSLocalizedString("_wait_", comment: ""), image: "doc.badge.arrow.up", color: color)
  78. .offset(y: showHUD ? (geo.size.height / 2) : -200)
  79. .animation(.easeOut, value: showHUD)
  80. }
  81. }
  82. }
  83. }