1
- import React from 'react' ;
2
1
import classNames from 'classnames' ;
3
- import { PropsType , Indicator } from './PropsType' ;
4
-
5
- class StaticRenderer extends React . Component < any , any > {
6
- shouldComponentUpdate ( nextProps : any ) {
7
- return nextProps . shouldUpdate ;
8
- }
9
- render ( ) {
10
- return < div > { this . props . render ( ) } </ div > ;
11
- }
12
- }
2
+ import * as React from 'react' ;
3
+ import { IPropsType } from './PropsType' ;
4
+ import StaticRenderer from './StaticRenderer' ;
13
5
14
6
function setTransform ( nodeStyle : any , value : any ) {
15
7
nodeStyle . transform = value ;
@@ -37,20 +29,27 @@ try {
37
29
const willPreventDefault = supportsPassive ? { passive : false } : false ;
38
30
// const willNotPreventDefault = supportsPassive ? { passive: true } : false;
39
31
40
- export default class PullToRefresh extends React . Component < PropsType , any > {
32
+ type ICurrSt = 'activate' | 'deactivate' | 'release' | 'finish' ;
33
+
34
+ interface IState {
35
+ currSt : ICurrSt ;
36
+ dragOnEdge : boolean ;
37
+ }
38
+
39
+ export default class PullToRefresh extends React . Component < IPropsType , IState > {
41
40
static defaultProps = {
42
41
prefixCls : 'rmc-pull-to-refresh' ,
43
42
getScrollContainer : ( ) => undefined ,
44
43
direction : DOWN ,
45
44
distanceToRefresh : 25 ,
46
45
damping : 100 ,
47
- indicator : INDICATOR as Indicator ,
48
- } as PropsType ;
46
+ indicator : INDICATOR ,
47
+ } ;
49
48
50
49
// https://github.com/yiminghe/zscroller/blob/2d97973287135745818a0537712235a39a6a62a1/src/Scroller.js#L355
51
50
// currSt: `activate` / `deactivate` / `release` / `finish`
52
51
state = {
53
- currSt : 'deactivate' ,
52
+ currSt : 'deactivate' as ICurrSt ,
54
53
dragOnEdge : false ,
55
54
} ;
56
55
@@ -163,6 +162,8 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
163
162
if ( direction === DOWN ) {
164
163
return ele . scrollTop <= 0 ;
165
164
}
165
+ // 补全 branch, test 才过的了,但是实际上代码永远不会走到这里,这里为了保证代码的一致性,返回 undefined
166
+ return undefined ;
166
167
}
167
168
168
169
damping = ( dy : number ) : number => {
@@ -263,7 +264,7 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
263
264
264
265
const {
265
266
className, prefixCls, children, getScrollContainer,
266
- direction, onRefresh, refreshing, indicator, distanceToRefresh, ...restProps ,
267
+ direction, onRefresh, refreshing, indicator, distanceToRefresh, ...restProps
267
268
} = props ;
268
269
269
270
const renderChildren = < StaticRenderer
@@ -276,7 +277,7 @@ export default class PullToRefresh extends React.Component<PropsType, any> {
276
277
< div className = { cla } ref = { el => this . contentRef = el } >
277
278
{ direction === UP ? renderChildren : null }
278
279
< div className = { `${ prefixCls } -indicator` } >
279
- { ( indicator as any ) [ this . state . currSt ] || ( INDICATOR as any ) [ this . state . currSt ] }
280
+ { indicator [ this . state . currSt ] || INDICATOR [ this . state . currSt ] }
280
281
</ div >
281
282
{ direction === DOWN ? renderChildren : null }
282
283
</ div >
0 commit comments