// Copyright 2004-present Facebook. All Rights Reserved.

package com.facebook.react.views.toolbar;

import android.graphics.drawable.Drawable;

import com.facebook.drawee.drawable.ForwardingDrawable;
import com.facebook.imagepipeline.image.ImageInfo;
import com.facebook.react.uimanager.PixelUtil;

/**
 * Fresco currently sets drawables' intrinsic size to (-1, -1). This is to guarantee that scaling is
 * performed correctly. In the case of the Toolbar, we don't have access to the widget's internal
 * ImageView, which has width/height set to WRAP_CONTENT, which relies on intrinsic size.
 *
 * To work around this we have this class which just wraps another Drawable, but returns the correct
 * dimensions in getIntrinsicWidth/Height. This makes WRAP_CONTENT work in Toolbar's internals.
 *
 * This drawable uses the size of a loaded image to determine the intrinsic size. It therefore can't
 * be used safely until *after* an image has loaded, and must be replaced when the image is
 * replaced.
 */
public class DrawableWithIntrinsicSize extends ForwardingDrawable implements Drawable.Callback {

  private final ImageInfo mImageInfo;

  public DrawableWithIntrinsicSize(Drawable drawable, ImageInfo imageInfo) {
    super(drawable);
    mImageInfo = imageInfo;
  }

  @Override
  public int getIntrinsicWidth() {
    return (int) PixelUtil.toDIPFromPixel(mImageInfo.getWidth());
  }

  @Override
  public int getIntrinsicHeight() {
    return (int) PixelUtil.toDIPFromPixel(mImageInfo.getHeight());
  }

}

@@ -1329,39 +1329,8 @@
 urn 
-(int) PixelUtil.toDIPFromPixel(
 mIma
@@ -1346,17 +1346,16 @@
 tWidth()
-)
 ;%0A  %7D%0A%0A 
@@ -1416,39 +1416,8 @@
 urn 
-(int) PixelUtil.toDIPFromPixel(
 mIma
@@ -1434,17 +1434,16 @@
 Height()
-)
 ;%0A  %7D%0A%0A%7D

remove extraneous dimension conversion