Skip to content

Commit 65f4988

Browse files
andreicoman11Ahmed El-Helw
authored andcommitted
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
1 parent e1ece03 commit 65f4988

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ReactAndroid/src/main/java/com/facebook/react/flat/RCTImageView.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import com.facebook.csslayout.Spacing;
1515
import com.facebook.drawee.drawable.ScalingUtils.ScaleType;
16+
import com.facebook.react.bridge.ReadableArray;
1617
import com.facebook.react.uimanager.PixelUtil;
1718
import com.facebook.react.uimanager.annotations.ReactProp;
1819
import com.facebook.react.uimanager.ViewProps;
@@ -86,7 +87,9 @@ public void setShouldNotifyLoadEvents(boolean shouldNotifyLoadEvents) {
8687
}
8788

8889
@ReactProp(name = "src")
89-
public void setSource(@Nullable String source) {
90+
public void setSource(@Nullable ReadableArray sources) {
91+
final String source =
92+
(sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri");
9093
getMutableDrawImage().setImageRequest(
9194
ImageRequestHelper.createImageRequest(getThemedContext(), source));
9295
}

ReactAndroid/src/main/java/com/facebook/react/flat/RCTTextInlineImage.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.text.SpannableStringBuilder;
1515
import android.text.Spanned;
1616

17+
import com.facebook.react.bridge.ReadableArray;
1718
import com.facebook.react.uimanager.annotations.ReactProp;
1819

1920
/**
@@ -65,7 +66,9 @@ protected void performCollectAttachDetachListeners(StateBuilder stateBuilder) {
6566
}
6667

6768
@ReactProp(name = "src")
68-
public void setSource(@Nullable String source) {
69+
public void setSource(@Nullable ReadableArray sources) {
70+
final String source =
71+
(sources == null || sources.size() == 0) ? null : sources.getMap(0).getString("uri");
6972
getMutableSpan().setImageRequest(
7073
ImageRequestHelper.createImageRequest(getThemedContext(), source));
7174
}

0 commit comments

Comments
 (0)