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
1856e05c
Commit
1856e05c
authored
Dec 21, 2017
by
李勇諭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve layout
parent
6561ee13
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
26 deletions
+25
-26
examples/Basic.tsx
examples/Basic.tsx
+3
-3
src/PullToRefresh.tsx
src/PullToRefresh.tsx
+22
-23
No files found.
examples/Basic.tsx
View file @
1856e05c
...
@@ -18,9 +18,9 @@ export class Basic extends React.Component<BasicProps, BasicState> {
...
@@ -18,9 +18,9 @@ export class Basic extends React.Component<BasicProps, BasicState> {
return
(
return
(
<
div
style=
{
{
overflow
:
"
scroll
"
}
}
>
<
div
style=
{
{
overflow
:
"
scroll
"
}
}
>
<
PullToRefresh
<
PullToRefresh
pullDownContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
}
}
>
pullDownContent
</
div
>
}
pullDownContent=
{
<
div
style=
{
{
backgroundColor
:
"
grey
"
,
height
:
"
200px
"
,
textAlign
:
"
center
"
}
}
>
Pull down to refresh
</
div
>
}
releaseContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
}
}
>
releaseContent
</
div
>
}
releaseContent=
{
<
div
style=
{
{
backgroundColor
:
"
green
"
,
height
:
"
200px
"
,
textAlign
:
"
center
"
}
}
>
Release to refresh
</
div
>
}
refreshContent=
{
<
div
style=
{
{
backgroundColor
:
"
red
"
,
height
:
"
200px
"
}
}
>
refreshContent
</
div
>
}
refreshContent=
{
<
div
style=
{
{
backgroundColor
:
"
yellow
"
,
height
:
"
200px
"
,
textAlign
:
"
center
"
}
}
>
Refreshing
</
div
>
}
pullDownThreshold=
{
200
}
pullDownThreshold=
{
200
}
onRefresh=
{
this
.
onRefresh
}
onRefresh=
{
this
.
onRefresh
}
>
>
...
...
src/PullToRefresh.tsx
View file @
1856e05c
...
@@ -69,6 +69,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -69,6 +69,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
this
.
currentY
=
this
.
startY
;
this
.
currentY
=
this
.
startY
;
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)
"
;
this
.
pullDown
.
style
.
transition
=
"
transform 0.2s cubic-bezier(0,0,0.31,1)
"
;
}
}
@
autobind
@
autobind
...
@@ -93,7 +94,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -93,7 +94,7 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
}
}
this
.
container
.
style
.
overflow
=
"
visible
"
;
this
.
container
.
style
.
overflow
=
"
visible
"
;
this
.
container
.
style
.
transform
=
`translate
3d(0px,
${
this
.
currentY
-
this
.
startY
}
px, 0
px)`
;
this
.
container
.
style
.
transform
=
`translate
(0px,
${
this
.
currentY
-
this
.
startY
}
px)`
;
}
}
@
autobind
@
autobind
...
@@ -108,14 +109,18 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -108,14 +109,18 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
}
}
this
.
container
.
style
.
overflow
=
"
visible
"
;
this
.
container
.
style
.
overflow
=
"
visible
"
;
this
.
container
.
style
.
transform
=
`translate
3d(0px,
${
this
.
props
.
pullDownThreshold
}
px, 0
px)`
;
this
.
container
.
style
.
transform
=
`translate
(0px,
${
this
.
props
.
pullDownThreshold
}
px)`
;
this
.
setState
({
this
.
setState
({
pullToRefreshThresholdBreached
:
false
,
onRefreshing
:
true
,
onRefreshing
:
true
,
},
()
=>
{
},
()
=>
{
this
.
props
.
onRefresh
().
then
(()
=>
{
this
.
props
.
onRefresh
().
then
(()
=>
{
this
.
setState
({
onRefreshing
:
false
});
this
.
initContainer
();
this
.
initContainer
();
setTimeout
(()
=>
{
this
.
setState
({
onRefreshing
:
false
,
pullToRefreshThresholdBreached
:
false
,
});
},
200
);
});
});
});
});
}
}
...
@@ -128,43 +133,37 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
...
@@ -128,43 +133,37 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
}
}
private
renderPullDownContent
()
{
private
renderPullDownContent
()
{
const
{
releaseContent
,
pullDownContent
,
refreshContent
,
pullDownThreshold
}
=
this
.
props
;
const
{
releaseContent
,
pullDownContent
,
refreshContent
}
=
this
.
props
;
const
{
onRefreshing
,
pullToRefreshThresholdBreached
}
=
this
.
state
;
const
{
onRefreshing
,
pullToRefreshThresholdBreached
}
=
this
.
state
;
const
content
=
onRefreshing
?
refreshContent
:
pullToRefreshThresholdBreached
?
releaseContent
:
pullDownContent
;
const
content
=
onRefreshing
?
refreshContent
:
pullToRefreshThresholdBreached
?
releaseContent
:
pullDownContent
;
const
contentStyle
:
React
.
CSSProperties
=
{
const
contentStyle
:
React
.
CSSProperties
=
{
height
:
`
${
pullDownThreshold
}
px`
,
position
:
"
absolute
"
,
overflow
:
"
hidden
"
,
left
:
0
,
right
:
0
,
top
:
0
,
};
};
return
(
return
(
<
div
style=
{
contentStyle
}
>
<
div
style=
{
contentStyle
}
ref=
{
this
.
pullDownRef
}
>
{
content
}
{
content
}
</
div
>
</
div
>
);
);
}
}
public
render
()
{
public
render
()
{
const
{
maxPullDownDistance
}
=
this
.
state
;
const
containerStyle
:
React
.
CSSProperties
=
{
const
containerStyle
:
React
.
CSSProperties
=
{
height
:
"
auto
"
,
height
:
"
auto
"
,
overflow
:
"
hidden
"
,
overflow
:
"
hidden
"
,
WebkitOverflowScrolling
:
"
touch
"
,
WebkitOverflowScrolling
:
"
touch
"
,
};
position
:
"
relative
"
,
zIndex
:
1
,
const
pullContentStyles
:
React
.
CSSProperties
=
{
backgroundColor
:
"
white
"
,
position
:
"
absolute
"
,
left
:
0
,
right
:
0
,
top
:
(
-
maxPullDownDistance
),
};
};
return
(
return
(
<
div
ref=
{
this
.
containerRef
}
style=
{
containerStyle
}
>
<
div
style=
{
containerStyle
}
>
<
div
ref=
{
this
.
pullDownRef
}
style=
{
{
position
:
"
relative
"
}
}
>
<
div
style=
{
pullContentStyles
}
>
{
this
.
renderPullDownContent
()
}
{
this
.
renderPullDownContent
()
}
</
div
>
<
div
ref=
{
this
.
containerRef
}
style=
{
containerStyle
}
>
</
div
>
<
div
style=
{
{
position
:
"
relative
"
,
zIndex
:
1
}
}
>
{
this
.
props
.
children
}
{
this
.
props
.
children
}
</
div
>
</
div
>
</
div
>
</
div
>
...
...
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