123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import SwiftUI
- import PreviewSnapshots
- 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 {
- snapshots.previews.previewLayout(.sizeThatFits)
- }
- static var snapshots: PreviewSnapshots<String> {
- PreviewSnapshots(
- configurations: [
- .init(name: NCGlobal.shared.defaultSnapshotConfiguration, state: "")
- ],
- configure: { _ in
- ContentView().frameForPreview()
- })
- }
- }
|