Skip to content

Commit

Permalink
fix preact diff error, ref ant-design/ant-design-mobile#1839
Browse files Browse the repository at this point in the history
  • Loading branch information
warmhug committed Oct 11, 2017
1 parent 92fa054 commit 40875f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}
transform-origin: left top 0px;
}

&-transition {
transition: transform 0.3s;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rmc-pull-to-refresh",
"version": "1.0.0-alpha.2",
"version": "1.0.0-alpha.3",
"description": "React Mobile Pull To Refresh Component",
"keywords": [
"react",
Expand Down
13 changes: 7 additions & 6 deletions src/PullToRefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
componentDidMount() {
// `getScrollContainer` most likely return React.Node at the next tick. Need setTimeout
setTimeout(() => {
this.initPullUp(this.props.getScrollContainer() || this.containerRef);
this.init(this.props.getScrollContainer() || this.containerRef);
this.triggerPullToRefresh();
});
}

componentWillUnmount() {
// Should have no setTimeout here!
this.destroyPullUp(this.props.getScrollContainer() || this.containerRef);
this.destroy(this.props.getScrollContainer() || this.containerRef);
}

triggerPullToRefresh = () => {
Expand All @@ -77,7 +77,7 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
}
}

initPullUp = (ele: any) => {
init = (ele: any) => {
this._to = {
touchstart: this.onTouchStart.bind(this, ele),
touchmove: this.onTouchMove.bind(this, ele),
Expand All @@ -89,7 +89,7 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
});
}

destroyPullUp = (ele: any) => {
destroy = (ele: any) => {
Object.keys(this._to).forEach(key => {
ele.removeEventListener(key, this._to[key]);
});
Expand Down Expand Up @@ -183,13 +183,14 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
direction, onRefresh, refreshing, indicator, distanceToRefresh, ...restProps,
} = this.props;

// set key="content" and key="indicator" for preact. Otherwise it will be diff wrong.
const renderRefresh = (cls: string) => {
const cla = classNames(cls, !this.state.dragOnEdge && `${prefixCls}-transition`);
return (
<div className={`${prefixCls}-content-wrapper`}>
<div className={cla} ref={el => this.contentRef = el}>
<div className={cla} ref={el => this.contentRef = el} key="content">
{direction === UP ? children : null}
<div className={`${prefixCls}-indicator`}>
<div className={`${prefixCls}-indicator`} key="indicator">
{(indicator as any)[this.state.currSt] || (INDICATOR as any)[this.state.currSt]}
</div>
{direction === DOWN ? children : null}
Expand Down

0 comments on commit 40875f3

Please sign in to comment.