Chat UIKit React Native v3
Chat UIKit React Native
Chat UIKit
React Native
Version 3

Configure group channel settings

Copy link

You can configure the settings of each group channel. Customizable settings include channel name, cover image, and notifications. You can also leave the channel. For channel operators, you can view the moderation menu.


You can start building a group channel settings screen by first creating a fragment. To do so, call the createGroupChannelSettingsFragment method. Once a group channel settings fragment is built, you need to set up the navigation props and register the screen to a navigation library. Refer to the code below.

import React, { useState } from 'react';
import { useSendbirdChat, createGroupChannelSettingsFragment } from '@sendbird/uikit-react-native';
import { useGroupChannel } from "@sendbird/uikit-chat-hooks";

const GroupChannelSettingsFragment = createGroupChannelSettingsFragment();
const GroupChannelSettingsScreen = ({ route: { params } }: any) => {
    const { sdk } = useSendbirdChat();
    const { channel } = useGroupChannel(sdk, params.channelUrl);
    if (!channel) return null;

    const navigateToBack = () => {};
    const navigateToGroupChannelListScreen = () => {};
    const navigateToGroupChannelMembersScreen = () => {};
    const navigateToGroupChannelModerationScreen = () => {};

    // This line is only required if mention is turned on.
    const navigateToGroupChannelNotificationScreen = () => {};

    return (
        <GroupChannelSettingsFragment
            channel={channel}
            onPressHeaderLeft={navigateToBack}
            onPressMenuLeaveChannel={navigateToGroupChannelListScreen}
            onPressMenuMembers={navigateToGroupChannelMembersScreen}
            onPressMenuModeration={navigateToGroupChannelModerationScreen}
            onPressMenuNotification={navigateToGroupChannelNotificationScreen}
        />
    );
};

List of properties

Copy link

The following table lists the properties of GroupChannelSettingsFragment.

Properties
RequiredTypeDescription

channel

object

Specifies the group channel that the current user is a member of.

onPressHeaderLeft

function

Specifies the prop to execute a custom navigation operation when the button on the top left corner of the header component is selected. By default, the screen goes back to the previous screen.

onPressMenuModeration

function

Specifies the prop to execute a custom navigation operation when a user selects Moderation in the settings menu. By default, the moderation screen appears.

onPressMenuMembers

function

Specifies the prop to execute a custom navigation operation when a user selects Members in the settings menu. By default, the member list screen appears.

onPressMenuLeaveChannel

function

Specifies the prop to execute a custom navigation operation when a user selects Leave channel in the settings menu. By default, the channel list screen appears.

OptionalTypeDescription

menuItemsCreator

function

Specifies the prop to customize the menu list in the settings menu component.


Context

Copy link

To store and handle data that are used to build the group channel settings screen, Sendbird UIKit provides GroupChannelSettingsContexts, which is comprised of GroupChannelSettingsContexts.Fragment.

type GroupChannelSettingsContextsType<User> = {
    Fragment: React.Context<{
        channel: Sendbird.GroupChannel;
        headerTitle: string;
        headerRight: string;
        onPressHeaderRight: () => void;
    }>;
};

Fragment

Copy link

To retrieve data from the Chat SDK on the current user's group channel settings screen, you need to call the useContext hook and pass GroupChannelSettingsContexts.Fragment as a parameter. The data is then used to render the group channel module and its components.

import { useContext } from 'react';
import { GroupChannelSettingsContexts } from '@sendbird/uikit-react-native';

const Component = () => {
  const { channel, headerTitle, headerRight, onPressHeaderRight } = useContext(GroupChannelSettingsContexts.Fragment);
}

Module components

Copy link

A group channel settings screen is composed of three module components: header, channel information, and settings menu. These components make up the GroupChannelSettingsModule and are used to create and display the group channel settings UI.

Header

Copy link

The header component displays the title of the group channel settings screen, a button on the top left corner, and another button on the top right corner. The left button allows you to go back to the previous screen and when selected, the onPressHeaderLeft navigation prop is called. When the right button is selected, you can edit the channel name and cover image.

List of properties

Copy link

The following table lists the properties of GroupChannelSettingsModule.Header.

Property nameTypeDescription

onPressHeaderLeft

function

Specifies the prop to execute a custom navigation operation when the button on the top left corner of the header component is selected. By default, the screen goes back to the previous screen.

Channel information

Copy link

The channel information component shows the channel's cover image and name by default.

Settings menu

Copy link

The settings menu shows different configuration options of the channel that you can set. The menu includes notifications, members, and leave channel.

List of properties

Copy link

The following table lists the properties of GroupChannelSettingsModule.Menu.

Property nameTypeDescription

onPressMenuModeration

function

Specifies the prop to execute a custom navigation operation when a user selects Moderation in the settings menu. By default, the moderation screen appears.

onPressMenuMembers

function

Specifies the prop to execute a custom navigation operation when a user selects Members in the settings menu. By default, the member list screen appears.

onPressMenuLeaveChannel

function

Specifies the prop to execute a custom navigation operation when a user selects Leave channel in the settings menu. By default, the channel list screen appears.

onPressMenuNotification

function

Specifies the prop to execute a custom navigation operation when a user selects Notification in the settings menu. By default, the channel notifications screen appears. This prop is only required when the mention feature is turned on.

menuItemsCreator

function

Specifies the prop to customize the menu list in the settings menu component.


Customization

Copy link

In the group channel settings function, you can customize the default GroupChannelSettingsFragment to change the settings menu items. See the code below on how to add a custom item to the settings menu.

Note: To learn more about how to customize a fragment, go to the fragment page.

import { Text, Share } from 'react-native';

import { Icon } from '@sendbird/uikit-react-native-foundation';
import { useGroupChannel } from "@sendbird/uikit-chat-hooks";

const GroupChannelSettingsFragment = createGroupChannelSettingsFragment({
  Header: () => <Text>{'Custom Header'}</Text>,
  Menu: () => <Text>{'Custom Menu'}</Text>,  
  Info: () => <Text>{'Custom Info'}</Text>,
});
const GroupChannelSettingsScreen = ({ route: { params } }: any) => {
    const { sdk } = useSendbirdChat();
    const { channel } = useGroupChannel(sdk, params.channelUrl);
    if (!channel) return null;

    const navigateToBack = () => {};
    const navigateToGroupChannelModerationScreen = () => {};
    const navigateToGroupChannelMembersScreen = () => {};
    const navigateToGroupChannelListScreen = () => {};
    
    // This line is only required if mention is turned on.
    const navigateToGroupChannelNotificationScreen = () => {};

    return (
        <GroupChannelSettingsFragment
            channel={channel}
            onPressHeaderLeft={navigateToBack}
            onPressMenuModeration={navigateToGroupChannelModerationScreen}
            onPressMenuMembers={navigateToGroupChannelMembersScreen}
            onPressMenuLeaveChannel={navigateToGroupChannelListScreen}
            onPressMenuNotification={navigateToGroupChannelNotificationScreen}
            menuItemsCreator={(items) => {
                items.unshift({
                    icon: 'channels',
                    name: 'Share channel',
                    actionItem: <Icon icon={'chevron-right'} color={'black'} />,
                    onPress: () => Share.share({ title: 'Channel url', url: channel.url }),
                });
                return items;
            }}
        />
    );
};