commit 9f7b1e5e1018b8d9742b0c7ad8c55fe2245dd013
parent 42d0f2712016cafa7931f22bdc6fb9881fe79c94
Author: Marc Stibane <marc@taler.net>
Date: Sun, 10 Sep 2023 13:31:16 +0200
Speed up Sidebar
Diffstat:
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift
@@ -71,7 +71,9 @@ extension MainView {
@Binding var talerFont: Int
@State var sidebarVisible: Bool = false
func hamburgerAction() {
- sidebarVisible = !sidebarVisible
+ withAnimation(.easeInOut(duration: 0.25)) {
+ sidebarVisible = !sidebarVisible
+ }
}
let balances = String(localized: "Balances")
@@ -108,13 +110,24 @@ extension MainView {
.id(views[currentView].name)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.transition(.backslide)
- }
+ } .id(talerFont)
.navigationBarTitleDisplayMode(.automatic)
- }.navigationViewStyle(.stack)
- // The side view is on top of the current view
+ .background(NavigationBarBuilder { navigationController in
+ // navigationController.navigationBar.barTintColor = .red
+ navigationController.navigationBar.titleTextAttributes =
+ [.font: TalerFont.talerFont(talerFont, size: 24, relativeTo: .title2)]
+ navigationController.navigationBar.largeTitleTextAttributes =
+ [.font: TalerFont.talerFont(talerFont, size: 38, relativeTo: .largeTitle)]
+ })
+ }
+ .navigationViewStyle(.stack)
+ .talerNavBar(talerFont: talerFont)
+
+ // The side view is above (Z-Axis) the current view
SideBarView(views: views,
currentView: $currentView,
- sidebarVisible: $sidebarVisible)
+ sidebarVisible: sidebarVisible,
+ hamburgerAction: hamburgerAction)
}
}
} // Content
diff --git a/TalerWallet1/Views/Main/SideBarView.swift b/TalerWallet1/Views/Main/SideBarView.swift
@@ -17,7 +17,8 @@ struct SideBarView: View {
private let symLog = SymLogV(0)
let views: [SidebarItem]
@Binding var currentView: Int
- @Binding var sidebarVisible: Bool
+ let sidebarVisible: Bool
+ let hamburgerAction: () -> Void
@State private var rotationEnabled = false
var body: some View {
@@ -35,8 +36,8 @@ struct SideBarView: View {
ForEach(0..<views.count, id: \.self) { i in
Button {
symLog.log("sidebar item \"\(views[i].name)\" selected")
- sidebarVisible = false // slide sidebar to the left
- withAnimation(.easeInOut) {currentView = i} // switch to the view the user selected
+ hamburgerAction() // slide sidebar to the left
+ withAnimation(.easeInOut(duration: 0.3)) {currentView = i} // animate to the view the user selected
} label: {
if let sysImage = views[i].sysImage {
Label(views[i].name, systemImage: sysImage)
@@ -68,11 +69,9 @@ struct SideBarView: View {
.offset(x: sidebarVisible ? sidebarWidth : 0)
.contentShape(Rectangle())
.onTapGesture {
- sidebarVisible = false
+ hamburgerAction() // slide sidebar to the left
}
}
- .animation(.linear //(duration: SLIDEDURATION)
- , value: sidebarVisible)
}
}
// MARK: -
@@ -86,7 +85,9 @@ fileprivate struct BindingViewContainer : View {
ZStack(alignment: .leading) {
views[currentView].view
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
- SideBarView(views: views, currentView: $currentView, sidebarVisible: $sidebarVisible)
+ SideBarView(views: views, currentView: $currentView,
+ sidebarVisible: sidebarVisible,
+ hamburgerAction: { sidebarVisible = !sidebarVisible })
}
}
}