forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Initiate image prefetching on ImageShadowNode layout (facebo…
…ok#47932) Summary: This diff introduces a code path to trigger image prefetching from `ImageShadowNode::layout`. Changelog: [Internal] Differential Revision: D66454087
- Loading branch information
1 parent
7ebe9af
commit 593d573
Showing
5 changed files
with
110 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...es/react-native/ReactCommon/react/renderer/imagemanager/platform/android/ImageFetcher.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "ImageFetcher.h" | ||
#include <react/renderer/imagemanager/conversions.h> | ||
|
||
namespace facebook::react { | ||
|
||
ImageFetcher::ImageFetcher(const ContextContainer::Shared& contextContainer) { | ||
fabricUIManager_ = | ||
contextContainer->at<jni::global_ref<jobject>>("FabricUIManager"); | ||
requestImage_ = | ||
fabricUIManager_->getClass() | ||
->getMethod<void(SurfaceId, Tag, JReadableMapBuffer::javaobject)>( | ||
"requestImage"); | ||
} | ||
|
||
ImageRequest ImageFetcher::requestImage( | ||
const ImageSource& imageSource, | ||
const ImageRequestParams& imageRequestParams, | ||
SurfaceId surfaceId, | ||
Tag tag) const { | ||
auto serializedImageRequest = | ||
serializeImageRequest(imageSource, imageRequestParams); | ||
|
||
auto readableMapBuffer = | ||
JReadableMapBuffer::createWithContents(std::move(serializedImageRequest)); | ||
|
||
requestImage_(fabricUIManager_, surfaceId, tag, readableMapBuffer.get()); | ||
|
||
auto telemetry = std::make_shared<ImageTelemetry>(surfaceId); | ||
|
||
return {imageSource, telemetry}; | ||
} | ||
} // namespace facebook::react |
37 changes: 37 additions & 0 deletions
37
...ages/react-native/ReactCommon/react/renderer/imagemanager/platform/android/ImageFetcher.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
|
||
#include <react/common/mapbuffer/JReadableMapBuffer.h> | ||
#include <react/jni/ReadableNativeMap.h> | ||
#include <react/renderer/imagemanager/ImageRequest.h> | ||
#include <react/renderer/imagemanager/ImageRequestParams.h> | ||
#include <react/utils/ContextContainer.h> | ||
|
||
namespace facebook::react { | ||
|
||
class ImageFetcher { | ||
public: | ||
ImageFetcher(const ContextContainer::Shared& contextContainer); | ||
|
||
void discardImageRequest(const std::string& imageRequestCacheKey) const; | ||
|
||
ImageRequest requestImage( | ||
const ImageSource& imageSource, | ||
const ImageRequestParams& imageRequestParams, | ||
SurfaceId surfaceId, | ||
Tag tag) const; | ||
|
||
private: | ||
jni::global_ref<jobject> fabricUIManager_; | ||
jni::JMethod<void(SurfaceId, Tag, JReadableMapBuffer::javaobject)> | ||
requestImage_; | ||
}; | ||
} // namespace facebook::react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters