<commit_before>/**
 * @flow
 */
'use strict';

let React = require('react-native');
let ScrollableMixin = require('react-native-scrollable-mixin');
let {
  PropTypes,
  ScrollView,
} = React;

let DefaultLoadingIndicator = require('./DefaultLoadingIndicator');

let InfiniteScrollView = React.createClass({
  mixins: [ScrollableMixin],

  propTypes: {
    ...ScrollView.propTypes,
    distanceToLoadMore: PropTypes.number.isRequired,
    canLoadMore: PropTypes.bool.isRequired,
    isLoadingMore: PropTypes.bool.isRequired,
    onLoadMore: PropTypes.func.isRequired,
    renderLoadingIndicator: PropTypes.func.isRequired,
    renderScrollComponent: PropTypes.func.isRequired,
  },

  getDefaultProps() {
    return {
      distanceToLoadMore: 1000,
      canLoadMore: false,
      scrollEventThrottle: 100,
      renderLoadingIndicator: () => <DefaultLoadingIndicator />,
      renderScrollComponent: props => <ScrollView {...props} />,
    };
  },

  getScrollResponder(): ReactComponent {
    return this._scrollComponent.getScrollResponder();
  },

  setNativeProps(props) {
    this._scrollComponent.setNativeProps(props);
  },

  render() {
    if (this.props.isLoadingMore) {
      var loadingIndicator = this.props.renderLoadingIndicator();
    }

    let {
      renderScrollComponent,
      ...props,
    } = this.props;
    Object.assign(props, {
      onScroll: this._handleScroll,
      children: [this.props.children, loadingIndicator],
    });

    let scrollComponent = renderScrollComponent(props);
    let originalRef = scrollComponent.ref;
    if (originalRef != null && typeof originalRef !== 'function') {
      console.warn(
        'String refs are not supported for composed scroll components. Use a ' +
        'callback ref instead. Ignoring ref: ' + originalRef
      );
      originalRef = null;
    }

    return React.cloneElement(renderScrollComponent(props), {
      ref: component => {
        this._scrollComponent = component;
        if (originalRef) {
          originalRef(component);
        }
      },
    });
  },

  _handleScroll(event) {
    if (this.props.onScroll) {
      this.props.onScroll(event);<commit_msg>Use cloneReferencedElement to preserve ref, add key to loading indicator<commit_after>/**
 * @flow
 */
'use strict';

let React = require('react-native');
let ScrollableMixin = require('react-native-scrollable-mixin');
let {
  PropTypes,
  ScrollView,
} = React;

let cloneReferencedElement = require('react-native-clone-referenced-element');

let DefaultLoadingIndicator = require('./DefaultLoadingIndicator');

let InfiniteScrollView = React.createClass({
  mixins: [ScrollableMixin],

  propTypes: {
    ...ScrollView.propTypes,
    distanceToLoadMore: PropTypes.number.isRequired,
    canLoadMore: PropTypes.bool.isRequired,
    isLoadingMore: PropTypes.bool.isRequired,
    onLoadMore: PropTypes.func.isRequired,
    renderLoadingIndicator: PropTypes.func.isRequired,
  },

  getDefaultProps() {
    return {
      distanceToLoadMore: 1000,
      canLoadMore: false,
      scrollEventThrottle: 100,
      renderLoadingIndicator: () => <DefaultLoadingIndicator />,
      renderScrollComponent: props => <ScrollView {...props} />,
    };
  },

  getScrollResponder(): ReactComponent {
    return this._scrollComponent.getScrollResponder();
  },

  setNativeProps(props) {
    this._scrollComponent.setNativeProps(props);
  },

  render() {
    if (this.props.isLoadingMore) {
      var loadingIndicator = React.cloneElement(
        this.props.renderLoadingIndicator(),
        { key: 'loading-indicator' },
      );
    }

    let {
      renderScrollComponent,
      ...props,
    } = this.props;
    Object.assign(props, {
      onScroll: this._handleScroll,
      children: [this.props.children, loadingIndicator],
    });

    return cloneReferencedElement(renderScrollComponent(props), {
      ref: component => { this._scrollComponent = component; },
    });
  },

  _handleScroll(event) {
    if (this.props.onScroll) {
      this.props.onScroll(event);
{'fraction_non_alphanumeric': 0.12164179104477611, 'fraction_numerical': 0.003482587064676617, 'mean_word_length': 3.3659066232356136, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '1639421', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1166, 'n_words': 211}