@react-native-ohos/react-native-blurhash 2.0.4-rc.1 → 2.0.4-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/harmony/blurhash/index.ets +2 -0
  2. package/harmony/blurhash/oh-package.json5 +1 -1
  3. package/harmony/blurhash/src/main/cpp/Blurhash.cpp +171 -77
  4. package/harmony/blurhash/src/main/cpp/{Blurhash.hpp → Blurhash.h} +5 -2
  5. package/harmony/blurhash/src/main/cpp/BlurhashNode.cpp +18 -12
  6. package/harmony/blurhash/src/main/cpp/BlurhashNode.h +3 -2
  7. package/harmony/blurhash/src/main/cpp/BlurhashPackage.h +23 -12
  8. package/harmony/blurhash/src/main/cpp/BlurhashViewComponentInstance.cpp +56 -82
  9. package/harmony/blurhash/src/main/cpp/BlurhashViewComponentInstance.h +8 -5
  10. package/harmony/blurhash/src/main/cpp/BlurhashViewJSIBinder.h +11 -7
  11. package/harmony/blurhash/src/main/cpp/ComponentDescriptors.h +4 -2
  12. package/harmony/blurhash/src/main/cpp/EventEmitters.cpp +9 -8
  13. package/harmony/blurhash/src/main/cpp/EventEmitters.h +4 -4
  14. package/harmony/blurhash/src/main/cpp/Props.cpp +11 -10
  15. package/harmony/blurhash/src/main/cpp/Props.h +19 -13
  16. package/harmony/blurhash/src/main/cpp/RNBlurhashTurboModule.cpp +16 -10
  17. package/harmony/blurhash/src/main/cpp/RNBlurhashTurboModule.h +3 -3
  18. package/harmony/blurhash/src/main/cpp/ShadowNodes.cpp +1 -2
  19. package/harmony/blurhash/src/main/cpp/ShadowNodes.h +5 -5
  20. package/harmony/blurhash/src/main/cpp/SparseArray.cpp +7 -4
  21. package/harmony/blurhash/src/main/cpp/SparseArray.h +2 -2
  22. package/harmony/blurhash/src/main/cpp/napi_init.cpp +4 -5
  23. package/harmony/blurhash/src/main/ets/{BlurhashPackage.ts → BlurhashPackage.ets} +3 -2
  24. package/harmony/blurhash/{ts.ts → ts.ets} +1 -1
  25. package/harmony/blurhash.har +0 -0
  26. package/package.json +12 -5
  27. package/harmony/blurhash/BuildProfile.ets +0 -17
  28. package/lib/commonjs/index.js +0 -95
  29. package/lib/commonjs/index.js.map +0 -1
  30. package/lib/commonjs/specs/NativeBlurhashModule.js +0 -9
  31. package/lib/commonjs/specs/NativeBlurhashModule.js.map +0 -1
  32. package/lib/commonjs/specs/NativeBlurhashView.js +0 -10
  33. package/lib/commonjs/specs/NativeBlurhashView.js.map +0 -1
  34. package/lib/commonjs/utils.js +0 -56
  35. package/lib/commonjs/utils.js.map +0 -1
  36. package/lib/module/index.js +0 -85
  37. package/lib/module/index.js.map +0 -1
  38. package/lib/module/specs/NativeBlurhashModule.js +0 -3
  39. package/lib/module/specs/NativeBlurhashModule.js.map +0 -1
  40. package/lib/module/specs/NativeBlurhashView.js +0 -3
  41. package/lib/module/specs/NativeBlurhashView.js.map +0 -1
  42. package/lib/module/utils.js +0 -48
  43. package/lib/module/utils.js.map +0 -1
  44. package/lib/typescript/index.d.ts +0 -90
  45. package/lib/typescript/specs/NativeBlurhashModule.d.ts +0 -9
  46. package/lib/typescript/specs/NativeBlurhashView.d.ts +0 -19
  47. package/lib/typescript/utils.d.ts +0 -22
@@ -3,9 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
7
6
  #include "BlurhashViewComponentInstance.h"
8
- #include "Blurhash.hpp"
7
+ #include "Blurhash.h"
9
8
  #include "Props.h"
10
9
  #include <filemanagement/file_uri/oh_file_uri.h>
11
10
  #include "RNBlurhashTurboModule.h"
@@ -13,125 +12,100 @@
13
12
  #include <iomanip>
14
13
  #include <react/renderer/core/ConcreteState.h>
15
14
  #include <sstream>
16
- #include <cstdio>
17
15
 
18
16
  namespace rnoh {
19
17
 
20
- BlurhashViewComponentInstance::BlurhashViewComponentInstance(Context context) : CppComponentInstance(std::move(context)) {
18
+ BlurhashViewComponentInstance::BlurhashViewComponentInstance(Context context)
19
+ : CppComponentInstance(std::move(context))
20
+ {
21
21
  this->getLocalRootArkUINode().setNodeDelegate(this);
22
22
  }
23
23
 
24
- void BlurhashViewComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
25
-
24
+ void BlurhashViewComponentInstance::onPropsChanged(SharedConcreteProps const &props)
25
+ {
26
26
  CppComponentInstance::onPropsChanged(props);
27
27
 
28
28
  if (!m_props || m_props->resizeMode != props->resizeMode) {
29
29
  this->getLocalRootArkUINode().setResizeMode(convertToImageResizeMode(props->resizeMode));
30
30
  }
31
- // Validate inputs and early-return to avoid passing null/invalid data into ArkUI
32
31
  if (props->blurhash == "") {
33
- if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "The provided Blurhash string must not be empty!"});
34
- return;
35
- }
32
+ m_eventEmitter->onLoadError({"The provided Blurhash string must not be null!"});
33
+ };
36
34
  if (props->decodeWidth <= 0) {
37
- if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "decodeWidth must be greater than 0!"});
38
- return;
39
- }
35
+ m_eventEmitter->onLoadError({"decodeWidth must be greater than 0!"});
36
+ };
40
37
  if (props->decodeHeight <= 0) {
41
- if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "decodeHeight must be greater than 0!"});
42
- return;
43
- }
38
+ m_eventEmitter->onLoadError({"decodeHeight must be greater than 0!"});
39
+ };
44
40
  if (props->decodePunch <= 0) {
45
- if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "decodePunch must be greater than 0!"});
46
- return;
47
- }
48
-
49
- std::string filePath = decodeImageByBlurhash(props->blurhash, props->decodeWidth, props->decodeHeight, props->decodePunch);
50
- if (filePath.empty()) {
51
- if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "Failed to decode blurhash to image."});
52
- return;
53
- }
54
-
55
-
56
- // If filePath is already a URI, use it directly
57
- if (filePath.find("://") != std::string::npos) {
58
- this->getLocalRootArkUINode().setSource(filePath);
59
- return;
60
- }
61
- // If filePath is an absolute path, use it as-is; otherwise prefix cache dir
62
- std::string absPath = filePath;
63
- if (!(absPath.rfind("/", 0) == 0)) {
64
- absPath = "/data/storage/el2/base/haps/entry/cache/" + absPath;
65
- }
66
-
67
- const char *path = absPath.c_str();
68
- unsigned int length = static_cast<unsigned int>(absPath.size());
41
+ m_eventEmitter->onLoadError({"decodePunch must be greater than 0!"});
42
+ };
43
+ std::string filePath = decodeImageByBlurhash(props->blurhash,
44
+ props->decodeWidth, props->decodeHeight, props->decodePunch);
45
+ std::string tempPath = "/data/storage/el2/base/haps/entry/cache/" + filePath;
46
+ char *path = new char[tempPath.size() + 1];
47
+ std::strcpy(path, tempPath.c_str());
48
+ unsigned int length = strlen(path);
69
49
  char *result = nullptr;
70
50
  FileManagement_ErrCode ret = OH_FileUri_GetUriFromPath(path, length, &result);
71
- if (ret != FileManagement_ErrCode::ERR_OK || result == nullptr) {
72
- if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "Failed to convert path to file URI."});
73
- return;
51
+ this->getLocalRootArkUINode().setSource(std::string(result));
52
+ if (result != nullptr) {
53
+ free(result);
74
54
  }
75
- std::string uriStr(result);
76
- this->getLocalRootArkUINode().setSource(uriStr);
77
- free(result);
78
55
  }
79
56
 
80
- std::string BlurhashViewComponentInstance::decodeImageByBlurhash(const std::string &blurhash, const int &width, const int &height, const float &punch) {
81
- std::string expectedName = blurhash + ".bmp";
57
+ std::string BlurhashViewComponentInstance::decodeImageByBlurhash(const std::string &blurhash,
58
+ const int &width, const int &height, const float &punch)
59
+ {
82
60
  blurhash::decode(blurhash, width, height, punch);
83
61
  auto rnInstance = m_deps->rnInstance.lock();
84
62
  auto turboModule = rnInstance->getTurboModule("ImageLoader");
85
63
  auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
86
- if (!arkTsTurboModule) {
87
- return expectedName; // fallback filename
88
- }
89
- auto cache = arkTsTurboModule->callSync("getPrefetchResult", {expectedName});
90
- std::string result;
91
- if (cache.isString()) {
92
- result = cache.asString();
93
- }
94
- if (result.empty()) {
95
- // in case non-string/unsupported shape returned, fallback
96
- result = expectedName;
97
- }
98
- return result;
64
+ auto cache = arkTsTurboModule->callSync("getPrefetchResult", {blurhash + ".bmp"});
65
+ return cache.asString();
99
66
  }
100
67
 
101
- BlurhashNode &BlurhashViewComponentInstance::getLocalRootArkUINode() { return m_imageNode; }
68
+ BlurhashNode &BlurhashViewComponentInstance::getLocalRootArkUINode()
69
+ {
70
+ return m_imageNode;
71
+ }
102
72
 
103
- void BlurhashViewComponentInstance::onComplete() {
104
- if (m_eventEmitter) {
105
- m_eventEmitter->onLoadStart({});
106
- m_eventEmitter->onLoadEnd({});
73
+ void BlurhashViewComponentInstance::onComplete()
74
+ {
75
+ m_eventEmitter->onLoadStart({});
76
+ if (m_eventEmitter == nullptr) {
77
+ return;
107
78
  }
79
+ m_eventEmitter->onLoadEnd({});
108
80
  }
109
81
 
110
- void BlurhashViewComponentInstance::onError(int32_t errorCode) {
82
+ void BlurhashViewComponentInstance::onError(int32_t errorCode)
83
+ {
111
84
  if (m_eventEmitter) {
112
- m_eventEmitter->onLoadError({.message = ""});
85
+ m_eventEmitter->onLoadError({""});
113
86
  }
114
87
  }
115
88
 
116
- void BlurhashViewComponentInstance::onLoadStart(SharedConcreteProps const &props) {
89
+ void BlurhashViewComponentInstance::onLoadStart(SharedConcreteProps const &props)
90
+ {
117
91
  if (m_eventEmitter) {
118
- // RN 0.77: DirectEventHandler<null>
119
- m_eventEmitter->onLoadStart({});
92
+ m_eventEmitter->onLoadStart({props->blurhash,
93
+ props->decodeWidth, props->decodeHeight, props->decodePunch});
120
94
  }
121
95
  }
122
96
 
123
- facebook::react::ImageResizeMode BlurhashViewComponentInstance::convertToImageResizeMode(facebook::react::BlurhashViewResizeMode mode) {
97
+ facebook::react::ImageResizeMode BlurhashViewComponentInstance::convertToImageResizeMode(
98
+ facebook::react::BlurhashViewResizeMode mode)
99
+ {
124
100
  switch (mode) {
125
- case facebook::react::BlurhashViewResizeMode::Contain:
126
- return facebook::react::ImageResizeMode::Contain;
127
- case facebook::react::BlurhashViewResizeMode::Cover:
128
- return facebook::react::ImageResizeMode::Cover;
129
- case facebook::react::BlurhashViewResizeMode::Stretch:
130
- return facebook::react::ImageResizeMode::Stretch;
131
- case facebook::react::BlurhashViewResizeMode::Center:
132
- return facebook::react::ImageResizeMode::Center;
101
+ case facebook::react::BlurhashViewResizeMode::Contain:
102
+ return facebook::react::ImageResizeMode::Contain;
103
+ case facebook::react::BlurhashViewResizeMode::Cover:
104
+ return facebook::react::ImageResizeMode::Cover;
105
+ case facebook::react::BlurhashViewResizeMode::Stretch:
106
+ return facebook::react::ImageResizeMode::Stretch;
107
+ case facebook::react::BlurhashViewResizeMode::Center:
108
+ return facebook::react::ImageResizeMode::Center;
133
109
  }
134
- // Fallback to avoid undefined behavior
135
- return facebook::react::ImageResizeMode::Cover;
136
110
  }
137
111
  } // namespace rnoh
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef BLURHASHVIEWCOMPONENTINSTANCE_H
7
+ #define BLURHASHVIEWCOMPONENTINSTANCE_H
7
8
  #pragma once
8
9
 
9
10
  #include "EventEmitters.h"
@@ -13,15 +14,16 @@
13
14
  #include "RNOH/arkui/ImageNode.h"
14
15
 
15
16
  namespace rnoh {
16
- class BlurhashViewComponentInstance : public CppComponentInstance<facebook::react::BlurhashViewShadowNode>, public BlurhashNodeDelegate {
17
+ class BlurhashViewComponentInstance : public CppComponentInstance<
18
+ facebook::react::BlurhashViewShadowNode>, public BlurhashNodeDelegate {
17
19
  private:
18
20
  BlurhashNode m_imageNode;
19
21
  std::string m_uri;
20
22
 
21
- std::string decodeImageByBlurhash(std::string const &blurhash, int const &width, int const &height, float const &punch);
22
-
23
+ std::string decodeImageByBlurhash(std::string const &blurhash,
24
+ int const &width, int const &height, float const &punch);
23
25
  public:
24
- BlurhashViewComponentInstance(Context context);
26
+ explicit BlurhashViewComponentInstance(Context context);
25
27
  void onPropsChanged(SharedConcreteProps const &props) override;
26
28
  void onComplete() override;
27
29
  void onLoadStart(SharedConcreteProps const &props);
@@ -32,3 +34,4 @@ public:
32
34
  BlurhashNode &getLocalRootArkUINode() override;
33
35
  };
34
36
  } // namespace rnoh
37
+ #endif
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef BLURHASHVIEWJSIBINDER_H
7
+ #define BLURHASHVIEWJSIBINDER_H
7
8
  #pragma once
8
9
 
9
10
  #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
@@ -11,7 +12,8 @@
11
12
  namespace rnoh {
12
13
  class BlurhashViewJSIBinder : public ViewComponentJSIBinder {
13
14
  protected:
14
- facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
15
+ facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override
16
+ {
15
17
  auto object = ViewComponentJSIBinder::createNativeProps(rt);
16
18
  object.setProperty(rt, "imgUri", true);
17
19
  object.setProperty(rt, "blurhash", true);
@@ -23,12 +25,14 @@ protected:
23
25
  return object;
24
26
  }
25
27
 
26
- facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
28
+ facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override
29
+ {
27
30
  facebook::jsi::Object events(rt);
28
- events.setProperty(rt, "topLoadStart", createDirectEvent(rt, "onLoadStart"));
29
- events.setProperty(rt, "topLoadEnd", createDirectEvent(rt, "onLoadEnd"));
30
- events.setProperty(rt, "topLoadError", createDirectEvent(rt, "onLoadError"));
31
+ events.setProperty(rt, "topOnLoadStart", createDirectEvent(rt, "onLoadStart"));
32
+ events.setProperty(rt, "topOnLoadEnd", createDirectEvent(rt, "onLoadEnd"));
33
+ events.setProperty(rt, "topOnLoadError", createDirectEvent(rt, "onLoadError"));
31
34
  return events;
32
35
  }
33
36
  };
34
- } // namespace rnoh
37
+ } // namespace rnoh
38
+ #endif
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef COMPONENTDESCRIPTORS_H
7
+ #define COMPONENTDESCRIPTORS_H
7
8
  #pragma once
8
9
 
9
10
  #include "ShadowNodes.h"
@@ -15,4 +16,5 @@ namespace react {
15
16
  using BlurhashViewComponentDescriptor = ConcreteComponentDescriptor<BlurhashViewShadowNode>;
16
17
 
17
18
  } // namespace react
18
- } // namespace facebook
19
+ } // namespace facebook
20
+ #endif
@@ -10,27 +10,28 @@
10
10
  namespace facebook {
11
11
  namespace react {
12
12
 
13
- void BlurhashViewEventEmitter::onLoadError(OnLoadError event) const {
14
- dispatchEvent("LoadError", [event = std::move(event)](jsi::Runtime &runtime) {
13
+ void BlurhashViewEventEmitter::onLoadError(OnLoadError event) const
14
+ {
15
+ dispatchEvent("onLoadError", [event = std::move(event)](jsi::Runtime &runtime) {
15
16
  auto payload = jsi::Object(runtime);
16
17
  payload.setProperty(runtime, "message", event.message);
17
18
  return payload;
18
19
  });
19
20
  }
20
21
 
21
- void BlurhashViewEventEmitter::onLoadEnd(OnLoadEnd event) const {
22
- dispatchEvent("LoadEnd", [](jsi::Runtime &runtime) {
22
+ void BlurhashViewEventEmitter::onLoadEnd(OnLoadEnd event) const
23
+ {
24
+ dispatchEvent("onLoadEnd", [](jsi::Runtime &runtime) {
23
25
  auto payload = jsi::Object(runtime);
24
26
  return payload;
25
27
  });
26
28
  }
27
- void BlurhashViewEventEmitter::onLoadStart(OnLoadStart event) const {
28
- dispatchEvent("LoadStart", [](jsi::Runtime &runtime) {
29
+ void BlurhashViewEventEmitter::onLoadStart(OnLoadStart event) const
30
+ {
31
+ dispatchEvent("onLoadStart", [](jsi::Runtime &runtime) {
29
32
  auto payload = jsi::Object(runtime);
30
33
  return payload;
31
34
  });
32
35
  }
33
-
34
-
35
36
  } // namespace react
36
37
  } // namespace facebook
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef BLURHASH_EVENTEMITTERS_H
7
+ #define BLURHASH_EVENTEMITTERS_H
7
8
  #pragma once
8
9
 
9
10
  #include <react/renderer/components/view/ViewEventEmitter.h>
@@ -15,7 +16,6 @@ namespace react {
15
16
  class JSI_EXPORT BlurhashViewEventEmitter : public ViewEventEmitter {
16
17
  public:
17
18
  using ViewEventEmitter::ViewEventEmitter;
18
-
19
19
  struct OnLoadStart {
20
20
  std::string blurhash;
21
21
  int decodeWidth;
@@ -35,6 +35,6 @@ public:
35
35
 
36
36
  void onLoadStart(OnLoadStart value) const;
37
37
  };
38
-
39
38
  } // namespace react
40
- } // namespace facebook
39
+ } // namespace facebook
40
+ #endif
@@ -11,15 +11,16 @@
11
11
  namespace facebook {
12
12
  namespace react {
13
13
 
14
- BlurhashViewProps::BlurhashViewProps(const PropsParserContext &context, const BlurhashViewProps &sourceProps, const RawProps &rawProps)
15
- : ViewProps(context, sourceProps, rawProps),
16
- imgUri(convertRawProp(context, rawProps, "imgUri", sourceProps.imgUri, {})),
17
- blurhash(convertRawProp(context, rawProps, "blurhash", sourceProps.blurhash, {})),
18
- decodeWidth(convertRawProp(context, rawProps, "decodeWidth", sourceProps.decodeWidth, {})),
19
- decodeHeight(convertRawProp(context, rawProps, "decodeHeight", sourceProps.decodeHeight, {})),
20
- decodePunch(convertRawProp(context, rawProps, "decodePunch", sourceProps.decodePunch, {})),
21
- decodeAsync(convertRawProp(context, rawProps, "decodeAsync", sourceProps.decodeAsync, {})),
22
- resizeMode(convertRawProp(context, rawProps, "resizeMode", sourceProps.resizeMode, {facebook::react::BlurhashViewResizeMode::Cover})) {}
23
-
14
+ BlurhashViewProps::BlurhashViewProps(const PropsParserContext &context,
15
+ const BlurhashViewProps &sourceProps, const RawProps &rawProps)
16
+ : ViewProps(context, sourceProps, rawProps),
17
+ imgUri(convertRawProp(context, rawProps, "imgUri", sourceProps.imgUri, {})),
18
+ blurhash(convertRawProp(context, rawProps, "blurhash", sourceProps.blurhash, {})),
19
+ decodeWidth(convertRawProp(context, rawProps, "decodeWidth", sourceProps.decodeWidth, {})),
20
+ decodeHeight(convertRawProp(context, rawProps, "decodeHeight", sourceProps.decodeHeight, {})),
21
+ decodePunch(convertRawProp(context, rawProps, "decodePunch", sourceProps.decodePunch, {})),
22
+ decodeAsync(convertRawProp(context, rawProps, "decodeAsync", sourceProps.decodeAsync, {})),
23
+ resizeMode(convertRawProp(context, rawProps, "resizeMode", sourceProps.resizeMode,
24
+ {facebook::react::BlurhashViewResizeMode::Cover})) {}
24
25
  } // namespace react
25
26
  } // namespace facebook
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef BLURHASH_PROPS_H
7
+ #define BLURHASH_PROPS_H
7
8
  #pragma once
8
9
 
9
10
  #include <jsi/jsi.h>
@@ -18,7 +19,9 @@ namespace react {
18
19
 
19
20
  enum class BlurhashViewResizeMode { Contain, Cover, Stretch, Center };
20
21
 
21
- static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, BlurhashViewResizeMode &result) {
22
+ inline void fromRawValue(const PropsParserContext &context,
23
+ const RawValue &value, BlurhashViewResizeMode &result)
24
+ {
22
25
  auto string = (std::string)value;
23
26
  if (string == "contain") {
24
27
  result = BlurhashViewResizeMode::Contain;
@@ -36,19 +39,20 @@ static inline void fromRawValue(const PropsParserContext &context, const RawValu
36
39
  result = BlurhashViewResizeMode::Center;
37
40
  return;
38
41
  }
39
- abort();
42
+ throw std::runtime_error("Invalid display type");
40
43
  }
41
44
 
42
- static inline std::string toString(const BlurhashViewResizeMode &value) {
45
+ inline std::string toString(const BlurhashViewResizeMode &value)
46
+ {
43
47
  switch (value) {
44
- case BlurhashViewResizeMode::Contain:
45
- return "contain";
46
- case BlurhashViewResizeMode::Cover:
47
- return "cover";
48
- case BlurhashViewResizeMode::Stretch:
49
- return "stretch";
50
- case BlurhashViewResizeMode::Center:
51
- return "center";
48
+ case BlurhashViewResizeMode::Contain:
49
+ return "contain";
50
+ case BlurhashViewResizeMode::Cover:
51
+ return "cover";
52
+ case BlurhashViewResizeMode::Stretch:
53
+ return "stretch";
54
+ case BlurhashViewResizeMode::Center:
55
+ return "center";
52
56
  }
53
57
  }
54
58
 
@@ -57,7 +61,8 @@ enum class decodeWeight { defaltWeight };
57
61
  class JSI_EXPORT BlurhashViewProps final : public ViewProps {
58
62
  public:
59
63
  BlurhashViewProps() = default;
60
- BlurhashViewProps(const PropsParserContext &context, const BlurhashViewProps &sourceProps, const RawProps &rawProps);
64
+ BlurhashViewProps(const PropsParserContext &context,
65
+ const BlurhashViewProps &sourceProps, const RawProps &rawProps);
61
66
 
62
67
  #pragma mark - Props
63
68
  std::string imgUri{};
@@ -71,3 +76,4 @@ public:
71
76
 
72
77
  } // namespace react
73
78
  } // namespace facebook
79
+ #endif
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  #include "RNBlurhashTurboModule.h"
8
- #include "Blurhash.hpp"
8
+ #include "Blurhash.h"
9
9
  #include <sstream>
10
10
  #include <jsi/jsi.h>
11
11
  #include <react/renderer/components/view/ViewProps.h>
@@ -18,25 +18,31 @@ using namespace facebook;
18
18
 
19
19
  using Object = std::optional<jsi::Object>;
20
20
 
21
- static jsi::Value __hostFunction_RNBlurhashInstallModule_createBlurhashFromImage(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args,
22
- size_t count) {
23
-
21
+ static jsi::Value hostFunction_RNBlurhashInstallModule_createBlurhashFromImage(jsi::Runtime &rt,
22
+ react::TurboModule &turboModule, const jsi::Value *args,
23
+ size_t count)
24
+ {
24
25
  return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "createBlurhashFromImage", args, count);
25
26
  }
26
27
 
27
-
28
- void RNBlurhashTurboModule::clearCosineCache() {
28
+ void RNBlurhashTurboModule::clearCosineCache()
29
+ {
29
30
  ::blurhash::clearCache();
30
31
  return;
31
32
  }
32
33
 
33
- static jsi::Value __hostFunction_RNBlurhashInstallModule_clearCosineCache(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args, size_t count) {
34
+ static jsi::Value hostFunction_RNBlurhashInstallModule_clearCosineCache(jsi::Runtime &rt,
35
+ react::TurboModule &turboModule, const jsi::Value *args, size_t count)
36
+ {
34
37
  static_cast<RNBlurhashTurboModule *>(&turboModule)->clearCosineCache();
35
38
  return jsi::Value::undefined();
36
39
  };
37
40
 
38
41
 
39
- RNBlurhashTurboModule::RNBlurhashTurboModule(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
40
- methodMap_["clearCosineCache"] = MethodMetadata{0, __hostFunction_RNBlurhashInstallModule_clearCosineCache};
41
- methodMap_["createBlurhashFromImage"] = MethodMetadata{4, __hostFunction_RNBlurhashInstallModule_createBlurhashFromImage};
42
+ RNBlurhashTurboModule::RNBlurhashTurboModule(const ArkTSTurboModule::Context ctx,
43
+ const std::string name) : ArkTSTurboModule(ctx, name)
44
+ {
45
+ methodMap_["clearCosineCache"] = MethodMetadata{0, hostFunction_RNBlurhashInstallModule_clearCosineCache};
46
+ methodMap_["createBlurhashFromImage"] = MethodMetadata{
47
+ 4, hostFunction_RNBlurhashInstallModule_createBlurhashFromImage};
42
48
  }
@@ -3,17 +3,17 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
+ #ifndef RNBLURHASHTURBOMODULE_H
7
+ #define RNBLURHASHTURBOMODULE_H
6
8
  #pragma once
7
9
 
8
10
  #include <ReactCommon/TurboModule.h>
9
11
  #include "RNOH/ArkTSTurboModule.h"
10
12
  namespace rnoh {
11
-
12
13
  class JSI_EXPORT RNBlurhashTurboModule : public ArkTSTurboModule {
13
14
  public:
14
15
  RNBlurhashTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
15
-
16
16
  void clearCosineCache();
17
-
18
17
  };
19
18
  } // namespace rnoh
19
+ #endif
@@ -8,8 +8,7 @@
8
8
 
9
9
  namespace facebook {
10
10
  namespace react {
11
-
12
- extern const char BlurhashViewComponentName[] = "BlurhashView";
11
+ const char BlurhashViewComponentName[] = "BlurhashView";
13
12
 
14
13
  } // namespace react
15
14
  } // namespace facebook
@@ -3,7 +3,8 @@
3
3
  * Use of this source code is governed by a MIT license that can be
4
4
  * found in the LICENSE file.
5
5
  */
6
-
6
+ #ifndef BLURHASH_SHADOWNODES_H
7
+ #define BLURHASH_SHADOWNODES_H
7
8
  #pragma once
8
9
  #include "Props.h"
9
10
  #include "EventEmitters.h"
@@ -13,8 +14,7 @@
13
14
  namespace facebook {
14
15
  namespace react {
15
16
 
16
- JSI_EXPORT extern const char BlurhashViewComponentName[];
17
-
17
+ JSI_EXPORT extern const char BlurhashViewComponentName[32];
18
18
  /*
19
19
  * `ShadowNode` for <BlurhashView> component.
20
20
  */
@@ -22,6 +22,6 @@ using BlurhashViewShadowNode = ConcreteViewShadowNode<
22
22
  BlurhashViewComponentName,
23
23
  BlurhashViewProps,
24
24
  BlurhashViewEventEmitter>;
25
-
26
25
  } // namespace react
27
- } // namespace facebook
26
+ } // namespace facebook
27
+ #endif
@@ -9,7 +9,8 @@
9
9
 
10
10
  template <typename T> void SparseArray<T>::set(int key, const T &value) { data[key] = value; }
11
11
 
12
- template <typename T> T SparseArray<T>::get(int key) const {
12
+ template <typename T> T SparseArray<T>::get(int key) const
13
+ {
13
14
  auto it = data.find(key);
14
15
  if (it != data.end()) {
15
16
  return it->second;
@@ -21,8 +22,10 @@ template <typename T> void SparseArray<T>::remove(int key) { data.erase(key); }
21
22
 
22
23
  template <typename T> void SparseArray<T>::clear() { data.clear(); }
23
24
 
24
- template <typename T> bool SparseArray<T>::containsKey(int key) const { return data.find(key) != data.end(); }
25
-
25
+ template <typename T> bool SparseArray<T>::containsKey(int key) const
26
+ {
27
+ return data.find(key) != data.end();
28
+ }
26
29
  // 显式实例化模板类
27
30
  template class SparseArray<std::vector<double>>;
28
- template class SparseArray<std::vector<int>>;
31
+ template class SparseArray<std::vector<int>>;
@@ -4,8 +4,8 @@
4
4
  * found in the LICENSE file.
5
5
  */
6
6
 
7
- #ifndef SPARSEARRAY_H
8
- #define SPARSEARRAY_H
7
+ #ifndef BLURHASH_SPARSEARRAY_H
8
+ #define BLURHASH_SPARSEARRAY_H
9
9
 
10
10
  #include <unordered_map>
11
11
  #include <vector>
@@ -23,19 +23,18 @@
23
23
  */
24
24
 
25
25
  #include "RNOH/ArkJS.h"
26
- #include "Blurhash.hpp"
26
+ #include "Blurhash.h"
27
27
  #include "napi/native_api.h"
28
28
 
29
29
 
30
- static napi_value getEncode(napi_env env, napi_callback_info info){
30
+ static napi_value getEncode(napi_env env, napi_callback_info info)
31
+ {
31
32
  ArkJS arkJs(env);
32
33
  auto args = arkJs.getCallbackArgs(info, 3);
33
34
  std::string filename = arkJs.getString(args[0]);
34
35
  int components_x = arkJs.getInteger(args[1]);
35
36
  int components_y = arkJs.getInteger(args[2]);
36
-
37
- std::string blurhashcode = blurhash::encode(filename.c_str(),components_x,components_y);
38
-
37
+ std::string blurhashcode = blurhash::encode(filename.c_str(), components_x, components_y);
39
38
  napi_value val;
40
39
  napi_create_string_utf8(env, blurhashcode.c_str(), blurhashcode.size(), &val);
41
40
  return val;
@@ -32,6 +32,7 @@ import type {
32
32
  import { RNBlurhashModule } from './BlurhashTurboModule';
33
33
  import { BlurhashModule } from './TMSpecs'
34
34
  import { BlurhashView} from './RNCSpecs'
35
+ import { RNOHPackage } from '@rnoh/react-native-openharmony'
35
36
 
36
37
  class BlurhashTurboModulesFactory extends TurboModulesFactory {
37
38
  createTurboModule(name: string): TurboModule | null {
@@ -46,13 +47,13 @@ class BlurhashTurboModulesFactory extends TurboModulesFactory {
46
47
  }
47
48
  }
48
49
 
49
- export class BlurhashPackage extends RNPackage {
50
+ export class BlurhashPackage extends RNOHPackage {
50
51
  createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
51
52
  return new BlurhashTurboModulesFactory(ctx);
52
53
  }
53
54
  createDescriptorWrapperFactoryByDescriptorType(ctx: DescriptorWrapperFactoryByDescriptorTypeCtx): DescriptorWrapperFactoryByDescriptorType {
54
55
  return {
55
- [BlurhashView.NAME]: (ctx) => new BlurhashView.DescriptorWrapper(ctx.descriptor)
56
+ "BlurhashView": (ctx) => new BlurhashView.DescriptorWrapper(ctx.descriptor)
56
57
  }
57
58
  }
58
59
  }
@@ -22,5 +22,5 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export * from "./src/main/ets/BlurhashPackage"
25
+ export * from "./src/main/ets/BlurhashPackage.ets"
26
26
  export * from "./src/main/ets/BlurhashTurboModule"
Binary file