AsyncDrawable fix no dimensions bug
This commit is contained in:
parent
340ce5753c
commit
fb0faf6dfb
@ -33,6 +33,9 @@ public class AsyncDrawable extends Drawable {
|
|||||||
private int canvasWidth;
|
private int canvasWidth;
|
||||||
private float textSize;
|
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
|
* @since 1.0.1
|
||||||
*/
|
*/
|
||||||
@ -98,6 +101,19 @@ public class AsyncDrawable extends Drawable {
|
|||||||
this.result = result;
|
this.result = result;
|
||||||
this.result.setCallback(callback);
|
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();
|
final Rect bounds = resolveBounds();
|
||||||
result.setBounds(bounds);
|
result.setBounds(bounds);
|
||||||
setBounds(bounds);
|
setBounds(bounds);
|
||||||
@ -112,6 +128,10 @@ public class AsyncDrawable extends Drawable {
|
|||||||
public void initWithKnownDimensions(int width, float textSize) {
|
public void initWithKnownDimensions(int width, float textSize) {
|
||||||
this.canvasWidth = width;
|
this.canvasWidth = width;
|
||||||
this.textSize = textSize;
|
this.textSize = textSize;
|
||||||
|
|
||||||
|
if (waitingForDemensions) {
|
||||||
|
initBounds();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user