Commit 224b0118 authored by 李勇諭's avatar 李勇諭

improve pull region

parent f21d1ea7
...@@ -25,7 +25,7 @@ export class Basic extends React.Component<BasicProps, BasicState> { ...@@ -25,7 +25,7 @@ export class Basic extends React.Component<BasicProps, BasicState> {
onRefresh={this.onRefresh} onRefresh={this.onRefresh}
> >
<div style={{height: "95vh", textAlign: "center"}}> <div style={{height: "95vh", textAlign: "center"}}>
PullToRefresh <div onClick={console.log}>PullToRefresh</div>
</div> </div>
</PullToRefresh> </PullToRefresh>
</div> </div>
......
...@@ -51,29 +51,32 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef ...@@ -51,29 +51,32 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
} }
public componentDidMount(): void { public componentDidMount(): void {
this.pullTag.addEventListener("touchstart", this.onTouchStart); this.container.addEventListener("touchstart", this.onTouchStart);
this.container.addEventListener("touchmove", this.onTouchMove); this.container.addEventListener("touchmove", this.onTouchMove);
this.container.addEventListener("touchend", this.onEnd); this.container.addEventListener("touchend", this.onEnd);
this.pullTag.addEventListener("mousedown", this.onTouchStart); this.container.addEventListener("mousedown", this.onTouchStart);
this.container.addEventListener("mousemove", this.onTouchMove); this.container.addEventListener("mousemove", this.onTouchMove);
this.container.addEventListener("mouseup", this.onEnd); this.container.addEventListener("mouseup", this.onEnd);
} }
public componentWillUnmount(): void { public componentWillUnmount(): void {
this.pullTag.removeEventListener("touchstart", this.onTouchStart); this.container.removeEventListener("touchstart", this.onTouchStart);
this.container.removeEventListener("touchmove", this.onTouchMove); this.container.removeEventListener("touchmove", this.onTouchMove);
this.container.removeEventListener("touchend", this.onEnd); this.container.removeEventListener("touchend", this.onEnd);
this.pullTag.removeEventListener("mousedown", this.onTouchStart); this.container.removeEventListener("mousedown", this.onTouchStart);
this.container.removeEventListener("mousemove", this.onTouchMove); this.container.removeEventListener("mousemove", this.onTouchMove);
this.container.removeEventListener("mouseup", this.onEnd); this.container.removeEventListener("mouseup", this.onEnd);
} }
@autobind @autobind
private onTouchStart(e) { private onTouchStart(e) {
this.dragging = true;
this.startY = e["pageY"] || e.touches[0].pageY; this.startY = e["pageY"] || e.touches[0].pageY;
this.currentY = this.startY; this.currentY = this.startY;
if (this.startY > 40) {
return;
}
this.dragging = true;
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)"; this.pullDown.style.transition = "transform 0.2s cubic-bezier(0,0,0.31,1)";
} }
...@@ -166,19 +169,10 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef ...@@ -166,19 +169,10 @@ export class PullToRefresh extends React.Component<PullToRefreshProps, PullToRef
backgroundColor: "white", backgroundColor: "white",
}; };
const pullHiddenTagStyle: React.CSSProperties = {
height: "50px",
width: "100%",
position: "absolute",
top: 0,
zIndex: 100,
};
return ( return (
<div style={containerStyle}> <div style={containerStyle}>
{this.renderPullDownContent()} {this.renderPullDownContent()}
<div ref={this.containerRef} style={containerStyle}> <div ref={this.containerRef} style={containerStyle}>
<div ref={this.pullTagRef} style={pullHiddenTagStyle} />
{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