Skip to content

Commit

Permalink
Move ScalingUtils and ScaleType to Fresco ui-core module
Browse files Browse the repository at this point in the history
Reviewed By: steelrooter

Differential Revision: D59807566

fbshipit-source-id: 019499f960bafd95963e7bb435215339100c504a
  • Loading branch information
oprisnik authored and facebook-github-bot committed Jul 17, 2024
1 parent 700e094 commit 2eb960b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
1 change: 1 addition & 0 deletions drawee-backends/drawee-pipeline/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation project (':soloader')
implementation Deps.SoLoader.nativeloader
implementation project(':ui-common')
implementation project(':ui-core')
implementation project(':middleware')

api project(':fbcore')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import com.facebook.drawee.debug.DebugControllerOverlayDrawable;
import com.facebook.drawee.debug.listener.ImageLoadingTimeControllerListener;
import com.facebook.drawee.drawable.ArrayDrawable;
import com.facebook.drawee.drawable.DrawableParent;
import com.facebook.drawee.drawable.ScaleTypeDrawable;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.drawable.ScalingUtils.ScaleType;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.interfaces.DraweeHierarchy;
Expand Down Expand Up @@ -335,7 +336,7 @@ protected void updateDebugOverlay(
ScaleType scaleType = null;
if (draweeHierarchy != null) {
final ScaleTypeDrawable scaleTypeDrawable =
ScalingUtils.getActiveScaleTypeDrawable(draweeHierarchy.getTopLevelDrawable());
getActiveScaleTypeDrawable(draweeHierarchy.getTopLevelDrawable());
scaleType = scaleTypeDrawable != null ? scaleTypeDrawable.getScaleType() : null;
}
debugOverlay.setScaleType(scaleType);
Expand Down Expand Up @@ -445,4 +446,28 @@ public String toString() {
}
return cc.toString();
}

@Nullable
public static ScaleTypeDrawable getActiveScaleTypeDrawable(@Nullable Drawable drawable) {
if (drawable == null) {
return null;
} else if (drawable instanceof ScaleTypeDrawable) {
return (ScaleTypeDrawable) drawable;
} else if (drawable instanceof DrawableParent) {
final Drawable childDrawable = ((DrawableParent) drawable).getDrawable();
return getActiveScaleTypeDrawable(childDrawable);
} else if (drawable instanceof ArrayDrawable) {
final ArrayDrawable fadeDrawable = (ArrayDrawable) drawable;
final int numLayers = fadeDrawable.getNumberOfLayers();

for (int i = 0; i < numLayers; i++) {
final Drawable childDrawable = fadeDrawable.getDrawable(i);
final ScaleTypeDrawable result = getActiveScaleTypeDrawable(childDrawable);
if (result != null) {
return result;
}
}
}
return null;
}
}
3 changes: 2 additions & 1 deletion drawee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ dependencies {
compileOnly Deps.jsr305
compileOnly Deps.javaxAnnotation

api project(':ui-core')

implementation project(':fbcore')
implementation project(':imagepipeline')
implementation project(':imagepipeline-native')
implementation project(':memory-types:ashmem')
implementation project(':memory-types:nativememory')
implementation project(':memory-types:simple')
implementation project(':ui-common')
implementation project(':ui-core')
implementation project(':middleware')

testCompileOnly Deps.inferAnnotation
Expand Down
1 change: 1 addition & 0 deletions ui-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ android {

dependencies {
compileOnly Deps.jsr305
compileOnly Deps.inferAnnotation
}

apply plugin: "com.vanniktech.maven.publish"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import com.facebook.infer.annotation.Nullsafe;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -125,30 +124,6 @@ Matrix getTransform(
float focusY);
}

@Nullable
public static ScaleTypeDrawable getActiveScaleTypeDrawable(@Nullable Drawable drawable) {
if (drawable == null) {
return null;
} else if (drawable instanceof ScaleTypeDrawable) {
return (ScaleTypeDrawable) drawable;
} else if (drawable instanceof DrawableParent) {
final Drawable childDrawable = ((DrawableParent) drawable).getDrawable();
return getActiveScaleTypeDrawable(childDrawable);
} else if (drawable instanceof ArrayDrawable) {
final ArrayDrawable fadeDrawable = (ArrayDrawable) drawable;
final int numLayers = fadeDrawable.getNumberOfLayers();

for (int i = 0; i < numLayers; i++) {
final Drawable childDrawable = fadeDrawable.getDrawable(i);
final ScaleTypeDrawable result = getActiveScaleTypeDrawable(childDrawable);
if (result != null) {
return result;
}
}
}
return null;
}

@Nullable
public static ScaleType convertFromImageViewScaleType(ImageView.ScaleType scaleType) {
switch (scaleType) {
Expand Down

0 comments on commit 2eb960b

Please sign in to comment.