history.js 2.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
/**
 * Created by greg on 2016-06-30.
 */

import React, { Component } from 'react';
import {
    Navigator,
    TouchableOpacity,
    TouchableHighlight,
    ScrollView,
    ListView,
    RecyclerViewBackedScrollView,
    Text,
    View
} from 'react-native';
import _ from 'lodash';
//import TimerMixin from 'react-timer-mixin';
//var reactMixin = require('react-mixin');
import styles from '../../styles/styles';


class History extends Component {

    constructor(props) {
        super(props);
        let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
        if(_.isArray(this.props.data)){
            ds = ds.cloneWithRows(this.props.data);
        }
        this.state = {
            dataSource: ds,
        };
    }

    componentDidMount() {}

    componentWillUnmount() {}


    componentWillReceiveProps(newProps) {
        if(newProps && newProps.data && _.isArray(newProps.data)){
            this.setState({
                dataSource: this.state.dataSource.cloneWithRows(newProps.data),
            });
        }
    }


    render() {
        return (
            <ListView
                dataSource={this.state.dataSource}
                renderRow={this._renderRow}
                renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}
            />
        );
    }

    _renderRow(rowData: Object, sectionID: number, rowID: number, highlightRow: (sectionID: number, rowID: number) => void) {
        return (
            <TouchableHighlight onPress={() => {
              //this._pressRow(rowID);
              highlightRow(sectionID, rowID);
            }}>
                <View>
                    <View style={styles.listViewRow}>
                        <Text style={{flex:1,}}>
                            {rowData.value + ' - ' + rowData.startDate}
                        </Text>
                    </View>
                </View>
            </TouchableHighlight>
        );
    }

}

//reactMixin(History.prototype, TimerMixin);


module.exports = History;
export default History;