From 65f4988ddf480a78667a1856b728174c9ac2fb9f Mon Sep 17 00:00:00 2001 From: Andrei Coman Date: Mon, 13 Jun 2016 14:04:19 -0700 Subject: [PATCH] Support multi sources for images Summary: @public This adds support for specifying multiple sources for an image component, so that native can choose the best one based on the flexbox-computed size of the image. The API is as follows: the image component receives in the `source` prop an array of objects of the type `{uri, width, height}`. On the native side, the native component will wait for the layout pass to receive the width and height of the image, and then parse the array to find the best fitting one. For now, this does not support local resources, but it will be added soon. To see how this works and play with it, there's an example called `MultipleSourcesExample` under `ImageExample` In UIExplorer. Reviewed By: foghina Differential Revision: D3364550 --- .../src/main/java/com/facebook/react/flat/RCTImageView.java | 5 ++++- .../java/com/facebook/react/flat/RCTTextInlineImage.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageView.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageView.java index 729a4b5f288..4206819813d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageView.java @@ -13,6 +13,7 @@ import javax.annotation.Nullable; import com.facebook.csslayout.Spacing; import com.facebook.drawee.drawable.ScalingUtils.ScaleType; +import com.facebook.react.bridge.ReadableArray; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.ViewProps; @@ -86,7 +87,9 @@ import com.facebook.react.views.image.ImageResizeMode; } @ReactProp(name = "src") - public void setSource(@Nullable String source) { + public void setSource(@Nullable ReadableArray sources) { + final String source = + (sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri"); getMutableDrawImage().setImageRequest( ImageRequestHelper.createImageRequest(getThemedContext(), source)); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInlineImage.java b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInlineImage.java index fba7bd9171d..5682b04b221 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInlineImage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInlineImage.java @@ -14,6 +14,7 @@ import javax.annotation.Nullable; import android.text.SpannableStringBuilder; import android.text.Spanned; +import com.facebook.react.bridge.ReadableArray; import com.facebook.react.uimanager.annotations.ReactProp; /** @@ -65,7 +66,9 @@ import com.facebook.react.uimanager.annotations.ReactProp; } @ReactProp(name = "src") - public void setSource(@Nullable String source) { + public void setSource(@Nullable ReadableArray sources) { + final String source = + (sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri"); getMutableSpan().setImageRequest( ImageRequestHelper.createImageRequest(getThemedContext(), source)); }