Skip to content
This repository has been archived by the owner on Nov 27, 2021. It is now read-only.

Commit

Permalink
fix pulling amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuke Shibata committed Nov 25, 2017
1 parent 82797d0 commit ec25449
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
44 changes: 23 additions & 21 deletions src/component/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import { clamp } from 'lodash'
import { StyleSheet, css } from 'aphrodite'

const styles = StyleSheet.create({
Expand All @@ -23,25 +22,28 @@ const styles = StyleSheet.create({
}
})

export default (props, state, children) => [
<div
key='pull'
className={css(
styles.comp,
state.refreshing && styles.refreshing,
state.refreshed && styles.refreshed,
state.willRefresh && styles.willRefresh
)}
style={{
height: clamp(state.y, 0, props.max)
}}
>
{ state.refreshing && 'refreshing :' }
{ state.refreshed && 'refreshed :' }
{ state.willRefresh && 'willRefresh :' }
{ parseInt(state.y, 10) }
</div>,
children
]
export default (props, state, children) => {
const p = Math.atan(state.y / props.max)
return [
<div
key='pull'
className={css(
styles.comp,
state.refreshing && styles.refreshing,
state.refreshed && styles.refreshed,
state.willRefresh && styles.willRefresh
)}
style={{
height: Math.max(p * props.max, 0)
}}
>
{ state.refreshing && 'refreshing :' }
{ state.refreshed && 'refreshed :' }
{ state.willRefresh && 'willRefresh :' }
{ parseInt(state.y, 10) }
</div>,
children
]
}


4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Spring from './spring'
import { clamp } from 'lodash'
import scrollTop from './scrollTop'
import defaultRender from './component'

Expand Down Expand Up @@ -40,12 +39,11 @@ export default class PullRefresh extends Component {
}
}
onMove(evt) {
const { max } = this.props
const { refreshed, refreshing } = this.state
if(!this._down || refreshed || refreshing) return
const ey = evt.touches ? evt.touches[0].pageY : evt.pageY
if(scrollTop(this) <= 0) {
this._y = clamp(this._y + ey - this._py, 0, max + 10)
this._y = this._y + ey - this._py
this._spring.endValue = this._y
}
this._py = ey
Expand Down

0 comments on commit ec25449

Please sign in to comment.