diff --git a/sample-ui-kit/UIKitSample/AppTheme/AppTheme.swift b/sample-ui-kit/UIKitSample/AppTheme/AppTheme.swift index 9af82b274..330f1fe93 100644 --- a/sample-ui-kit/UIKitSample/AppTheme/AppTheme.swift +++ b/sample-ui-kit/UIKitSample/AppTheme/AppTheme.swift @@ -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") diff --git a/sample-ui-kit/UIKitSample/Connect.swift b/sample-ui-kit/UIKitSample/Connect.swift index 1b4362c2a..bc011b595 100644 --- a/sample-ui-kit/UIKitSample/Connect.swift +++ b/sample-ui-kit/UIKitSample/Connect.swift @@ -33,6 +33,7 @@ class Connect: ObservableObject { objectWillChange.send(authState) } } + @Published var isConnected: Bool = false init(state: ConnectState = .disconnected) { diff --git a/sample-ui-kit/UIKitSample/LoginScreen/LoginScreen.swift b/sample-ui-kit/UIKitSample/LoginScreen/LoginScreen.swift index c74b7abce..c412d079d 100644 --- a/sample-ui-kit/UIKitSample/LoginScreen/LoginScreen.swift +++ b/sample-ui-kit/UIKitSample/LoginScreen/LoginScreen.swift @@ -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 @@ -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() } @@ -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() + } }) } @@ -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 + } } } } @@ -137,7 +157,7 @@ struct LoginScreen: View { @ViewBuilder private func authView() -> some View { - NavigationView { + NavigationStack { ZStack { theme.color.mainBackground.ignoresSafeArea() if viewModel.isSignUped { @@ -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 @@ -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 @@ -299,6 +319,9 @@ 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() { @@ -306,6 +329,7 @@ struct LoginScreen: View { QuickBloxUIKit.feature.ai.ui = AIUISettings(theme) QuickBloxUIKit.feature.forward.enable = true QuickBloxUIKit.feature.reply.enable = true + QuickBloxUIKit.feature.toolbar.enable = openWithTabBar } } @@ -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") +} diff --git a/sample-ui-kit/UIKitSample/Resources/en.lproj/Localizable.strings b/sample-ui-kit/UIKitSample/Resources/en.lproj/Localizable.strings index bee36d219..48e85c274 100644 --- a/sample-ui-kit/UIKitSample/Resources/en.lproj/Localizable.strings +++ b/sample-ui-kit/UIKitSample/Resources/en.lproj/Localizable.strings @@ -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"; @@ -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 "; @@ -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"; diff --git a/sample-ui-kit/UIKitSample/Resources/es.lproj/Localizable.strings b/sample-ui-kit/UIKitSample/Resources/es.lproj/Localizable.strings index c61eba4de..5724de74f 100644 --- a/sample-ui-kit/UIKitSample/Resources/es.lproj/Localizable.strings +++ b/sample-ui-kit/UIKitSample/Resources/es.lproj/Localizable.strings @@ -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"; @@ -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 "; @@ -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";