@@ -32,11 +32,8 @@ struct LoginScreen: View {
32
32
@StateObject private var viewModel : LoginViewModal
33
33
@State public var theme : AppTheme = appThemes [ UserDefaults . standard. integer ( forKey: " Theme " ) ]
34
34
@State private var loginInfo = LoginConstant . login
35
- @State private var selectedTabIndex : String = " chats " {
36
- didSet {
37
- dialogsPresented = selectedTabIndex == " chats "
38
- }
39
- }
35
+ @State private var selectedTabIndex : QuickBloxUIKit . TabIndex = . dialogs
36
+
40
37
@State private var tabBarVisibility : Visibility = . visible
41
38
@State private var dialogsPresented : Bool = false
42
39
@@ -48,6 +45,9 @@ struct LoginScreen: View {
48
45
_viewModel = StateObject ( wrappedValue: viewModel)
49
46
viewModel. authState = QBSession . current. currentUser != nil
50
47
? AuthState . authorized : AuthState . unAuthorized
48
+ if openWithTabBar == false {
49
+ tabBarVisibility = . hidden
50
+ }
51
51
setupFeatures ( )
52
52
}
53
53
@@ -63,7 +63,14 @@ struct LoginScreen: View {
63
63
QuickBloxUIKit . dialogsView ( onExit: {
64
64
// Handling an event when exiting the QuickBloxUIKit e.g. disconnect and logout
65
65
viewModel. disconnect ( )
66
+ } , onSelect: { tabIndex in
67
+ selectedTabIndex = tabIndex
66
68
} )
69
+ . onAppear {
70
+ tabBarVisibility = . hidden
71
+ theme = appThemes [ UserDefaults . standard. integer ( forKey: " Theme " ) ]
72
+ setupSettings ( )
73
+ }
67
74
} )
68
75
}
69
76
@@ -73,46 +80,59 @@ struct LoginScreen: View {
73
80
case . unAuthorized, . authorization:
74
81
authView ( )
75
82
case . authorized:
76
-
77
- TabView ( selection: $selectedTabIndex) {
78
-
79
- QuickBloxUIKit . dialogsView ( onAppear: { appear in
80
- if selectedTabIndex == " chats " {
81
- tabBarVisibility = appear == true ? Visibility . visible : Visibility . hidden
82
- }
83
- } )
84
- . toolbar ( tabBarVisibility, for: . tabBar)
85
- . toolbarBackground ( theme. color. mainBackground, for: . tabBar)
86
- . toolbarBackground ( tabBarVisibility, for: . tabBar)
87
- . tag ( " chats " )
88
- . tabItem {
89
- Label ( " Chats " , systemImage: " bubble.left.and.bubble.right.fill " )
90
- }
91
-
92
- settingsView ( )
93
- . tabItem {
94
- Label ( " Settings " , systemImage: " gearshape " )
95
- } . tag ( " settings " )
96
-
97
- disconnectView ( )
83
+ if openWithTabBar == true {
84
+ TabView ( selection: $selectedTabIndex) {
85
+ QuickBloxUIKit . dialogsView ( onSelect: { tabIndex in
86
+ if tabIndex != . dialogs {
87
+ selectedTabIndex = tabIndex
88
+ }
89
+ } )
90
+ . toolbar ( tabBarVisibility, for: . tabBar)
91
+ . toolbarBackground ( theme. color. mainBackground, for: . tabBar)
92
+ . toolbarBackground ( tabBarVisibility, for: . tabBar)
93
+ . tag ( TabIndex . dialogs)
98
94
. tabItem {
99
- Label ( viewModel. authState == . unAuthorized ? " Enter " : " Exit " ,
100
- systemImage: viewModel. authState == . unAuthorized
101
- ? " figure.walk.arrival " : " figure.walk.departure " )
102
- } . tag ( " auth " )
103
-
104
- . onChange ( of: viewModel. authState) { authState in
105
- self . selectedTabIndex = authState == . authorized ? " chats " : " auth "
95
+ Label ( TabIndex . dialogs. title, systemImage: TabIndex . dialogs. systemIcon)
106
96
}
107
- }
108
- . accentColor ( theme. color. mainElements)
109
- . onAppear {
110
- selectedTabIndex = QBSession . current. currentUser != nil ? " chats " : " auth "
111
- viewModel. authState = QBSession . current. currentUser != nil
112
- ? AuthState . authorized : AuthState . unAuthorized
113
- theme = appThemes [ UserDefaults . standard. integer ( forKey: " Theme " ) ]
114
- setupSettings ( )
115
- tabBarVisibility = . visible
97
+ . onAppear {
98
+ theme = appThemes [ UserDefaults . standard. integer ( forKey: " Theme " ) ]
99
+ setupSettings ( )
100
+ tabBarVisibility = selectedTabIndex != . dialogs ? . visible : . hidden
101
+ }
102
+
103
+ settingsView ( )
104
+ . toolbar ( tabBarVisibility, for: . tabBar)
105
+ . toolbarBackground ( theme. color. mainBackground, for: . tabBar)
106
+ . toolbarBackground ( tabBarVisibility, for: . tabBar)
107
+ . tabItem {
108
+ Label ( TabIndex . settings. title, systemImage: TabIndex . settings. systemIcon)
109
+ }
110
+ . tag ( TabIndex . settings)
111
+
112
+ disconnectView ( )
113
+ . toolbar ( tabBarVisibility, for: . tabBar)
114
+ . toolbarBackground ( theme. color. mainBackground, for: . tabBar)
115
+ . toolbarBackground ( tabBarVisibility, for: . tabBar)
116
+ . tabItem {
117
+ Label ( viewModel. authState == . unAuthorized ? TabIndex . enter. title : TabIndex . exit. title,
118
+ systemImage: viewModel. authState == . unAuthorized
119
+ ? TabIndex . enter. systemIcon : TabIndex . exit. systemIcon)
120
+ }
121
+ . tag ( TabIndex . exit)
122
+
123
+ . onChange ( of: viewModel. authState) { authState in
124
+ self . selectedTabIndex = authState == . authorized ? TabIndex . dialogs : TabIndex . exit
125
+ }
126
+ }
127
+ . accentColor ( theme. color. mainElements)
128
+ . onAppear {
129
+ selectedTabIndex = QBSession . current. currentUser != nil ? TabIndex . dialogs : TabIndex . exit
130
+ viewModel. authState = QBSession . current. currentUser != nil
131
+ ? AuthState . authorized : AuthState . unAuthorized
132
+ theme = appThemes [ UserDefaults . standard. integer ( forKey: " Theme " ) ]
133
+ setupSettings ( )
134
+ tabBarVisibility = . visible
135
+ }
116
136
}
117
137
}
118
138
}
@@ -137,7 +157,7 @@ struct LoginScreen: View {
137
157
138
158
@ViewBuilder
139
159
private func authView( ) -> some View {
140
- NavigationView {
160
+ NavigationStack {
141
161
ZStack {
142
162
theme. color. mainBackground. ignoresSafeArea ( )
143
163
if viewModel. isSignUped {
@@ -177,8 +197,8 @@ struct LoginScreen: View {
177
197
isValidForm: $viewModel. isSignUpValidForm,
178
198
onTapped: {
179
199
viewModel. signUp ( withLogin: viewModel. login,
180
- displayName: viewModel. displayName,
181
- password: viewModel. password)
200
+ displayName: viewModel. displayName,
201
+ password: viewModel. password)
182
202
} , theme: theme)
183
203
184
204
. onChange ( of: viewModel. authState) { authState in
@@ -224,7 +244,7 @@ struct LoginScreen: View {
224
244
isValidForm: $viewModel. isLoginValidForm,
225
245
onTapped: {
226
246
viewModel. login ( withLogin: viewModel. login,
227
- password: viewModel. password)
247
+ password: viewModel. password)
228
248
} , theme: theme)
229
249
230
250
. onChange ( of: viewModel. authState) { authState in
@@ -299,13 +319,17 @@ struct LoginScreen: View {
299
319
// Setup Background Image for Dialog Screen
300
320
QuickBloxUIKit . settings. dialogScreen. backgroundImage = Image ( " dialogBackground " )
301
321
QuickBloxUIKit . settings. dialogScreen. backgroundImageColor = theme. color. divider
322
+ if openWithTabBar {
323
+ QuickBloxUIKit . settings. dialogsScreen. tabIndex. externalIndexes = [ . settings, . exit]
324
+ }
302
325
}
303
326
304
327
private func setupFeatures( ) {
305
328
QuickBloxUIKit . feature. ai. apiKey = " "
306
329
QuickBloxUIKit . feature. ai. ui = AIUISettings ( theme)
307
330
QuickBloxUIKit . feature. forward. enable = true
308
331
QuickBloxUIKit . feature. reply. enable = true
332
+ QuickBloxUIKit . feature. toolbar. enable = openWithTabBar
309
333
}
310
334
}
311
335
@@ -318,3 +342,10 @@ struct LoginScreen_Previews: PreviewProvider {
318
342
}
319
343
}
320
344
}
345
+
346
+ public extension TabIndex {
347
+ static let exit = TabIndex ( title: " Exit " ,
348
+ systemIcon: " figure.walk.departure " )
349
+ static let enter = TabIndex ( title: " Enter " ,
350
+ systemIcon: " figure.walk.arrival " )
351
+ }
0 commit comments