|
6 | 6 | // |
7 | 7 |
|
8 | 8 | import SwiftUI |
| 9 | +import SSSwiftUISideMenu |
| 10 | + |
| 11 | +enum AnimationType: String, CaseIterable { |
| 12 | + case defaultType = "Default" |
| 13 | + case bouncy = "Bouncy" |
| 14 | + case spring = "Spring" |
| 15 | + case easeIn = "EaseIn" |
| 16 | + case easeOut = "EaseOut" |
| 17 | + case easeInOut = "EaseInOut" |
| 18 | + case linear = "Linear" |
| 19 | +} |
9 | 20 |
|
10 | 21 | struct Home: View { |
11 | 22 |
|
| 23 | + // MARK: - Properties |
| 24 | + |
| 25 | + // Binding to control the presentation of the side menu |
12 | 26 | @Binding var presentSideMenu: Bool |
13 | 27 |
|
| 28 | + // Binding to customise the sidemenu |
| 29 | + @Binding var objMenuConfig: SSMenuConfig |
| 30 | + |
| 31 | + // State variables for various configuration options |
| 32 | + @State private var menuDirection = 0 |
| 33 | + @State private var swipeToClose = true |
| 34 | + @State private var titleColor: Color = .black |
| 35 | + @State private var iconTintColor: Color = .pink |
| 36 | + @State private var backgroundColor: Color = .white |
| 37 | + @State private var selectedTitleColor: Color = .black |
| 38 | + @State private var selectedAnimation: Animation = .default |
| 39 | + @State private var animationType: AnimationType = .defaultType |
| 40 | + |
| 41 | + // Computed property to update viewModel.menuConfig |
| 42 | + var updatedMenuConfig: SSMenuConfig { |
| 43 | + SSMenuConfig( |
| 44 | + iconTintColor: iconTintColor, |
| 45 | + titleColor: titleColor, |
| 46 | + selectedTitleColor: selectedTitleColor, |
| 47 | + backgroundColor: backgroundColor, |
| 48 | + animationType: selectedAnimation, |
| 49 | + menuDirection: menuDirection == 0 ? .left : .right, |
| 50 | + swipeToClose: swipeToClose |
| 51 | + ) |
| 52 | + } |
| 53 | + |
| 54 | + // MARK: - Body |
| 55 | + |
14 | 56 | var body: some View { |
15 | | - VStack{ |
16 | | - HStack{ |
17 | | - Button{ |
18 | | - presentSideMenu.toggle() |
19 | | - } label: { |
20 | | - Image("menu") |
21 | | - .resizable() |
22 | | - .frame(width: 32, height: 32) |
| 57 | + NavigationView { |
| 58 | + VStack { |
| 59 | + HStack { |
| 60 | + // Button to toggle the side menu |
| 61 | + Button { |
| 62 | + objMenuConfig = updatedMenuConfig |
| 63 | + presentSideMenu.toggle() |
| 64 | + } label: { |
| 65 | + Image("menu") |
| 66 | + .resizable() |
| 67 | + .frame(width: 32, height: 32) |
| 68 | + } |
| 69 | + Spacer() |
| 70 | + } |
| 71 | + // Form for configuring menu settings |
| 72 | + Form { |
| 73 | + Section(header: Text("Menu Settings")) { |
| 74 | + // Picker for menu direction |
| 75 | + Picker("Menu direction", selection: $menuDirection) { |
| 76 | + Text("Left").tag(0) |
| 77 | + Text("Right").tag(1) |
| 78 | + } |
| 79 | + .pickerStyle(.menu) |
| 80 | + |
| 81 | + // Toggle for swipe to close menu |
| 82 | + Toggle("Swipe to close menu", isOn: $swipeToClose) |
| 83 | + } |
| 84 | + |
| 85 | + Section(header: Text("Animation Settings")) { |
| 86 | + // Picker for animation type |
| 87 | + Picker("Animation", selection: $animationType) { |
| 88 | + ForEach(AnimationType.allCases, id: \.self) { type in |
| 89 | + Text(type.rawValue).tag(type) |
| 90 | + } |
| 91 | + } |
| 92 | + .pickerStyle(.menu) |
| 93 | + .onChange(of: animationType) { |
| 94 | + switch animationType { |
| 95 | + case .defaultType: |
| 96 | + selectedAnimation = .default |
| 97 | + case .bouncy: |
| 98 | + selectedAnimation = .bouncy |
| 99 | + case .spring: |
| 100 | + selectedAnimation = .spring |
| 101 | + case .easeIn: |
| 102 | + selectedAnimation = .easeIn |
| 103 | + case .easeOut: |
| 104 | + selectedAnimation = .easeOut |
| 105 | + case .easeInOut: |
| 106 | + selectedAnimation = .easeInOut |
| 107 | + case .linear: |
| 108 | + selectedAnimation = .linear |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + Section(header: Text("UI Customisation")) { |
| 114 | + // Color pickers for customizing UI colors |
| 115 | + ColorPicker("Title color", selection: $titleColor) |
| 116 | + ColorPicker("Selected title color", selection: $selectedTitleColor) |
| 117 | + ColorPicker("Background color", selection: $backgroundColor) |
| 118 | + ColorPicker("Icon tint color", selection: $iconTintColor) |
| 119 | + } |
23 | 120 | } |
24 | | - Spacer() |
| 121 | + .padding(.horizontal, -20) |
| 122 | + .listRowInsets(EdgeInsets()) |
25 | 123 | } |
26 | | - |
27 | | - Spacer() |
28 | | - Text("Home") |
29 | | - Spacer() |
| 124 | + .navigationBarTitle("SSSwiftUI SideMenu", displayMode: .inline) |
30 | 125 | } |
31 | 126 | .padding(.horizontal, 24) |
32 | 127 | } |
|
0 commit comments