import React, { useEffect } from 'react'; import { StyleProp, StyleSheet, Text, TouchableOpacity, View, ViewStyle } from 'react-native'; import { CompositeNavigationProp, useNavigation } from '@react-navigation/native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useAttachmentPickerContext, useTheme } from 'stream-chat-react-native'; import { UnreadCountBadge } from './UnreadCountBadge'; import { GoBack } from '../icons/GoBack'; import type { DrawerNavigationProp } from '@react-navigation/drawer'; import type { StackNavigationProp } from '@react-navigation/stack'; import type { DrawerNavigatorParamList, StackNavigatorParamList } from '../types'; const styles = StyleSheet.create({ backButton: { paddingVertical: 8, }, backButtonUnreadCount: { left: 25, position: 'absolute', }, centerContainer: { alignItems: 'center', flex: 1, justifyContent: 'center', }, contentContainer: { alignItems: 'center', flexDirection: 'row', padding: 8, }, leftContainer: { width: 70, }, rightContainer: { alignItems: 'flex-end', width: 70, }, safeAreaContainer: { borderBottomWidth: 1, }, subTitle: { fontSize: 12, }, title: { fontSize: 16, fontWeight: '700', }, }); type ScreenHeaderNavigationProp = CompositeNavigationProp< DrawerNavigationProp, StackNavigationProp >; export const BackButton: React.FC<{ onBack?: () => void; showUnreadCountBadge?: boolean; }> = ({ onBack, showUnreadCountBadge }) => { const navigation = useNavigation(); return ( { navigation.goBack(); if (onBack) { onBack(); } }} style={styles.backButton} > {!!showUnreadCountBadge && ( )} ); }; type ScreenHeaderProps = { titleText: string; inSafeArea?: boolean; LeftContent?: React.ElementType; onBack?: () => void; RightContent?: React.ElementType; showUnreadCountBadge?: boolean; style?: StyleProp; Subtitle?: React.ElementType; subtitleText?: string; Title?: React.ElementType; }; const HEADER_CONTENT_HEIGHT = 55; export const ScreenHeader: React.FC = (props) => { const { inSafeArea, LeftContent, onBack, RightContent = () => , showUnreadCountBadge, style, Subtitle, subtitleText, Title, titleText = 'Stream Chat', } = props; const { theme: { colors: { black, border, grey, white }, }, } = useTheme(); const insets = useSafeAreaInsets(); const { setTopInset } = useAttachmentPickerContext(); useEffect(() => { if (setTopInset) { setTopInset(HEADER_CONTENT_HEIGHT + insets.top); } }, [insets.top]); return ( {LeftContent ? ( ) : ( )} {Title ? ( ) : ( !!titleText && ( <Text style={[ styles.title, { color: black, }, ]} > {titleText} </Text> ) )} </View> {Subtitle ? ( <Subtitle /> ) : ( !!subtitleText && ( <Text style={[ styles.subTitle, { color: grey, }, ]} > {subtitleText} </Text> ) )} </View> <View style={styles.rightContainer}> <RightContent /> </View> </View> </View> ); };