summaryrefslogtreecommitdiff
path: root/TalerWallet1/Views/Sheets/Sheet.swift
blob: 6aa796e8a64c3f4a80bad24cef090539421bb2bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
 * See LICENSE.md
 */
import SwiftUI
import SymLog
import os.log

struct Sheet: View {
    private let symLog = SymLogV(0)
    @Environment(\.dismiss) var dismiss     // call dismiss() to get rid of the sheet
    @EnvironmentObject private var debugViewC: DebugViewC
    @EnvironmentObject private var model: WalletModel
    @AppStorage("talerFontIndex") var talerFontIndex: Int = 0

#if DEBUG
    @AppStorage("developerMode") var developerMode: Bool = true
#else
    @AppStorage("developerMode") var developerMode: Bool = false
#endif

    var sheetView: AnyView

    let logger = Logger(subsystem: "net.taler.gnu", category: "Sheet")

    var cancelButton: some View {
        Button("Cancel") {
            logger.log("Cancel")
            dismissTop()
        }
    }

    var body: some View {
        let idString = debugViewC.sheetID > 0 ? String(debugViewC.sheetID)
                                              : ""      // show nothing if 0
        NavigationView {
            Group {
                if let error2 = model.error2 {
                    ErrorSheet(data: error2, devMode: developerMode) {
                        logger.log("ErrorSheet dismissTop")
                        dismissTop()
                    }
                } else {
                    sheetView
                        .navigationBarItems(leading: cancelButton)
                }
            }
                .navigationBarTitleDisplayMode(.automatic)
                .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
        }
        .navigationViewStyle(.stack)
        .talerNavBar(talerFontIndex: talerFontIndex)
        .overlay(alignment: .top) {
            // Show the viewID on top of the sheet's NavigationView
            Text(idString)
                .foregroundColor(.purple)
                .font(.system(size: 11))        // no talerFont
                .monospacedDigit()
                .edgesIgnoringSafeArea(.top)
                .id("sheetID")
                .accessibilityLabel(Text("Sheet.ID.", comment: "AccessibilityLabel"))
                .accessibilityValue(idString)
        }
        .onDisappear {
            symLog.log("❗️❗️Sheet onDisappear")
        }
    }
}