switcher account animation

This commit is contained in:
cheykrym 2025-08-14 03:48:28 +03:00
parent 82168755e2
commit 27a6ce7ce3

View File

@ -1,5 +1,7 @@
import SwiftUI
// --- HELPER STRUCTS & EXTENSIONS ---
// Dummy data for the account list
struct Account: Identifiable {
let id = UUID()
@ -8,6 +10,57 @@ struct Account: Identifiable {
let isCurrent: Bool
}
// Custom Transition for older Xcode versions
extension AnyTransition {
static var slideAndFade: AnyTransition {
let insertion = AnyTransition.move(edge: .top).combined(with: .opacity)
let removal = AnyTransition.move(edge: .top).combined(with: .opacity)
return .asymmetric(insertion: insertion, removal: removal)
}
}
// Helper Views for buttons
struct SideMenuButton: View {
let icon: String
let title: String
let action: () -> Void
var body: some View {
Button(action: action) {
HStack(spacing: 15) {
Image(systemName: icon)
.font(.title3)
.frame(width: 30)
Text(title)
.font(.subheadline)
}
.foregroundColor(.primary)
.padding(.vertical, 8)
}
}
}
struct SideMenuFooterButton: View {
let icon: String
let title: String
let action: () -> Void
var body: some View {
Button(action: action) {
VStack {
Image(systemName: icon)
.font(.title2)
Text(title)
.font(.caption2)
}
.foregroundColor(.primary)
}
}
}
// --- MAIN VIEW ---
struct SideMenuView: View {
@Binding var isPresented: Bool
@State private var isAccountListExpanded = false
@ -66,7 +119,8 @@ struct SideMenuView: View {
.padding(.horizontal, 20)
.padding(.bottom, 10)
// --- Collapsible Account List ---
// --- Collapsible Account List in a clipped container ---
VStack {
if isAccountListExpanded {
VStack(alignment: .leading, spacing: 15) {
ForEach(accounts) { account in
@ -100,7 +154,10 @@ struct SideMenuView: View {
}
.padding(.horizontal, 20)
.padding(.vertical, 10)
.transition(.slideAndFade)
}
}
.clipped()
// Menu Items
VStack(alignment: .leading, spacing: 20) {
@ -143,6 +200,7 @@ struct SideMenuView: View {
}
.frame(maxWidth: .infinity, alignment: .leading) // Align to the left
}
.clipped()
Spacer()
@ -160,42 +218,3 @@ struct SideMenuView: View {
.background(Color(UIColor.systemBackground))
}
}
// Helper Views for buttons
struct SideMenuButton: View {
let icon: String
let title: String
let action: () -> Void
var body: some View {
Button(action: action) {
HStack(spacing: 15) {
Image(systemName: icon)
.font(.title3)
.frame(width: 30)
Text(title)
.font(.subheadline)
}
.foregroundColor(.primary)
.padding(.vertical, 8)
}
}
}
struct SideMenuFooterButton: View {
let icon: String
let title: String
let action: () -> Void
var body: some View {
Button(action: action) {
VStack {
Image(systemName: icon)
.font(.title2)
Text(title)
.font(.caption2)
}
.foregroundColor(.primary)
}
}
}