Skip to content

Commit 56e5829

Browse files
Add io target to ReactCxxPlatform (#51900)
Summary: Pull Request resolved: #51900 changelog: [internal] Reviewed By: andrewdacenko Differential Revision: D76240623 fbshipit-source-id: 4756ff73f9cc7ee42c31fba60918380400c14410
1 parent 0fad032 commit 56e5829

13 files changed

Lines changed: 1245 additions & 0 deletions
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "ImageLoaderModule.h"
9+
10+
namespace facebook::react {
11+
12+
// TODO: T170340321 - actual implementation
13+
14+
jsi::Object ImageLoaderModule::getConstants(jsi::Runtime& rt) {
15+
return jsi::Object(rt);
16+
}
17+
18+
void ImageLoaderModule::abortRequest(jsi::Runtime& rt, int32_t requestId) {}
19+
20+
AsyncPromise<ImageSize> ImageLoaderModule::getSize(
21+
jsi::Runtime& rt,
22+
const std::string& /*uri*/) {
23+
auto promise = AsyncPromise<ImageSize>(rt, jsInvoker_);
24+
promise.resolve({.width = 0.0, .height = 0.0});
25+
return promise;
26+
}
27+
28+
AsyncPromise<ImageSize> ImageLoaderModule::getSizeWithHeaders(
29+
jsi::Runtime& rt,
30+
const std::string& /*uri*/,
31+
jsi::Object /*headers*/) {
32+
auto promise = AsyncPromise<ImageSize>(rt, jsInvoker_);
33+
promise.resolve({.width = 0.0, .height = 0.0});
34+
return promise;
35+
}
36+
37+
AsyncPromise<bool> ImageLoaderModule::prefetchImage(
38+
jsi::Runtime& rt,
39+
const std::string& /*uri*/,
40+
int32_t /*requestId*/) {
41+
auto promise = AsyncPromise<bool>(rt, jsInvoker_);
42+
promise.resolve(false);
43+
return promise;
44+
}
45+
46+
jsi::Object ImageLoaderModule::queryCache(
47+
jsi::Runtime& rt,
48+
const std::vector<std::string>& /*uris*/) {
49+
return jsi::Object(rt);
50+
}
51+
52+
} // namespace facebook::react
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h>
11+
#include <react/bridging/Promise.h>
12+
#include <memory>
13+
#include <string>
14+
#include <vector>
15+
16+
namespace facebook::react {
17+
18+
using ImageSize = NativeImageLoaderAndroidImageSize<double, double>;
19+
20+
template <>
21+
struct Bridging<ImageSize>
22+
: NativeImageLoaderAndroidImageSizeBridging<ImageSize> {};
23+
24+
class ImageLoaderModule
25+
: public NativeImageLoaderAndroidCxxSpec<ImageLoaderModule> {
26+
public:
27+
explicit ImageLoaderModule(std::shared_ptr<CallInvoker> jsInvoker)
28+
: NativeImageLoaderAndroidCxxSpec(jsInvoker) {}
29+
30+
jsi::Object getConstants(jsi::Runtime& rt);
31+
void abortRequest(jsi::Runtime& rt, int32_t requestId);
32+
33+
AsyncPromise<ImageSize> getSize(jsi::Runtime& rt, const std::string& uri);
34+
35+
AsyncPromise<ImageSize> getSizeWithHeaders(
36+
jsi::Runtime& rt,
37+
const std::string& uri,
38+
jsi::Object headers);
39+
40+
AsyncPromise<bool>
41+
prefetchImage(jsi::Runtime& rt, const std::string& uri, int32_t requestId);
42+
43+
jsi::Object queryCache(
44+
jsi::Runtime& rt,
45+
const std::vector<std::string>& uris);
46+
};
47+
48+
} // namespace facebook::react

0 commit comments

Comments
 (0)