1+ import  {  getObserver  }  from  '../common/wechat' ; 
12import  {  RelationsOptions ,  SuperComponent ,  wxComponent  }  from  '../common/src/index' ; 
23import  config  from  '../common/config' ; 
34import  props  from  './props' ; 
@@ -70,11 +71,7 @@ export default class PullDownRefresh extends SuperComponent {
7071
7172      this . pixelRatio  =  750  /  screenWidth ; 
7273
73-       getRect ( this ,  `.${ name }  ) . then ( ( rect )  =>  { 
74-         this . setData ( { 
75-           distanceTop : rect . top , 
76-         } ) ; 
77-       } ) ; 
74+       this . updateDistanceTop ( ) ; 
7875    } , 
7976
8077    detached ( )  { 
@@ -119,6 +116,27 @@ export default class PullDownRefresh extends SuperComponent {
119116  } ; 
120117
121118  methods  =  { 
119+     updateDistanceTop ( )  { 
120+       const  update  =  ( top : number )  =>  { 
121+         this . setData ( { 
122+           distanceTop : top , 
123+         } ) ; 
124+       } ; 
125+ 
126+       getRect ( this ,  `.${ name }  ) . then ( ( rect )  =>  { 
127+         if  ( rect . top )  { 
128+           update ( rect . top ) ; 
129+           return ; 
130+         } 
131+ 
132+         getObserver ( this ,  `.${ name }  ) . then ( ( res )  =>  { 
133+           if  ( res . intersectionRatio  >  0 )  { 
134+             update ( res . boundingClientRect . top ) ; 
135+           } 
136+         } ) ; 
137+       } ) ; 
138+     } , 
139+ 
122140    resetTimer ( )  { 
123141      if  ( this . refreshStatusTimer )  { 
124142        clearTimeout ( this . refreshStatusTimer ) ; 
@@ -129,11 +147,13 @@ export default class PullDownRefresh extends SuperComponent {
129147    onScrollToBottom ( )  { 
130148      this . triggerEvent ( 'scrolltolower' ) ; 
131149    } , 
150+ 
132151    onScrollToTop ( )  { 
133152      this . setData ( { 
134153        enableToRefresh : true , 
135154      } ) ; 
136155    } , 
156+ 
137157    onScroll ( e )  { 
138158      const  {  scrollTop }  =  e . detail ; 
139159
@@ -142,6 +162,7 @@ export default class PullDownRefresh extends SuperComponent {
142162      } ) ; 
143163      this . triggerEvent ( 'scroll' ,  {  scrollTop } ) ; 
144164    } , 
165+ 
145166    onTouchStart ( e : WechatMiniprogram . Component . TrivialInstance )  { 
146167      if  ( this . isPulling  ||  ! this . data . enableToRefresh  ||  this . properties . disabled )  return ; 
147168      const  {  touches }  =  e ; 
0 commit comments