mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-03 15:14:18 +00:00
* Fixes Android Release images not rendering (Issue #129) (#1) * Fixes Android Release images not rendering (Issue #129) Issue caused by 2 things: - Image resources were not properly getting the path due to missing scheme (if required via require('./images/img.png')) - markUpdated() was not causing a re-render thus image was not updating if it was a resource id after fetching. This is been changed to directly call bitmapTryRender, however, this may not be the best approach to this issue. Minor note: After making this change, RenderableShadowNode would get a null for images. I put a null check for the alpha parameter to suppress this. * Reverts check for color work around
This commit is contained in:
committed by
Dustin Savery
parent
20ea2d9bb5
commit
7ddbf2a73b
@@ -32,6 +32,7 @@ import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|||||||
import com.facebook.react.bridge.ReadableMap;
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
import com.facebook.react.common.ReactConstants;
|
import com.facebook.react.common.ReactConstants;
|
||||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||||
|
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@@ -105,6 +106,9 @@ class ImageShadowNode extends RenderableShadowNode {
|
|||||||
mImageHeight = 0;
|
mImageHeight = 0;
|
||||||
}
|
}
|
||||||
mUri = Uri.parse(uriString);
|
mUri = Uri.parse(uriString);
|
||||||
|
if (mUri.getScheme() == null) {
|
||||||
|
mUri = ResourceDrawableIdHelper.getInstance().getResourceDrawableUri(getThemedContext(), uriString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +152,7 @@ class ImageShadowNode extends RenderableShadowNode {
|
|||||||
if (Fresco.getImagePipeline().isInBitmapMemoryCache(request)) {
|
if (Fresco.getImagePipeline().isInBitmapMemoryCache(request)) {
|
||||||
tryRender(request, canvas, paint, opacity * mOpacity);
|
tryRender(request, canvas, paint, opacity * mOpacity);
|
||||||
} else {
|
} else {
|
||||||
loadBitmap(request);
|
loadBitmap(request, canvas, paint, opacity * mOpacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,16 +164,14 @@ class ImageShadowNode extends RenderableShadowNode {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadBitmap(ImageRequest request) {
|
private void loadBitmap(ImageRequest request, final Canvas canvas, final Paint paint, final float opacity) {
|
||||||
final DataSource<CloseableReference<CloseableImage>> dataSource
|
final DataSource<CloseableReference<CloseableImage>> dataSource
|
||||||
= Fresco.getImagePipeline().fetchDecodedImage(request, getThemedContext());
|
= Fresco.getImagePipeline().fetchDecodedImage(request, getThemedContext());
|
||||||
|
|
||||||
dataSource.subscribe(new BaseBitmapDataSubscriber() {
|
dataSource.subscribe(new BaseBitmapDataSubscriber() {
|
||||||
@Override
|
@Override
|
||||||
public void onNewResultImpl(Bitmap bitmap) {
|
public void onNewResultImpl(Bitmap bitmap) {
|
||||||
mLoading.set(false);
|
mLoading.set(false);
|
||||||
SvgViewShadowNode shadowNode = getSvgShadowNode();
|
bitmapTryRender(bitmap, canvas, paint, opacity * mOpacity);
|
||||||
shadowNode.markUpdated();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -284,4 +286,14 @@ class ImageShadowNode extends RenderableShadowNode {
|
|||||||
dataSource.close();
|
dataSource.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void bitmapTryRender(Bitmap bitmap, Canvas canvas, Paint paint, float opacity) {
|
||||||
|
try {
|
||||||
|
if (bitmap != null) {
|
||||||
|
doRender(canvas, paint, bitmap, opacity);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user