Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
R
react-pull-to-refresh
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jason.yap
react-pull-to-refresh
Commits
f8adadd1
Commit
f8adadd1
authored
Dec 19, 2017
by
AFOC-1709091830\echou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve animation
parent
b163a558
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
36 deletions
+70
-36
examples/Basic.tsx
examples/Basic.tsx
+34
-0
src/PullToRefresh.tsx
src/PullToRefresh.tsx
+31
-12
src/dev.tsx
src/dev.tsx
+5
-24
No files found.
examples/Basic.tsx
0 → 100644
View file @
f8adadd1
import
*
as
React
from
"
react
"
;
import
{
PullToRefresh
}
from
"
../src
"
;
export
interface
BasicProps
{
}
export
interface
BasicState
{
}
export
class
Basic
extends
React
.
Component
<
BasicProps
,
BasicState
>
{
private
onRefresh
()
{
return
new
Promise
((
resolve
)
=>
{
setTimeout
(
resolve
,
2000
);
});
}
public
render
()
{
return
(
<
div
style=
{
{
overflow
:
"
scroll
"
}
}
>
<
PullToRefresh
pullDownContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
}
}
>
pullDownContent
</
div
>
}
releaseContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
}
}
>
releaseContent
</
div
>
}
refreshContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
,
height
:
"
200px
"
}
}
>
refreshContent
</
div
>
}
pullDownThreshold=
{
200
}
onRefresh=
{
this
.
onRefresh
}
>
<
div
style=
{
{
height
:
"
95vh
"
,
textAlign
:
"
center
"
}
}
>
PullToRefresh
</
div
>
</
PullToRefresh
>
</
div
>
);
}
}
src/PullToRefresh.tsx
View file @
f8adadd1
...
@@ -68,7 +68,6 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -68,7 +68,6 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
this
.
startY
=
e
[
"
pageY
"
]
||
e
.
touches
[
0
].
pageY
;
this
.
startY
=
e
[
"
pageY
"
]
||
e
.
touches
[
0
].
pageY
;
this
.
currentY
=
this
.
startY
;
this
.
currentY
=
this
.
startY
;
this
.
container
.
style
[
"
willChange
"
]
=
"
transform
"
;
this
.
container
.
style
.
transition
=
"
transform 0.2s cubic-bezier(0,0,0.31,1)
"
;
this
.
container
.
style
.
transition
=
"
transform 0.2s cubic-bezier(0,0,0.31,1)
"
;
}
}
...
@@ -89,7 +88,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -89,7 +88,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
});
});
}
}
if
(
this
.
currentY
-
this
.
startY
>
this
.
state
.
maxPullDownDistance
)
{
if
(
this
.
currentY
-
this
.
startY
>
this
.
state
.
maxPullDownDistance
*
1.2
)
{
return
;
return
;
}
}
...
@@ -103,25 +102,43 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -103,25 +102,43 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
this
.
startY
=
0
;
this
.
startY
=
0
;
this
.
currentY
=
0
;
this
.
currentY
=
0
;
if
(
!
this
.
state
.
pullToRefreshThresholdBreached
)
{
this
.
initContainer
();
return
;
}
this
.
container
.
style
.
overflow
=
"
visible
"
;
this
.
container
.
style
.
transform
=
`translate3d(0px,
${
this
.
props
.
pullDownThreshold
}
px, 0px)`
;
this
.
setState
({
this
.
setState
({
pullToRefreshThresholdBreached
:
false
,
pullToRefreshThresholdBreached
:
false
,
onRefreshing
:
true
,
onRefreshing
:
true
,
},
()
=>
{
},
()
=>
{
this
.
props
.
onRefresh
().
then
(()
=>
{
this
.
props
.
onRefresh
().
then
(()
=>
{
this
.
setState
({
onRefreshing
:
false
});
this
.
setState
({
onRefreshing
:
false
});
requestAnimationFrame
(()
=>
{
this
.
initContainer
();
this
.
container
.
style
.
overflow
=
"
auto
"
;
this
.
container
.
style
.
transform
=
"
none
"
;
this
.
container
.
style
[
"
willChange
"
]
=
"
none
"
;
});
});
});
});
});
}
}
private
initContainer
()
{
requestAnimationFrame
(()
=>
{
this
.
container
.
style
.
overflow
=
"
auto
"
;
this
.
container
.
style
.
transform
=
"
none
"
;
});
}
private
renderPullDownContent
()
{
private
renderPullDownContent
()
{
const
{
releaseContent
,
pullDownContent
,
refreshContent
}
=
this
.
props
;
const
{
releaseContent
,
pullDownContent
,
refreshContent
,
pullDownThreshold
}
=
this
.
props
;
const
{
onRefreshing
,
pullToRefreshThresholdBreached
}
=
this
.
state
;
const
{
onRefreshing
,
pullToRefreshThresholdBreached
}
=
this
.
state
;
return
onRefreshing
?
refreshContent
:
pullToRefreshThresholdBreached
?
releaseContent
:
pullDownContent
;
const
content
=
onRefreshing
?
refreshContent
:
pullToRefreshThresholdBreached
?
releaseContent
:
pullDownContent
;
const
contentStyle
:
React
.
CSSProperties
=
{
height
:
`
${
pullDownThreshold
}
px`
,
};
return
(
<
div
style=
{
contentStyle
}
>
{
content
}
</
div
>
);
}
}
public
render
()
{
public
render
()
{
...
@@ -129,7 +146,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -129,7 +146,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
const
containerStyle
:
React
.
CSSProperties
=
{
const
containerStyle
:
React
.
CSSProperties
=
{
height
:
"
auto
"
,
height
:
"
auto
"
,
overflow
:
"
auto
"
,
overflow
:
"
hidden
"
,
WebkitOverflowScrolling
:
"
touch
"
,
WebkitOverflowScrolling
:
"
touch
"
,
};
};
...
@@ -137,7 +154,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -137,7 +154,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
position
:
"
absolute
"
,
position
:
"
absolute
"
,
left
:
0
,
left
:
0
,
right
:
0
,
right
:
0
,
top
:
(
-
1
*
maxPullDownDistance
),
top
:
(
-
maxPullDownDistance
),
};
};
return
(
return
(
...
@@ -147,7 +164,9 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -147,7 +164,9 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
{
this
.
renderPullDownContent
()
}
{
this
.
renderPullDownContent
()
}
</
div
>
</
div
>
</
div
>
</
div
>
{
this
.
props
.
children
}
<
div
style=
{
{
position
:
"
relative
"
,
zIndex
:
1
}
}
>
{
this
.
props
.
children
}
</
div
>
</
div
>
</
div
>
);
);
}
}
...
...
src/dev.tsx
View file @
f8adadd1
...
@@ -2,44 +2,25 @@
...
@@ -2,44 +2,25 @@
import
*
as
React
from
"
react
"
;
import
*
as
React
from
"
react
"
;
import
{
render
}
from
"
react-dom
"
;
import
{
render
}
from
"
react-dom
"
;
import
{
AppContainer
}
from
"
react-hot-loader
"
;
import
{
AppContainer
}
from
"
react-hot-loader
"
;
import
{
PullToRefresh
}
from
"
./PullToRefresh
"
;
import
{
Basic
}
from
"
../examples/Basic
"
;
const
onRefresh
=
()
=>
{
const
renderExample
=
()
=>
{
return
new
Promise
((
reslove
)
=>
{
setTimeout
(
reslove
,
1000
);
});
};
const
renderMasterLayout
=
()
=>
{
const
root
=
document
.
getElementById
(
"
sample
"
);
const
root
=
document
.
getElementById
(
"
sample
"
);
render
(
render
(
<
AppContainer
>
<
AppContainer
>
<
div
>
<
Basic
/>
<
div
>
Header
</
div
>
<
PullToRefresh
pullDownContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
,
height
:
"
200px
"
}
}
>
pullDownContent
</
div
>
}
releaseContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
,
height
:
"
200px
"
}
}
>
releaseContent
</
div
>
}
refreshContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
,
height
:
"
200px
"
}
}
>
refreshContent
</
div
>
}
pullDownThreshold=
{
100
}
onRefresh=
{
onRefresh
}
>
<
div
style=
{
{
backgroundColor
:
"
green
"
,
height
:
"
500px
"
,
color
:
"
white
"
,
textAlign
:
"
center
"
}
}
>
PullToRefresh
</
div
>
</
PullToRefresh
>
</
div
>
</
AppContainer
>,
</
AppContainer
>,
root
,
root
,
);
);
};
};
render
MasterLayout
();
render
Example
();
// Hot Module Replacement API
// Hot Module Replacement API
declare
const
module
:
{
hot
:
any
};
declare
const
module
:
{
hot
:
any
};
if
(
module
.
hot
)
{
if
(
module
.
hot
)
{
module
.
hot
.
accept
(
"
./PullToRefresh
"
,
()
=>
{
module
.
hot
.
accept
(
"
./PullToRefresh
"
,
()
=>
{
render
MasterLayout
();
render
Example
();
});
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment