ChannelFliter.js 3.53 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';

const {
    View,
    Text,
    ListView,
    TouchableOpacity,
    Dimensions,
    StyleSheet,
} = ReactNative;


export default class ChannelFliter extends React.Component {

    constructor(props) {
        super (props);

        this._renderRow = this._renderRow.bind(this);
        this._renderSeparator = this._renderSeparator.bind(this);

        this.dataSource = new ListView.DataSource({
            rowHasChanged: (r1, r2) => r1.key != r2.key,
        });

        this.state = {
            filters: [
                {
                    name: 'Boy',
                    isSelect: false,
                },
                {
                    name: 'Girl',
                    isSelect: false,
                },
                {
                    name: 'Kid',
                    isSelect: false,
                },
                {
                    name: 'Lifestyle',
                    isSelect: false,
                },
            ],
            selectedIndex: this.props.selectID,
        };
    }

    _renderRow(rowData, sectionID, rowID) {
        let colorStyle = rowID == this.props.selectID-1 ? {color: '#444444',fontFamily: 'HelveticaNeue',fontSize: 17} : {color: '#b0b0b0',fontFamily: 'HelveticaNeue-Bold',fontSize: 14,};

        return (
            <TouchableOpacity activeOpacity={1} onPress={() => {
                let filters = this.state.filters;
                let filter = this.state.filters[rowID];
                if (this.props.selectID-1 == rowID) {
                    return;
                }

                filter.isSelect = !(filter.isSelect-1);
                filters[rowID] = filter;
                this.props.onChannelPressFliter && this.props.onChannelPressFliter(Number(rowID)+1);
            }}>
                <View key={'row' + rowID} style={styles.rowContainer}>
                    <Text style={[styles.name, colorStyle]}>{rowData.name}</Text>
                </View>
            </TouchableOpacity>
        );
    }

    _renderSeparator(sectionID, rowID, adjacentRowHighlighted) {
        return (
            <View key={'sep' + rowID} style={styles.separator}>
            </View>
        );
    }

    render() {

        let {style} = this.props;

        return (
            <View style={[styles.container, style]}>
                <ListView
                    contentContainerStyle={[styles.contentContainer, style]}
                    enableEmptySections={true}
                    dataSource={this.dataSource.cloneWithRows(this.state.filters)}
                    renderRow={this._renderRow}
                    renderSeparator={this._renderSeparator}
                    scrollEnabled={false}
                    scrollsToTop={false}
                />
            </View>
        );
    }
}

let {width, height} = Dimensions.get('window');

let styles = StyleSheet.create({
    container: {
        marginLeft: -1,
        width: width + 2,
        height: 44,
        borderTopColor: 'transparent',
        borderBottomColor: '#e5e5e5',
        borderWidth: 0.5,
		backgroundColor:'white',
    },
    contentContainer: {
        flexDirection: 'row',
    },
    rowContainer: {
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
        width: Math.ceil(width / 4),
        height: 44,
		backgroundColor:'white',
    },
    name: {
        color: '#b0b0b0',
    },
    separator: {
        width: 0.5,
        top: 44 / 4,
        height: 44 / 2,
        backgroundColor: '#e5e5e5',
    },
});