mirror of
				https://gitee.com/vant-contrib/vant.git
				synced 2025-10-27 01:32:10 +08:00 
			
		
		
		
	fix(PullRefresh): may trigger browser bounce in some cases (#10090)
This commit is contained in:
		
							parent
							
								
									63e25b05d6
								
							
						
					
					
						commit
						9c16a6ad2b
					
				| @ -1,13 +1,11 @@ | |||||||
| import { on } from '../utils/dom/event'; | import { on } from '../utils/dom/event'; | ||||||
| 
 | 
 | ||||||
| const MIN_DISTANCE = 10; |  | ||||||
| 
 |  | ||||||
| function getDirection(x, y) { | function getDirection(x, y) { | ||||||
|   if (x > y && x > MIN_DISTANCE) { |   if (x > y) { | ||||||
|     return 'horizontal'; |     return 'horizontal'; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   if (y > x && y > MIN_DISTANCE) { |   if (y > x) { | ||||||
|     return 'vertical'; |     return 'vertical'; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -28,13 +26,21 @@ export const TouchMixin = { | |||||||
| 
 | 
 | ||||||
|     touchMove(event) { |     touchMove(event) { | ||||||
|       const touch = event.touches[0]; |       const touch = event.touches[0]; | ||||||
|       // Fix: Safari back will set clientX to negative number
 |       // safari back will set clientX to negative number
 | ||||||
|       this.deltaX = touch.clientX < 0 ? 0 : touch.clientX - this.startX; |       this.deltaX = touch.clientX < 0 ? 0 : touch.clientX - this.startX; | ||||||
|       this.deltaY = touch.clientY - this.startY; |       this.deltaY = touch.clientY - this.startY; | ||||||
|       this.offsetX = Math.abs(this.deltaX); |       this.offsetX = Math.abs(this.deltaX); | ||||||
|       this.offsetY = Math.abs(this.deltaY); |       this.offsetY = Math.abs(this.deltaY); | ||||||
|       this.direction = | 
 | ||||||
|         this.direction || getDirection(this.offsetX, this.offsetY); |       // lock direction when distance is greater than a certain value
 | ||||||
|  |       const LOCK_DIRECTION_DISTANCE = 10; | ||||||
|  |       if ( | ||||||
|  |         !this.direction || | ||||||
|  |         (this.offsetX < LOCK_DIRECTION_DISTANCE && | ||||||
|  |           this.offsetY < LOCK_DIRECTION_DISTANCE) | ||||||
|  |       ) { | ||||||
|  |         this.direction = getDirection(this.offsetX, this.offsetY); | ||||||
|  |       } | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     resetTouchStatus() { |     resetTouchStatus() { | ||||||
|  | |||||||
| @ -210,16 +210,8 @@ export default createComponent({ | |||||||
| 
 | 
 | ||||||
|       this.touchMove(event); |       this.touchMove(event); | ||||||
| 
 | 
 | ||||||
|       // if user starting to touchmove, prevent the event bubbling to
 |  | ||||||
|       // avoid affecting the parent components
 |  | ||||||
|       const shouldPrevent = |  | ||||||
|         this.isCorrectDirection || |  | ||||||
|         this.offsetY > this.offsetX === this.vertical; |  | ||||||
|       if (shouldPrevent) { |  | ||||||
|         preventDefault(event, this.stopPropagation); |  | ||||||
|       } |  | ||||||
| 
 |  | ||||||
|       if (this.isCorrectDirection) { |       if (this.isCorrectDirection) { | ||||||
|  |         preventDefault(event, this.stopPropagation); | ||||||
|         this.move({ offset: this.delta }); |         this.move({ offset: this.delta }); | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user