HUDView.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. import PreviewSnapshots
  25. struct HUDView: View {
  26. @Binding var showHUD: Bool
  27. @State var textLabel: String
  28. @State var image: String
  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)
  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. func makeUIView(context: Context) -> UIVisualEffectView {
  50. let effectView = UIVisualEffectView(effect: UIBlurEffect(style: style))
  51. effectView.backgroundColor = NCBrandColor.shared.brand
  52. return effectView
  53. }
  54. func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
  55. uiView.effect = UIBlurEffect(style: style)
  56. }
  57. }
  58. struct ContentView: View {
  59. @State private var showHUD = false
  60. @Namespace var hudAnimation
  61. func dismissHUDAfterTime() {
  62. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  63. self.showHUD = false
  64. }
  65. }
  66. var body: some View {
  67. GeometryReader { geo in
  68. ZStack(alignment: .top) {
  69. NavigationView {
  70. Button("Save image") {
  71. self.showHUD.toggle()
  72. }
  73. .navigationTitle("Content View")
  74. }
  75. HUDView(showHUD: $showHUD, textLabel: NSLocalizedString("_wait_", comment: ""), image: "doc.badge.arrow.up")
  76. .offset(y: showHUD ? (geo.size.height / 2) : -200)
  77. .animation(.easeOut)
  78. }
  79. }
  80. }
  81. }
  82. struct HUDView_Previews: PreviewProvider {
  83. static var previews: some View {
  84. snapshots.previews.previewLayout(.sizeThatFits)
  85. }
  86. static var snapshots: PreviewSnapshots<String> {
  87. PreviewSnapshots(
  88. configurations: [
  89. .init(name: NCGlobal.shared.defaultSnapshotConfiguration, state: "")
  90. ],
  91. configure: { _ in
  92. ContentView().frameForPreview()
  93. })
  94. }
  95. }