Commit 1856e05c authored by 李勇諭's avatar 李勇諭

improve layout

parent 6561ee13
...@@ -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}
> >
......
...@@ -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 = `translate3d(0px, ${this.currentY - this.startY}px, 0px)`; 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 = `translate3d(0px, ${this.props.pullDownThreshold}px, 0px)`; 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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment