mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Easy refactor of constants in ImageResizeMode
Summary: This is an easy refactor of constants in ImageResizeMode changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D19509348 fbshipit-source-id: 2bed9e35f0c7daa04c64ec7fba6975517633bfa7
This commit is contained in:
committed by
Facebook Github Bot
parent
a5b5d1a805
commit
f6b3bce961
@@ -15,23 +15,29 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
||||
/** Converts JS resize modes into Android-specific scale type. */
|
||||
public class ImageResizeMode {
|
||||
|
||||
private static final String RESIZE_MODE_CONTAIN = "contain";
|
||||
private static final String RESIZE_MODE_COVER = "cover";
|
||||
private static final String RESIZE_MODE_STRETCH = "stretch";
|
||||
private static final String RESIZE_MODE_CENTER = "center";
|
||||
private static final String RESIZE_MODE_REPEAT = "repeat";
|
||||
|
||||
/**
|
||||
* Converts JS resize modes into {@code ScalingUtils.ScaleType}. See {@code ImageResizeMode.js}.
|
||||
*/
|
||||
public static ScalingUtils.ScaleType toScaleType(@Nullable String resizeModeValue) {
|
||||
if ("contain".equals(resizeModeValue)) {
|
||||
if (RESIZE_MODE_CONTAIN.equals(resizeModeValue)) {
|
||||
return ScalingUtils.ScaleType.FIT_CENTER;
|
||||
}
|
||||
if ("cover".equals(resizeModeValue)) {
|
||||
if (RESIZE_MODE_COVER.equals(resizeModeValue)) {
|
||||
return ScalingUtils.ScaleType.CENTER_CROP;
|
||||
}
|
||||
if ("stretch".equals(resizeModeValue)) {
|
||||
if (RESIZE_MODE_STRETCH.equals(resizeModeValue)) {
|
||||
return ScalingUtils.ScaleType.FIT_XY;
|
||||
}
|
||||
if ("center".equals(resizeModeValue)) {
|
||||
if (RESIZE_MODE_CENTER.equals(resizeModeValue)) {
|
||||
return ScalingUtils.ScaleType.CENTER_INSIDE;
|
||||
}
|
||||
if ("repeat".equals(resizeModeValue)) {
|
||||
if (RESIZE_MODE_REPEAT.equals(resizeModeValue)) {
|
||||
// Handled via a combination of ScaleType and TileMode
|
||||
return ScaleTypeStartInside.INSTANCE;
|
||||
}
|
||||
@@ -45,13 +51,13 @@ public class ImageResizeMode {
|
||||
|
||||
/** Converts JS resize modes into {@code Shader.TileMode}. See {@code ImageResizeMode.js}. */
|
||||
public static Shader.TileMode toTileMode(@Nullable String resizeModeValue) {
|
||||
if ("contain".equals(resizeModeValue)
|
||||
|| "cover".equals(resizeModeValue)
|
||||
|| "stretch".equals(resizeModeValue)
|
||||
|| "center".equals(resizeModeValue)) {
|
||||
if (RESIZE_MODE_CONTAIN.equals(resizeModeValue)
|
||||
|| RESIZE_MODE_COVER.equals(resizeModeValue)
|
||||
|| RESIZE_MODE_STRETCH.equals(resizeModeValue)
|
||||
|| RESIZE_MODE_CENTER.equals(resizeModeValue)) {
|
||||
return Shader.TileMode.CLAMP;
|
||||
}
|
||||
if ("repeat".equals(resizeModeValue)) {
|
||||
if (RESIZE_MODE_REPEAT.equals(resizeModeValue)) {
|
||||
// Handled via a combination of ScaleType and TileMode
|
||||
return Shader.TileMode.REPEAT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user