Skip to main content
Version: v4

Create Group

Overview

CometChatCreateGroup serves as a versatile Component, empowering users to create diverse group types, encompassing public, private, and password-protected options. This functionality grants users the flexibility to tailor their group settings to suit their preferences and requirements.

Image

The CometChatCreateGroup component is composed of the following BaseComponents:

ComponentsDescription
CometChatListBaseCometChatListBase serves as a comprehensive container component, encompassing essential elements such as a title (navigationBar), search functionality (search-bar), background, and a container to embed a list view. This design provides a cohesive and intuitive user experience, facilitating seamless navigation and interaction within the component.

Usage

Integration

CreateGroup, as a custom view controller, offers flexible integration options, allowing it to be launched directly via button clicks or any user-triggered action. Additionally, it seamlessly integrates into tab view controllers. With CreateGroup, users gain access to a wide range of parameters and methods for effortless customization of its user interface.

The following code snippet exemplifies how you can seamlessly integrate the CreateGroup component into your application.

let cometChatCreateGroup = CometChatCreateGroup()
let naviVC = UINavigationController(rootViewController: cometChatCreateGroup)
self.present(naviVC, animated: true)
info

If you are already using a navigation controller, you can use the pushViewController function instead of presenting the view controller.


Actions

Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.

1. SetOnCreateGroupClick

The setOnCreateGroupClick action is activated when you click the create Group button. This returns the created groups.

You can override this action using the following code snippet.

let cometChatCreateGroup = CometChatCreateGroup()
.setOnCreateGroupClick (onCreateGroupClick:{ group in
//Perform Your Action

})
2. SetOnError

You can customize this behavior by using the provided code snippet to override the On Error and improve error handling.

let cometChatCreateGroup = CometChatCreateGroup()
.setOnError (onError:{ CometChatException in
//Perform Your Action

})

3. SetOnBack

Enhance your application's functionality by leveraging the SetOnBack feature. This capability allows you to customize the behavior associated with navigating back within your app. Utilize the provided code snippet to override default behaviors and tailor the user experience according to your specific requirements.

let cometChatCreateGroup = CometChatCreateGroup()
.setOnBack (onBack:{
//Perform Your Action

})

Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of ChatSDK.

The CreateGroup component does not have any exposed filters.

Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed.

Events emitted by the Create Group component is as follows.

EventDescription
onGroupCreateThis event will be triggered when the logged-in user initiates the creation of a group.
onCreateGroupClick()This event is utilized to execute specific tasks when the logged-in user clicks the "Create Group" button.
// View controller from your project where you want to listen events.
public class ViewController: UIViewController {

public override func viewDidLoad() {
super.viewDidLoad()

// Subscribing for the listener to listen events from user module
CometChatGroupEvents.addListener("UNIQUE_ID", self as CometChatGroupEventListener)
}
}
// Listener events from groups module
extension ViewController: CometChatGroupEventListener {

public func onCreateGroupClick() {
// Do Stuff
}
public func onGroupCreate(group: Group) {
// Do Stuff
}
}
Emitting Group Events
///you need to pass the [Group] object of the group which is created
CometChatGroupEvents.emitOnGroupCreate(group: Group)

View Controller
public override func viewWillDisappear(_ animated: Bool) {
// Uncubscribing for the listener to listen events from user module
CometChatGroupEvents.removeListener("LISTENER_ID_USED_FOR_ADDING_THIS_LISTENER")
}

Customization

To fit your app's design requirements, you can customize the appearance of the Groups component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

Style

Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.

1. CreateGroup Style report

You can set the CreateGroupStyle to the Create Group Component to customize the styling.

// Creating  CreateGroupStyle object
let createGroupStyle = CreateGroupStyle()

// Creating Modifying the propeties of create group
createGroupStyle.set(background: .black)
.set(cornerRadius: CometChatCornerStyle(cornerRadius: 0.0))
.set(borderColor: .clear)
.set(borderWidth: 0)
.set(titleTextFont: .systemFont(ofSize: 22))
.set(titleTextColor: .white)
.set(namePlaceholderTextFont: .systemFont(ofSize: 16))
.set(namePlaceholderTextColor: .white)
.set(passwordPlaceholderFont: .systemFont(ofSize: 16))
.set(passwordPlaceholderColor: .white)
.set(nameInputTextFont: .systemFont(ofSize: 16))
.set(nameInputTextColor: .white)
.set(passwordInputTextFont: .systemFont(ofSize: 16))
.set(passwordInputTextColor: .white)
.set(tabColor: .black)
.set(tabTextColor: .white)
.set(tabTextFont: .systemFont(ofSize: 16))
.set(selectedTabTextColor: .white)
.set(selectedTabTextFont: .systemFont(ofSize: 16))
.set(inputBackgroundColor: .white)
.set(createButtonTextFont: .systemFont(ofSize: 16))
.set(createButtonTextColor: .tintColor)
.set(cancelButtonTextFont: .systemFont(ofSize: 16))
.set(cancelButtonTextColor: .tintColor)


// Setting the CreateGroupStyle
let cometChatCreateGroup = CometChatCreateGroup()
cometChatCreateGroup.set(createGroupStyle: createGroupStyle)

List of properties exposed by CreateGroupStyle

PropertyDescriptionCode
BackgroundSets the background color for create groupset(background: UIColor)
CornerRadiusSets the corner radius for create groupset(cornerRadius: CometChatCornerStyle)
BorderWidthSets the border width for create groupset(borderWidth: CGFloat)
BorderColorSets the border color for create groupset(borderColor: UIColor)
TitleTextColorSets the title color for create groupset(titleTextColor: UIColor)
TitleTextFontSets the title font for create groupset(titleTextFont: UIFont)
NamePlaceholderTextColorSets the placeholder color for nameset(namePlaceholderTextColor: UIColor)
NamePlaceholderTextFontSets the placeholder font for nameset(namePlaceholderTextFont: UIFont)
NameInputTextFontSets the text font for nameset(nameInputTextFont: UIFont)
NameInputTextColorSets the text color for nameset(nameInputTextColor: UIColor)
PasswordInputTextColorSets the text color for passwordset(passwordInputTextColor: UIColor)
PasswordInputTextFontSets the text font for passwordset(passwordInputTextFont: UIFont)
PasswordPlaceholderColorSets the placeholder color for passwordset(passwordPlaceholderColor: UIColor)
PasswordPlaceholderFontSets the placeholder font for passwordset(passwordPlaceholderFont: UIFont)
TabColorSets the tab color for group typesset(tabColor: UIColor)
TabTextFontSets the tab text font for group typesset(tabTextFont: UIFont)
TabTextColorSets the tab text color for group typesset(tabTextColor: UIColor)
SelectedTabTextFontSets the selected tab text font for group typesset(selectedTabTextFont: UIFont)
SelectedTabTextColorSets the selected tab text color for group typesset(selectedTabTextColor: UIColor)
InputBackgroundColorSets the input view background colorset(inputBackgroundColor: UIColor)
InputCornerRadiusSets the input view corner radiusset(inputCornerRadius: CGFloat)
CreateButtonTextColorSets the create button text colorset(createButtonTextColor: UIColor)
CreateButtonTextFontSets the create button text fontset(createButtonTextFont: UIFont)
CancelButtonTextColorSets the cancel button text colorset(cancelButtonTextColor: UIColor)
CancelButtonTextFontSets the cancel button text fontset(cancelButtonTextFont: UIFont)

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.

let cometChatCreateGroup = CometChatCreateGroup()
.set(title: "Your Custom Title", mode: .automatic)
.set(backButtonTitle: "Cc")
.hide(separator: true)

PropertyDescriptionCode
TitleCustom title for the component.set(title: String, mode: UINavigationItem.LargeTitleDisplayMode)
BackButtonTextCustom text for the back button.set(backButtonTitle: String?)
SearchPlaceholderTextCustom placeholder text for search field.set(searchPlaceholder: String)
ShowBackButtonWhether to hide the back button.show(backButton: Bool)
ErrorStateTextCustom error state text.set(errorStateText: String)
BackButtonIconCustom back button icon.set(backButtonIcon: UIImage)

Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your own views, layouts, and UI elements and then incorporate those into the component.

The Create Group component does not provide additional functionalities beyond this level of customization.