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

List operators in open channel

Copy link

An operator list is a complete list of operators of an open channel. The operator list is created through OpenChannelOperatorsFragment.


You can start building an operator list screen by first creating a fragment. To do so, call the createOpenChannelOperatorsFragment method. Once an operator list 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 from 'react';

import { useOpenChannel } from '@sendbird/uikit-chat-hooks';
import { createOpenChannelOperatorsFragment, useSendbirdChat } from '@sendbird/uikit-react-native';

const OpenChannelOperatorsFragment = createOpenChannelOperatorsFragment();
const OpenChannelOperatorsScreen = ({ route: { params } }: any) => {
    const { sdk } = useSendbirdChat();
    const { channel } = useOpenChannel(sdk, params.channelUrl);
    if (!channel) return null;
    
    const navigateToBack = () => {};
    const navigateToOpenChannelRegisterOperator = () => {};
    
    return (
        <OpenChannelOperatorsFragment
            channel={channel}
            onPressHeaderLeft={navigateToBack}
            onPressHeaderRight={navigateToOpenChannelRegisterOperator}
        />
    );
};

List of properties

Copy link

The following table lists the properties of OpenChannelOperatorsFragment.

Properties
RequiredTypeDescription

channel

object

Specifies the open channel that the current user is a participant 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.

onPressHeaderRight

function

Specifies the prop to execute a custom navigation operation when the button on the top right corner of the header component is selected. By default, the screen changes to the open channel register operator screen where you can add new operator to the channel.

OptionalTypeDescription

renderUser

function

Renders a customized view of the user profile.


Context

Copy link

To store and handle data that are used to build the operator list screen, Sendbird Chat UIKit provides OpenChannelOperatorsContexts, which includes the Fragment context object.

type OpenChannelOperatorsContextsType = {
    Fragment: React.Context<{
        headerTitle: string;
        channel: Sendbird.OpenChannel;
    }>;
};

Fragment

Copy link

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

const Component = () => {
    const {
        headerTitle,
        channel,
    } = useContext(OpenChannelOperatorsContexts.Fragment);
};

Module components

Copy link

An operator list screen is composed of five module components: header, list, loading status, loading error, and empty status. These components make up the OpenChannelOperatorsModule and are used to create and display the UI of the screen.

Header

Copy link

The header component displays the title of the open channel, a button on the top left corner, and another button on the top right corner. By default, 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, onPressHeaderRight is called and the open channel settings screen appears.

List of properties

Copy link

The following table lists the properties of OpenChannelOperatorsModule.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.

onPressHeaderRight

function

Specifies the prop to execute a custom navigation operation when the button on the top right corner of the header component is selected. By default, the screen changes to the open channel register operator screen where you can add new operator to the channel.

The list component shows a list of profile images and names of operators of the channel.

List of properties

Copy link

The following table lists the properties of OpenChannelOperatorsModule.List.

Property nameTypeDescription

operators

array of objects

Specifies a list of operators.

onLoadNext

function

Specifies the prop to execute custom operations when loading more user list items.

renderUser

function

Renders a customized view of the user profile.

ListEmptyComponent

ReactElement

Renders a customized view of the empty user list.

StatusLoading

Copy link

The StatusLoading component lets the user know if the operator list is loading.

StatusEmpty

Copy link

The StatusEmpty component lets the user know if the operator list is empty.

StatusError

Copy link

The StatusError component lets the user know if fetching the operator list has failed.


Customization

Copy link

In the list operators in open channel key function, you can customize the default OpenChannelOperatorsFragment to change various elements of the screen such as the module and its components. See the code below on how to replace the default header component with a custom header component in OpenChannelOperatorsFragment as an example.

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

const OpenChannelOperatorsFragment = createOpenChannelOperatorsFragment({
    Header: () => <MyHeader />, // Use custom header
});
const OpenChannelOperatorsScreen = ({ route: { params } }: any) => {
    const { sdk } = useSendbirdChat();
    const { channel } = useOpenChannel(sdk, params.channelUrl);
    if (!channel) return null;
    
    const navigateToBack = () => {};
    const navigateToOpenChannelRegisterOperator = () => {};
    
    return (
        <OpenChannelOperatorsFragment
            channel={channel}
            onPressHeaderLeft={navigateToBack}
            onPressHeaderRight={navigateToOpenChannelRegisterOperator}
        />
    );
};