index.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React, { FC, ReactNode } from 'react';
  2. import { Text, TouchableOpacity, View } from 'react-native';
  3. import { CommonActions, useNavigation } from '@react-navigation/native';
  4. import { styles } from './style';
  5. import ChevronLeft from '../../../assets/icons/chevron-left.svg';
  6. import CloseSvg from '../../../assets/icons/close.svg';
  7. import { NAVIGATION_PAGES } from 'src/types';
  8. import { Colors } from 'src/theme';
  9. type Props = {
  10. label: string;
  11. rightElement?: ReactNode;
  12. shouldClose?: boolean;
  13. };
  14. export const Header: FC<Props> = ({ label, rightElement, shouldClose }) => {
  15. const navigation = useNavigation();
  16. const handlePress = () => {
  17. if (shouldClose) {
  18. navigation.dispatch(
  19. CommonActions.reset({
  20. index: 1,
  21. routes: [{ name: NAVIGATION_PAGES.IN_APP }]
  22. })
  23. );
  24. } else {
  25. navigation.goBack();
  26. }
  27. };
  28. // navigation.setOptions() TODO
  29. return (
  30. <View style={styles.wrapper}>
  31. <TouchableOpacity onPress={handlePress}>
  32. <View style={styles.chevronWrapper}>{shouldClose ? <CloseSvg /> : <ChevronLeft fill={Colors.DARK_BLUE} />}</View>
  33. </TouchableOpacity>
  34. <Text style={styles.label}>{label}</Text>
  35. {rightElement ? <View>{rightElement}</View> : <View style={styles.placeholder} />}
  36. </View>
  37. );
  38. };