<commit_before>'use strict';

import PfText from '../components/PfText'
import Constants from '../Constants'

import * as collectionActions from '../store/collectionReducer'

import React, { Component } from 'react'
import {
  StyleSheet,
  View,
  TouchableHighlight,
  ActivityIndicator,
  ScrollView,
  ListView
} from 'react-native';
import { connect } from 'react-redux';

class ListCollectionsScreen extends Component {

  constructor(props) {
    super(props);

    const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      dataSource: ds.cloneWithRows(props.collections)
    };
  }

  componentWillReceiveProps(nextProps) {
    this.setState({
      dataSource: this.state.dataSource.cloneWithRows(nextProps.collections)
    });
  }

  _renderRow(coll) {
    return (
      <PfText>
        {coll.name} {coll.address} {coll.numBottles} {coll.preferredTimes}
      </PfText>
    );
  }

  render() {
    return (
      <View style={styles.vbox}>
        <PfText>
          Currently available collections:
        </PfText>
        <ListView
            dataSource={this.state.dataSource}
            renderRow={this._renderRow}
            enableEmptySections={true} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  // TODO: DRY
  vbox: {
    flexDirection: 'column',
    alignItems: 'stretch',
    padding: 10,
    marginTop: 60
  },
});

function mapStateToProps(store) {
  return {
    collections: store.collections
  }
}
<commit_msg>Fix two list view bugs<commit_after>'use strict';

import PfText from '../components/PfText'
import Constants from '../Constants'

import * as collectionActions from '../store/collectionReducer'

import React, { Component } from 'react'
import {
  StyleSheet,
  View,
  TouchableHighlight,
  ActivityIndicator,
  ScrollView,
  ListView
} from 'react-native';
import { connect } from 'react-redux';

class ListCollectionsScreen extends Component {

  constructor(props) {
    super(props);

    const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      dataSource: ds.cloneWithRows(props.collections)
    };
  }

  componentWillReceiveProps(nextProps) {
    this.setState({
      dataSource: this.state.dataSource.cloneWithRows(nextProps.collections)
    });
  }

  _renderRow(coll) {
    return (
      <PfText>
        {coll.name} {coll.address} {coll.numBottles} {coll.preferredTimes}
      </PfText>
    );
  }

  render() {
    return (
      <View style={styles.vbox}>
        <PfText>
          Currently available collections:
        </PfText>

        { /* Without removeClippedSubviews, the list view sometimes shows up empty until you scroll,
             see https://productpains.com/post/react-native/listview-doesnt-render-rows-until-scroll/ */ }
        <ListView
            dataSource={this.state.dataSource}
            renderRow={this._renderRow}
            enableEmptySections={true}
            removeClippedSubviews={false}
            style={styles.list} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  // TODO: DRY
  vbox: {
    flexDirection: 'column',
    alignItems: 'stretch',
    justifyContent: 'flex-start',
    padding: 10,
    marginTop: 60,
    flex: 1
  },
  list: {
    flex: 1
  }
});

function mapStateToProps(store) {
  return {
    collections: store.collections
  }
}

{'fraction_non_alphanumeric': 0.1254066844128956, 'fraction_numerical': 0.005323868677905945, 'mean_word_length': 2.7536071032186458, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5145391', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1043, 'n_words': 217}