Header.js 3.68 KB
Newer Older
Giang Tran committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import React, {useEffect, useState} from 'react';
import {
  View,
  Text,
  Image,
  StatusBar,
  StyleSheet,
  TouchableOpacity,
  TextInput,
} from 'react-native';
import R from '../../assets/R';
import {getFontXD, WIDTH, HEIGHTXD} from '../../config/Functions';
import LinearGradient from 'react-native-linear-gradient';
import Icon from 'react-native-vector-icons/Ionicons';
import Block from '../Block';
import {useNavigation} from '@react-navigation/native';
import ModalOption from './ModalOption';
Giang Tran committed
18
import SnackBar from '../SnackBar';
Giang Tran committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

const HeaderHome = (props) => {
  const {title} = props;

  const navigate = useNavigation();
  const [openSearch, setOpenSearch] = useState(false);
  const [txtSearch, setTxtSearch] = useState('');
  const [isOpenModal, setOpenModal] = useState(false);
  const [isSelected, setSelected] = useState();

  const closeModal = () => {
    setOpenModal(false);
  };
  const openModal = () => {
    setOpenModal(true);
  };

  const toggleSearch = () => {
    setTxtSearch('');
    setOpenSearch(!openSearch);
  };
  const onChangePicker = (value) => {
    setSelected(value);
  };

  const onModalClick = () => {
    setOpenModal(false);
  };

  return (
    <LinearGradient
      start={{x: 0, y: 0}}
      end={{x: 0, y: 1}}
      colors={['#0062E1', '#22AEFB']}>
Giang Tran committed
53
      <StatusBar barStyle="light-content" translucent={true} />
Giang Tran committed
54 55 56 57 58 59 60 61 62
      <View style={styles.container}>
        <View style={{flex: 1}}>
          <Block center row>
            <TouchableOpacity onPress={() => navigate.goBack()}>
              <Icon name={'chevron-back'} size={30} color={R.colors.white} />
            </TouchableOpacity>

            {openSearch ? (
              <TextInput
Giang Tran committed
63
                placeholderTextColor={R.colors.placeHolder}
Giang Tran committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
                style={styles.txtInput}
                onChangeText={(val) => setTxtSearch(val)}
                value={txtSearch}
              />
            ) : (
              <Text style={styles.txtTitle}>{title ? title : ''} </Text>
            )}
          </Block>
        </View>
        <TouchableOpacity onPress={toggleSearch}>
          {openSearch ? (
            <Icon
              style={[styles.btnIcon, {marginLeft: 10, marginRight: 20}]}
              name={'refresh-outline'}
              size={20}
              color={R.colors.white}
            />
          ) : (
            <Icon
              style={[styles.btnIcon, {marginLeft: 10, marginRight: 20}]}
              name={'search-sharp'}
              size={20}
              color={R.colors.white}
            />
          )}
        </TouchableOpacity>
        <TouchableOpacity onPress={openModal}>
          <Icon
            style={styles.btnIcon}
            name={'options'}
            size={20}
            color={R.colors.white}
          />
        </TouchableOpacity>
      </View>
      <ModalOption
        onChangePicker={onChangePicker}
        isOpen={isOpenModal}
        closeModal={closeModal}
        onClick={onModalClick}
      />
    </LinearGradient>
  );
};

export default HeaderHome;

const styles = StyleSheet.create({
  container: {
    height: 55,
    paddingHorizontal: 10,
    flexDirection: 'row',
    alignItems: 'center',
  },
  txtTitle: {
    fontSize: getFontXD(52),
    color: R.colors.white,
    fontWeight: 'bold',
    marginLeft: 5,
  },
  txt: {fontSize: getFontXD(36), color: R.colors.white},
  img: {
    width: 50,
    height: 50,
    borderRadius: 50,
    borderWidth: 1,
    borderColor: R.colors.white,
  },
  btnIcon: {
    backgroundColor: R.colors.lightBlue2,
    padding: 5,
    borderRadius: 20,
  },
  txtInput: {
    backgroundColor: R.colors.white,
    flex: 1,
    height: HEIGHTXD(139),
    fontSize: getFontXD(42),
    borderRadius: 10,
Giang Tran committed
143
    color: 'black',
Giang Tran committed
144 145
  },
});