PriceListView.js 3.4 KB
Newer Older
Giang Tran committed
1 2
import React, {useState} from 'react';
import {
Nguyễn Thị Thúy committed
3 4 5 6 7 8
    View,
    Text,
    FlatList,
    StyleSheet,
    TouchableOpacity,
    ScrollView,
Giang Tran committed
9 10 11 12
} from 'react-native';

import HeaderDrawer from '../../../components/Header/HeaderDrawer';
import Item from './Item';
Nguyễn Thị Thúy committed
13
import {getFontXD, HEIGHTXD} from '../../../Config/Functions';
Giang Tran committed
14
import AppText from '../../../components/AppText';
15 16
import {PRODUCTDETAIL} from '../../../routers/ScreenNames';
import {useNavigation} from '@react-navigation/native';
Giang Tran committed
17

Nguyễn Thị Thúy committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
const PriceListView = (props) => {
    const {onRefresh, isRefresh, onLoadMore, setFilterId, filters, data, filterId} = props;
    const navigate = useNavigation();
    return (
        <View style={{flex: 1}}>
            <View style={styles.headerContainer}>
                <ScrollView horizontal showsHorizontalScrollIndicator={false}>
                    {filters.map((e) => (
                        <TouchableOpacity
                            key={e.id}
                            onPress={() => setFilterId(e.id)}
                            style={[
                                styles.itemFillter,
                                filterId == e.id ? {borderColor: '#1473E6'} : null,
                            ]}>
                            <Text
                                style={[
                                    styles.txtFillter,
                                    filterId == e.id ? {color: '#1473E6'} : {},
                                ]}>{e.name}</Text>
                        </TouchableOpacity>
                    ))}
                </ScrollView>
            </View>
Giang Tran committed
42

Nguyễn Thị Thúy committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
            {data.length == 0 && !isRefresh? (
                <View style={{justifyContent: 'center', alignItems: 'center', flex: 1}}>
                    <AppText
                        i18nKey={'NoData'}
                        style={{
                            fontSize: 18,
                            fontWeight: 'bold',
                        }}></AppText>
                </View>
            ) : (
                <FlatList
                    style={{paddingVertical: HEIGHTXD(15)}}
                    keyExtractor={(item) => item.id}
                    data={data}
                    refreshing={isRefresh}
                    onRefresh={onRefresh}
                    onEndReachedThreshold={0.01}
                    onEndReached={(info) => {
                        onLoadMore();
                    }}
                    renderItem={({item, index}) => <Item item={item}
                                                  isEndItem={index == data.length -1}
65
                                                  onPress={(item) => navigate.navigate(PRODUCTDETAIL, {id: item.id, name: item.name})}/>}
Nguyễn Thị Thúy committed
66 67
                />
            )}
Giang Tran committed
68
        </View>
Nguyễn Thị Thúy committed
69
    );
Giang Tran committed
70 71 72
};

const styles = StyleSheet.create({
Nguyễn Thị Thúy committed
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
    headerContainer: {
        paddingVertical: 10,
        backgroundColor: 'white',
        flexDirection: 'row',
        alignItems: 'center',
        paddingHorizontal: 10,
    },
    itemFillter: {
        borderRadius: 10,
        paddingVertical: 5,
        paddingHorizontal: 10,
        borderWidth: 1,
        borderColor: '#929292',
        justifyContent: 'center',
        alignItems: 'center',
        marginRight: 10,
    },
    txtFillter: {
        fontSize: getFontXD(36),
        color: '#929292',
        fontWeight: 'bold',
    },
    txtTitle: {
        fontSize: getFontXD(46),
        fontWeight: 'bold',
    },
Giang Tran committed
99 100
});

Nguyễn Thị Thúy committed
101
export default PriceListView;