Skip to content

Commit 1684e78

Browse files
Merge pull request #4 from SimformSolutionsPvtLtd/feature/update-example-project
Add configuration properties to home view
2 parents 1abe7de + e20b7a4 commit 1684e78

File tree

2 files changed

+112
-15
lines changed

2 files changed

+112
-15
lines changed

Example/SSSwiftUISideMenuDemo/Container Views/Home.swift

Lines changed: 108 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,122 @@
66
//
77

88
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+
}
920

1021
struct Home: View {
1122

23+
// MARK: - Properties
24+
25+
// Binding to control the presentation of the side menu
1226
@Binding var presentSideMenu: Bool
1327

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+
1456
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+
}
23120
}
24-
Spacer()
121+
.padding(.horizontal, -20)
122+
.listRowInsets(EdgeInsets())
25123
}
26-
27-
Spacer()
28-
Text("Home")
29-
Spacer()
124+
.navigationBarTitle("SSSwiftUI SideMenu", displayMode: .inline)
30125
}
31126
.padding(.horizontal, 24)
32127
}

Example/SSSwiftUISideMenuDemo/ContentView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ struct ContentView: View {
1616

1717
@State private var selectedIndex: Int = 0
1818

19+
@State private var menuConfig = SSMenuConfig()
20+
1921
private var menuItems = [
2022
MenuItem(title: "Home", icon: "home"),
2123
MenuItem(title: "My Friends", icon: "friends"),
@@ -28,7 +30,7 @@ struct ContentView: View {
2830

2931
TabView(selection: $selectedIndex) {
3032

31-
Home(presentSideMenu: $openSideMenu)
33+
Home(presentSideMenu: $openSideMenu, objMenuConfig: $menuConfig)
3234
.tag(0)
3335

3436
MyFriends(presentSideMenu: $openSideMenu)
@@ -38,7 +40,7 @@ struct ContentView: View {
3840
.tag(2)
3941
}
4042

41-
SSSwiftUISideMenu(openSideMenu: $openSideMenu, selectedIndex: $selectedIndex, menuItems: menuItems)
43+
SSSwiftUISideMenu(openSideMenu: $openSideMenu, selectedIndex: $selectedIndex, menuItems: menuItems, menuConfig: menuConfig)
4244
}
4345
}
4446
}

0 commit comments

Comments
 (0)