Skip to content

Commit e31b792

Browse files
Merge pull request #1369 from QuickBlox/Release-UIKit-Sample-1.1.3
Release UIKit-Sample 1.1.3
2 parents eb6578c + 34865a5 commit e31b792

File tree

5 files changed

+89
-47
lines changed

5 files changed

+89
-47
lines changed

sample-ui-kit/UIKitSample/AppTheme/AppTheme.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,13 @@ public class CustomImageTheme: ThemeImageProtocol {
128128

129129
public class CustomThemeString: ThemeStringProtocol {
130130

131+
public var removeItem: String = String(localized: "alert.message.removeItem")
132+
public var settings: String = String(localized: "permission.actions.settings")
133+
public var unknown: String = String(localized: "utils.string.unknown")
131134
public var dialogsEmpty: String = String(localized: "dialog.items.empty")
132135
public var usersEmpty: String = String(localized: "dialog.members.empty")
133136
public var messegesEmpty: String = String(localized: "dialog.messages.empty")
137+
public var selectDialog: String = String(localized: "dialog.info.selectDialog")
134138

135139
public var privateDialog: String = String(localized: "dialog.type.private")
136140
public var groupDialog: String = String(localized: "dialog.type.group")

sample-ui-kit/UIKitSample/Connect.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Connect: ObservableObject {
3333
objectWillChange.send(authState)
3434
}
3535
}
36+
3637
@Published var isConnected: Bool = false
3738

3839
init(state: ConnectState = .disconnected) {

sample-ui-kit/UIKitSample/LoginScreen/LoginScreen.swift

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ struct LoginScreen: View {
3232
@StateObject private var viewModel: LoginViewModal
3333
@State public var theme: AppTheme = appThemes[UserDefaults.standard.integer(forKey: "Theme")]
3434
@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+
4037
@State private var tabBarVisibility: Visibility = .visible
4138
@State private var dialogsPresented: Bool = false
4239

@@ -48,6 +45,9 @@ struct LoginScreen: View {
4845
_viewModel = StateObject(wrappedValue: viewModel)
4946
viewModel.authState = QBSession.current.currentUser != nil
5047
? AuthState.authorized : AuthState.unAuthorized
48+
if openWithTabBar == false {
49+
tabBarVisibility = .hidden
50+
}
5151
setupFeatures()
5252
}
5353

@@ -63,7 +63,14 @@ struct LoginScreen: View {
6363
QuickBloxUIKit.dialogsView(onExit: {
6464
// Handling an event when exiting the QuickBloxUIKit e.g. disconnect and logout
6565
viewModel.disconnect()
66+
}, onSelect: { tabIndex in
67+
selectedTabIndex = tabIndex
6668
})
69+
.onAppear {
70+
tabBarVisibility = .hidden
71+
theme = appThemes[UserDefaults.standard.integer(forKey: "Theme")]
72+
setupSettings()
73+
}
6774
})
6875
}
6976

@@ -73,46 +80,59 @@ struct LoginScreen: View {
7380
case .unAuthorized, .authorization:
7481
authView()
7582
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)
9894
.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)
10696
}
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+
}
116136
}
117137
}
118138
}
@@ -137,7 +157,7 @@ struct LoginScreen: View {
137157

138158
@ViewBuilder
139159
private func authView() -> some View {
140-
NavigationView {
160+
NavigationStack {
141161
ZStack {
142162
theme.color.mainBackground.ignoresSafeArea()
143163
if viewModel.isSignUped {
@@ -177,8 +197,8 @@ struct LoginScreen: View {
177197
isValidForm: $viewModel.isSignUpValidForm,
178198
onTapped: {
179199
viewModel.signUp(withLogin: viewModel.login,
180-
displayName: viewModel.displayName,
181-
password: viewModel.password)
200+
displayName: viewModel.displayName,
201+
password: viewModel.password)
182202
}, theme: theme)
183203

184204
.onChange(of: viewModel.authState) { authState in
@@ -224,7 +244,7 @@ struct LoginScreen: View {
224244
isValidForm: $viewModel.isLoginValidForm,
225245
onTapped: {
226246
viewModel.login(withLogin: viewModel.login,
227-
password: viewModel.password)
247+
password: viewModel.password)
228248
}, theme: theme)
229249

230250
.onChange(of: viewModel.authState) { authState in
@@ -299,13 +319,17 @@ struct LoginScreen: View {
299319
// Setup Background Image for Dialog Screen
300320
QuickBloxUIKit.settings.dialogScreen.backgroundImage = Image("dialogBackground")
301321
QuickBloxUIKit.settings.dialogScreen.backgroundImageColor = theme.color.divider
322+
if openWithTabBar {
323+
QuickBloxUIKit.settings.dialogsScreen.tabIndex.externalIndexes = [.settings, .exit]
324+
}
302325
}
303326

304327
private func setupFeatures() {
305328
QuickBloxUIKit.feature.ai.apiKey = ""
306329
QuickBloxUIKit.feature.ai.ui = AIUISettings(theme)
307330
QuickBloxUIKit.feature.forward.enable = true
308331
QuickBloxUIKit.feature.reply.enable = true
332+
QuickBloxUIKit.feature.toolbar.enable = openWithTabBar
309333
}
310334
}
311335

@@ -318,3 +342,10 @@ struct LoginScreen_Previews: PreviewProvider {
318342
}
319343
}
320344
}
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+
}

sample-ui-kit/UIKitSample/Resources/en.lproj/Localizable.strings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dialog.items.empty" = "There are no dialogs";
1010
"dialog.members.empty" = "You don’t have any users.";
1111
"dialog.messages.empty" = "You don’t have any messages.";
12+
"dialog.info.selectDialog" = "Select a dialog to start communication";
1213
"dialog.type.private" = "Private";
1314
"dialog.type.group" = "Group";
1415
"dialog.type.public" = "Public";
@@ -48,6 +49,7 @@
4849
"alert.actions.gallery" = "Gallery";
4950
"alert.actions.file" = "File";
5051
"alert.actions.remove" = "Remove";
52+
"alert.message.removeItem" = "Are you sure you want to remove ";
5153
"alert.actions.cancel" = "Cancel";
5254
"alert.actions.ok" = "Ok";
5355
"alert.message.removeUser" = "Are you sure you want to remove ";
@@ -92,6 +94,7 @@
9294
"utils.string.hasLeft" = "has left";
9395
"utils.string.today" = "Today";
9496
"utils.string.yesterday" = "Yesterday";
97+
"utils.string.unknown" = "Unknown";
9598

9699
"utils.string.connecting" = "connecting";
97100
"utils.string.update" = "update";

sample-ui-kit/UIKitSample/Resources/es.lproj/Localizable.strings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dialog.items.empty" = "No tiene ningún cuadro de canal.";
1010
"dialog.members.empty" = "No tiene ningún usuario.";
1111
"dialog.messages.empty" = "No tiene ningún mensaje.";
12+
"dialog.info.selectDialog" = "Seleccione un cuadro de diálogo para iniciar la comunicación";
1213
"dialog.type.private" = "Privado";
1314
"dialog.type.group" = "Grupo";
1415
"dialog.type.public" = "Público";
@@ -48,6 +49,7 @@
4849
"alert.actions.gallery" = "Galería";
4950
"alert.actions.file" = "Archivo";
5051
"alert.actions.remove" = "Eliminar";
52+
"alert.message.removeItem" = "¿Está seguro de que desea eliminar ";
5153
"alert.actions.cancel" = "Cancelar";
5254
"alert.actions.ok" = "Ok";
5355
"alert.message.removeUser" = "¿Está seguro de que desea eliminar ";
@@ -92,6 +94,7 @@
9294
"utils.string.hasLeft" = "se ha ido";
9395
"utils.string.today" = "Hoy";
9496
"utils.string.yesterday" = "Ayer";
97+
"utils.string.unknown" = "Desconocido";
9598

9699
"utils.string.connecting" = "conectando";
97100
"utils.string.update" = "actualizar";

0 commit comments

Comments
 (0)