So, we want to customize the GroupChannelFragment, wherein we want to replace the default header component for GroupChannelModule with our CustomHeader component.
We want to pass headerTitle to our CustomHeader, and therefore accessing it’s value from sendbird GroupChannelModule’s context ( GroupChannelContextsProvider ). The code that we have implemented to achieve our use-case so for is described below:
const GroupChannelScreen = () => {
const { params } = useRoute();
const { sdk } = useSendbirdChat();
const navigation = useNavigation();
const { channel } = useGroupChannel(sdk, params.channelUrl);
const CustomGroupChannelFragment = ({
channel,
onChannelDeleted = NOOP,
onPressHeaderLeft = NOOP,
onPressHeaderRight = NOOP,
}) => {
if (!channel) return null;
const { headerTitle } = useContext(GroupChannelContexts.Fragment);
console.log("title value", headerTitle); // "title value" ""
const CustomGroupChannelModule = createGroupChannelModule({
Header: CustomHeader,
});
return (
<CustomGroupChannelModule.Provider
channel={channel}
enableTypingIndicator={true}
keyboardAvoidOffset={20}
>
<CustomGroupChannelModule.Header
title={headerTitle}
onLeftArrowPress={onPressHeaderLeft}
/>
</CustomGroupChannelModule.Provider>
);
};
return (
<CustomGroupChannelFragment
channel={channel}
onChannelDeleted={() => {
// Navigate to GroupChannelList function.
navigation.navigate("GroupChannelList");
}}
onPressHeaderLeft={() => {
// Go back to the previous screen.
navigation.goBack();
}}
onPressHeaderRight={() => {
// Navigate to GroupChannelSettings function.
navigation.navigate("GroupChannelSettings", {
channelUrl: params.channelUrl,
});
}}
/>
);
};
As you can see, headerTitle console’s empty string. When we checked sendbird moduleContext file ( moduleContext.tsx ) for GroupChannel, we got to know that the value we are getting is the safeFallback value for the GroupChannelContextsProvider.
What are we missing here? Why are we getting the safeFallback value for the context we are using? We want the headerTitle value for current groupChannel we are in.
PS: we have checked our imports, seems to be correct.
import { GroupChannelContexts } from "@sendbird/uikit-react-native";