Skip to content

Commit

Permalink
Merge pull request #1369 from QuickBlox/Release-UIKit-Sample-1.1.3
Browse files Browse the repository at this point in the history
Release UIKit-Sample 1.1.3
  • Loading branch information
VladimirNybozhinsky authored Jan 31, 2024
2 parents eb6578c + 34865a5 commit e31b792
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 47 deletions.
4 changes: 4 additions & 0 deletions sample-ui-kit/UIKitSample/AppTheme/AppTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,13 @@ public class CustomImageTheme: ThemeImageProtocol {

public class CustomThemeString: ThemeStringProtocol {

public var removeItem: String = String(localized: "alert.message.removeItem")
public var settings: String = String(localized: "permission.actions.settings")
public var unknown: String = String(localized: "utils.string.unknown")
public var dialogsEmpty: String = String(localized: "dialog.items.empty")
public var usersEmpty: String = String(localized: "dialog.members.empty")
public var messegesEmpty: String = String(localized: "dialog.messages.empty")
public var selectDialog: String = String(localized: "dialog.info.selectDialog")

public var privateDialog: String = String(localized: "dialog.type.private")
public var groupDialog: String = String(localized: "dialog.type.group")
Expand Down
1 change: 1 addition & 0 deletions sample-ui-kit/UIKitSample/Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Connect: ObservableObject {
objectWillChange.send(authState)
}
}

@Published var isConnected: Bool = false

init(state: ConnectState = .disconnected) {
Expand Down
125 changes: 78 additions & 47 deletions sample-ui-kit/UIKitSample/LoginScreen/LoginScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ struct LoginScreen: View {
@StateObject private var viewModel: LoginViewModal
@State public var theme: AppTheme = appThemes[UserDefaults.standard.integer(forKey: "Theme")]
@State private var loginInfo = LoginConstant.login
@State private var selectedTabIndex: String = "chats" {
didSet {
dialogsPresented = selectedTabIndex == "chats"
}
}
@State private var selectedTabIndex: QuickBloxUIKit.TabIndex = .dialogs

@State private var tabBarVisibility: Visibility = .visible
@State private var dialogsPresented: Bool = false

Expand All @@ -48,6 +45,9 @@ struct LoginScreen: View {
_viewModel = StateObject(wrappedValue: viewModel)
viewModel.authState = QBSession.current.currentUser != nil
? AuthState.authorized : AuthState.unAuthorized
if openWithTabBar == false {
tabBarVisibility = .hidden
}
setupFeatures()
}

Expand All @@ -63,7 +63,14 @@ struct LoginScreen: View {
QuickBloxUIKit.dialogsView(onExit: {
// Handling an event when exiting the QuickBloxUIKit e.g. disconnect and logout
viewModel.disconnect()
}, onSelect: { tabIndex in
selectedTabIndex = tabIndex
})
.onAppear {
tabBarVisibility = .hidden
theme = appThemes[UserDefaults.standard.integer(forKey: "Theme")]
setupSettings()
}
})
}

Expand All @@ -73,46 +80,59 @@ struct LoginScreen: View {
case .unAuthorized, .authorization:
authView()
case .authorized:

TabView(selection: $selectedTabIndex) {

QuickBloxUIKit.dialogsView(onAppear: { appear in
if selectedTabIndex == "chats" {
tabBarVisibility = appear == true ? Visibility.visible : Visibility.hidden
}
})
.toolbar(tabBarVisibility, for: .tabBar)
.toolbarBackground(theme.color.mainBackground, for: .tabBar)
.toolbarBackground(tabBarVisibility, for: .tabBar)
.tag("chats")
.tabItem {
Label("Chats", systemImage: "bubble.left.and.bubble.right.fill")
}

settingsView()
.tabItem {
Label("Settings", systemImage: "gearshape")
}.tag("settings")

disconnectView()
if openWithTabBar == true {
TabView(selection: $selectedTabIndex) {
QuickBloxUIKit.dialogsView(onSelect: { tabIndex in
if tabIndex != .dialogs {
selectedTabIndex = tabIndex
}
})
.toolbar(tabBarVisibility, for: .tabBar)
.toolbarBackground(theme.color.mainBackground, for: .tabBar)
.toolbarBackground(tabBarVisibility, for: .tabBar)
.tag(TabIndex.dialogs)
.tabItem {
Label(viewModel.authState == .unAuthorized ? "Enter" : "Exit",
systemImage: viewModel.authState == .unAuthorized
? "figure.walk.arrival" : "figure.walk.departure")
}.tag("auth")

.onChange(of: viewModel.authState) { authState in
self.selectedTabIndex = authState == .authorized ? "chats" : "auth"
Label(TabIndex.dialogs.title, systemImage: TabIndex.dialogs.systemIcon)
}
}
.accentColor(theme.color.mainElements)
.onAppear {
selectedTabIndex = QBSession.current.currentUser != nil ? "chats" : "auth"
viewModel.authState = QBSession.current.currentUser != nil
? AuthState.authorized : AuthState.unAuthorized
theme = appThemes[UserDefaults.standard.integer(forKey: "Theme")]
setupSettings()
tabBarVisibility = .visible
.onAppear {
theme = appThemes[UserDefaults.standard.integer(forKey: "Theme")]
setupSettings()
tabBarVisibility = selectedTabIndex != .dialogs ? .visible : .hidden
}

settingsView()
.toolbar(tabBarVisibility, for: .tabBar)
.toolbarBackground(theme.color.mainBackground, for: .tabBar)
.toolbarBackground(tabBarVisibility, for: .tabBar)
.tabItem {
Label(TabIndex.settings.title, systemImage: TabIndex.settings.systemIcon)
}
.tag(TabIndex.settings)

disconnectView()
.toolbar(tabBarVisibility, for: .tabBar)
.toolbarBackground(theme.color.mainBackground, for: .tabBar)
.toolbarBackground(tabBarVisibility, for: .tabBar)
.tabItem {
Label(viewModel.authState == .unAuthorized ? TabIndex.enter.title : TabIndex.exit.title,
systemImage: viewModel.authState == .unAuthorized
? TabIndex.enter.systemIcon : TabIndex.exit.systemIcon)
}
.tag(TabIndex.exit)

.onChange(of: viewModel.authState) { authState in
self.selectedTabIndex = authState == .authorized ? TabIndex.dialogs : TabIndex.exit
}
}
.accentColor(theme.color.mainElements)
.onAppear {
selectedTabIndex = QBSession.current.currentUser != nil ? TabIndex.dialogs : TabIndex.exit
viewModel.authState = QBSession.current.currentUser != nil
? AuthState.authorized : AuthState.unAuthorized
theme = appThemes[UserDefaults.standard.integer(forKey: "Theme")]
setupSettings()
tabBarVisibility = .visible
}
}
}
}
Expand All @@ -137,7 +157,7 @@ struct LoginScreen: View {

@ViewBuilder
private func authView() -> some View {
NavigationView {
NavigationStack {
ZStack {
theme.color.mainBackground.ignoresSafeArea()
if viewModel.isSignUped {
Expand Down Expand Up @@ -177,8 +197,8 @@ struct LoginScreen: View {
isValidForm: $viewModel.isSignUpValidForm,
onTapped: {
viewModel.signUp(withLogin: viewModel.login,
displayName: viewModel.displayName,
password: viewModel.password)
displayName: viewModel.displayName,
password: viewModel.password)
}, theme: theme)

.onChange(of: viewModel.authState) { authState in
Expand Down Expand Up @@ -224,7 +244,7 @@ struct LoginScreen: View {
isValidForm: $viewModel.isLoginValidForm,
onTapped: {
viewModel.login(withLogin: viewModel.login,
password: viewModel.password)
password: viewModel.password)
}, theme: theme)

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

private func setupFeatures() {
QuickBloxUIKit.feature.ai.apiKey = ""
QuickBloxUIKit.feature.ai.ui = AIUISettings(theme)
QuickBloxUIKit.feature.forward.enable = true
QuickBloxUIKit.feature.reply.enable = true
QuickBloxUIKit.feature.toolbar.enable = openWithTabBar
}
}

Expand All @@ -318,3 +342,10 @@ struct LoginScreen_Previews: PreviewProvider {
}
}
}

public extension TabIndex {
static let exit = TabIndex(title: "Exit",
systemIcon: "figure.walk.departure")
static let enter = TabIndex(title: "Enter",
systemIcon: "figure.walk.arrival")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dialog.items.empty" = "There are no dialogs";
"dialog.members.empty" = "You don’t have any users.";
"dialog.messages.empty" = "You don’t have any messages.";
"dialog.info.selectDialog" = "Select a dialog to start communication";
"dialog.type.private" = "Private";
"dialog.type.group" = "Group";
"dialog.type.public" = "Public";
Expand Down Expand Up @@ -48,6 +49,7 @@
"alert.actions.gallery" = "Gallery";
"alert.actions.file" = "File";
"alert.actions.remove" = "Remove";
"alert.message.removeItem" = "Are you sure you want to remove ";
"alert.actions.cancel" = "Cancel";
"alert.actions.ok" = "Ok";
"alert.message.removeUser" = "Are you sure you want to remove ";
Expand Down Expand Up @@ -92,6 +94,7 @@
"utils.string.hasLeft" = "has left";
"utils.string.today" = "Today";
"utils.string.yesterday" = "Yesterday";
"utils.string.unknown" = "Unknown";

"utils.string.connecting" = "connecting";
"utils.string.update" = "update";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dialog.items.empty" = "No tiene ningún cuadro de canal.";
"dialog.members.empty" = "No tiene ningún usuario.";
"dialog.messages.empty" = "No tiene ningún mensaje.";
"dialog.info.selectDialog" = "Seleccione un cuadro de diálogo para iniciar la comunicación";
"dialog.type.private" = "Privado";
"dialog.type.group" = "Grupo";
"dialog.type.public" = "Público";
Expand Down Expand Up @@ -48,6 +49,7 @@
"alert.actions.gallery" = "Galería";
"alert.actions.file" = "Archivo";
"alert.actions.remove" = "Eliminar";
"alert.message.removeItem" = "¿Está seguro de que desea eliminar ";
"alert.actions.cancel" = "Cancelar";
"alert.actions.ok" = "Ok";
"alert.message.removeUser" = "¿Está seguro de que desea eliminar ";
Expand Down Expand Up @@ -92,6 +94,7 @@
"utils.string.hasLeft" = "se ha ido";
"utils.string.today" = "Hoy";
"utils.string.yesterday" = "Ayer";
"utils.string.unknown" = "Desconocido";

"utils.string.connecting" = "conectando";
"utils.string.update" = "actualizar";
Expand Down

0 comments on commit e31b792

Please sign in to comment.