<commit_before>'use strict'

import Indicator from './Indicator'
import React, { PropTypes } from 'react'
import { View, ScrollView } from 'react-native'

const INDICATOR_HEIGHT = 40

export default class PTRViewiOS extends React.Component {
  constructor () {
    super()
    this.state = {
      expand: -INDICATOR_HEIGHT,
      scroll_offset: 0,
      isLoading: false,
      needPull: true
    }
  }
  _handleScroll (e) {
    var offset = e.nativeEvent.contentOffset.y
    if (!this.state.isLoading) {
      this.setState({scroll_offset: offset})
      this.setState({needPull: offset > -this.props.offset})
    }
  }
  _handleRelease (e) {
    if (this.state.scroll_offset > -this.props.offset) {
      return
    }
    this.setState({
      state: 'laoding',
      isLoading: true
    }, () => {
      this._expander(true)
      this._handleOnRefresh()
    })
  }
  _delay () {
    return new Promise((resolve) => {
      setTimeout(resolve, this.props.delay)
    })
  }
  _handleOnRefresh () {
    return new Promise((resolve) => {
      Promise.all([
        this.props.onRefresh(resolve),
        this._delay()
      ])
        .then(() => {
          this._endLoading()
        })
    })
  }
  _endLoading () {
    this.setState({
      isLoading: false,
      scroll_offset: 0
    })
    this._expander(false)
  }
  _expander (is_expand) {
    var that = this
    var threshold = -INDICATOR_HEIGHT
    var n = -5

    if (is_expand) {
      threshold = 5
      n = 1
    }

    (function loop () {
      var animation = requestAnimationFrame(loop)<commit_msg>fix "drift" caused by repeated refreshing<commit_after>'use strict'

import Indicator from './Indicator'
import React, { PropTypes } from 'react'
import { View, ScrollView } from 'react-native'

const INDICATOR_HEIGHT = 40

export default class PTRViewiOS extends React.Component {
  constructor () {
    super()
    this.state = {
      expand: -INDICATOR_HEIGHT,
      scroll_offset: 0,
      isLoading: false,
      needPull: true
    }
  }
  _handleScroll (e) {
    var offset = e.nativeEvent.contentOffset.y
    if (!this.state.isLoading) {
      this.setState({scroll_offset: offset})
      this.setState({needPull: offset > -this.props.offset})
    }
  }
  _handleRelease (e) {
    if (this.state.scroll_offset > -this.props.offset) {
      return
    }
    this.setState({
      state: 'laoding',
      isLoading: true
    }, () => {
      this._expander(true)
      this._handleOnRefresh()
    })
  }
  _delay () {
    return new Promise((resolve) => {
      setTimeout(resolve, this.props.delay)
    })
  }
  _handleOnRefresh () {
    return new Promise((resolve) => {
      Promise.all([
        this.props.onRefresh(resolve),
        this._delay()
      ])
        .then(() => {
          this._endLoading()
        })
    })
  }
  _endLoading () {
    this.setState({
      isLoading: false,
      scroll_offset: 0,
      expand: -INDICATOR_HEIGHT
    })
    this._expander(false)
  }
  _expander (is_expand) {
    var that = this
    var threshold = -INDICATOR_HEIGHT
    var n = -5

    if (is_expand) {
      threshold = 5
      n = 1
    }

    (function loop () {
      var animation = requestAnimationFrame(loop)
{'fraction_non_alphanumeric': 0.12589815682599187, 'fraction_numerical': 0.0043736332396126214, 'mean_word_length': 2.2706843718079672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4412589', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1031, 'n_words': 216}