mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
0b6436b637
Summary: ImageRequestHelper was not handling data: scheme correctly, which resulted in images failing to load. This diff is fixing it by considering \"data:\" as a Uri resource, and piping it appropriately. Reviewed By: sriramramani Differential Revision: D2919403
52 lines
1.5 KiB
Java
52 lines
1.5 KiB
Java
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
package com.facebook.react.flat;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.net.Uri;
|
|
|
|
import com.facebook.imagepipeline.request.ImageRequest;
|
|
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
|
|
/* package */ class ImageRequestHelper {
|
|
|
|
/* package */ static @Nullable ImageRequest createImageRequest(
|
|
Context context,
|
|
@Nullable String source) {
|
|
if (source == null) {
|
|
return null;
|
|
}
|
|
|
|
final ImageRequestBuilder imageRequestBuilder;
|
|
if (isUriResource(source)) {
|
|
imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(source));
|
|
} else {
|
|
Resources resources = context.getResources();
|
|
int resId = resources.getIdentifier(
|
|
source,
|
|
"drawable",
|
|
context.getPackageName());
|
|
imageRequestBuilder = ImageRequestBuilder.newBuilderWithResourceId(resId);
|
|
}
|
|
|
|
return imageRequestBuilder.build();
|
|
}
|
|
|
|
private static boolean isUriResource(String source) {
|
|
return
|
|
source.startsWith("http://") ||
|
|
source.startsWith("https://") ||
|
|
source.startsWith("data:");
|
|
}
|
|
}
|