AsyncDrawable fix no dimensions bug
This commit is contained in:
		
							parent
							
								
									b6b360b736
								
							
						
					
					
						commit
						ca231ab2d8
					
				| @ -23,6 +23,9 @@ public class AsyncDrawable extends Drawable { | ||||
|     private int canvasWidth; | ||||
|     private float textSize; | ||||
| 
 | ||||
|     // @since 2.0.1 for use-cases when image is loaded faster than span is drawn and knows canvas width | ||||
|     private boolean waitingForDemensions; | ||||
| 
 | ||||
|     /** | ||||
|      * @since 1.0.1 | ||||
|      */ | ||||
| @ -88,6 +91,19 @@ public class AsyncDrawable extends Drawable { | ||||
|         this.result = result; | ||||
|         this.result.setCallback(callback); | ||||
| 
 | ||||
|         initBounds(); | ||||
|     } | ||||
| 
 | ||||
|     private void initBounds() { | ||||
| 
 | ||||
|         if (canvasWidth == 0) { | ||||
|             // we still have no bounds - wait for them | ||||
|             waitingForDemensions = true; | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|         waitingForDemensions = false; | ||||
| 
 | ||||
|         final Rect bounds = resolveBounds(); | ||||
|         result.setBounds(bounds); | ||||
|         setBounds(bounds); | ||||
| @ -102,6 +118,10 @@ public class AsyncDrawable extends Drawable { | ||||
|     public void initWithKnownDimensions(int width, float textSize) { | ||||
|         this.canvasWidth = width; | ||||
|         this.textSize = textSize; | ||||
| 
 | ||||
|         if (waitingForDemensions) { | ||||
|             initBounds(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov