This repository was archived by the owner on Jun 16, 2026. It is now read-only.
forked from react/react-native
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathprimitives.h
More file actions
118 lines (98 loc) · 2.96 KB
/
Copy pathprimitives.h
File metadata and controls
118 lines (98 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* 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 <string>
#include <vector>
#include <react/renderer/core/propsConversions.h>
#include <react/renderer/graphics/Float.h>
#include <react/renderer/graphics/Size.h>
namespace facebook::react {
class ImageSource {
public:
enum class Type { Invalid, Remote, Local };
enum class CacheStategy { Default, Reload, ForceCache, OnlyIfCached };
Type type{};
std::string uri{};
std::string bundle{};
Float scale{3};
Size size{0};
std::string body{};
std::string method{};
CacheStategy cache = CacheStategy::Default;
std::vector<std::pair<std::string, std::string>> headers{};
bool operator==(const ImageSource& rhs) const {
return std::tie(this->type, this->uri) == std::tie(rhs.type, rhs.uri);
}
bool operator!=(const ImageSource& rhs) const {
return !(*this == rhs);
}
#ifdef RN_SERIALIZABLE_STATE
folly::dynamic toDynamic() const {
folly::dynamic imageSourceResult = folly::dynamic::object();
switch (type) {
case ImageSource::Type::Invalid:
imageSourceResult["type"] = "invalid";
break;
case ImageSource::Type::Remote:
imageSourceResult["type"] = "remote";
break;
case ImageSource::Type::Local:
imageSourceResult["type"] = "local";
break;
}
imageSourceResult["uri"] = uri;
imageSourceResult["bundle"] = bundle;
imageSourceResult["scale"] = scale;
folly::dynamic sizeResult = folly::dynamic::object();
imageSourceResult["width"] = size.width;
imageSourceResult["height"] = size.height;
imageSourceResult["body"] = body;
imageSourceResult["method"] = method;
switch (cache) {
case ImageSource::CacheStategy::Default:
imageSourceResult["cache"] = "default";
break;
case ImageSource::CacheStategy::Reload:
imageSourceResult["cache"] = "reload";
break;
case ImageSource::CacheStategy::ForceCache:
imageSourceResult["cache"] = "force-cache";
break;
case ImageSource::CacheStategy::OnlyIfCached:
imageSourceResult["cache"] = "only-if-cached";
break;
}
folly::dynamic headersObject = folly::dynamic::object();
for (const auto& header : headers) {
headersObject[header.first] = header.second;
}
imageSourceResult["headers"] = headersObject;
return imageSourceResult;
}
#endif
};
#ifdef RN_SERIALIZABLE_STATE
inline folly::dynamic toDynamic(const ImageSource& imageSource) {
return imageSource.toDynamic();
}
#endif
using ImageSources = std::vector<ImageSource>;
enum class ImageResizeMode {
Cover,
Contain,
Stretch,
Center,
Repeat,
None,
};
class ImageErrorInfo {
public:
std::string error{};
int responseCode{};
std::vector<std::pair<std::string, std::string>> httpResponseHeaders{};
};
} // namespace facebook::react