@react-native-ohos/react-native-blurhash 2.0.4-rc.4 → 2.1.0

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 (64) hide show
  1. package/harmony/blurhash/BuildProfile.ets +17 -0
  2. package/harmony/blurhash/index.ets +0 -2
  3. package/harmony/blurhash/oh-package.json5 +1 -1
  4. package/harmony/blurhash/src/main/cpp/Blurhash.cpp +78 -172
  5. package/harmony/blurhash/src/main/cpp/{Blurhash.h → Blurhash.hpp} +3 -6
  6. package/harmony/blurhash/src/main/cpp/BlurhashNode.cpp +12 -18
  7. package/harmony/blurhash/src/main/cpp/BlurhashNode.h +2 -3
  8. package/harmony/blurhash/src/main/cpp/BlurhashPackage.h +12 -23
  9. package/harmony/blurhash/src/main/cpp/BlurhashViewComponentInstance.cpp +82 -56
  10. package/harmony/blurhash/src/main/cpp/BlurhashViewComponentInstance.h +5 -8
  11. package/harmony/blurhash/src/main/cpp/BlurhashViewJSIBinder.h +7 -11
  12. package/harmony/blurhash/src/main/cpp/ComponentDescriptors.h +2 -4
  13. package/harmony/blurhash/src/main/cpp/EventEmitters.cpp +8 -9
  14. package/harmony/blurhash/src/main/cpp/EventEmitters.h +4 -4
  15. package/harmony/blurhash/src/main/cpp/Props.cpp +10 -11
  16. package/harmony/blurhash/src/main/cpp/Props.h +13 -19
  17. package/harmony/blurhash/src/main/cpp/RNBlurhashTurboModule.cpp +10 -16
  18. package/harmony/blurhash/src/main/cpp/RNBlurhashTurboModule.h +3 -3
  19. package/harmony/blurhash/src/main/cpp/ShadowNodes.cpp +2 -1
  20. package/harmony/blurhash/src/main/cpp/ShadowNodes.h +5 -5
  21. package/harmony/blurhash/src/main/cpp/SparseArray.cpp +4 -7
  22. package/harmony/blurhash/src/main/cpp/SparseArray.h +2 -2
  23. package/harmony/blurhash/src/main/cpp/napi_init.cpp +6 -5
  24. package/harmony/blurhash/src/main/cpp/types/libblurhash/Index.d.ts +1 -1
  25. package/harmony/blurhash/src/main/ets/{BlurhashPackage.ets → BlurhashPackage.ts} +2 -3
  26. package/harmony/blurhash/src/main/ets/BlurhashTurboModule.ts +2 -1
  27. package/{lib/commonjs/blurhash/ts.ets → harmony/blurhash/ts.ts} +1 -1
  28. package/harmony/blurhash.har +0 -0
  29. package/lib/commonjs/index.js +95 -0
  30. package/lib/commonjs/index.js.map +1 -0
  31. package/lib/commonjs/specs/NativeBlurhashModule.js +9 -0
  32. package/lib/commonjs/specs/NativeBlurhashModule.js.map +1 -0
  33. package/lib/commonjs/specs/NativeBlurhashView.js +10 -0
  34. package/lib/commonjs/specs/NativeBlurhashView.js.map +1 -0
  35. package/lib/commonjs/utils.js +56 -0
  36. package/lib/commonjs/utils.js.map +1 -0
  37. package/lib/module/index.js +85 -0
  38. package/lib/module/index.js.map +1 -0
  39. package/lib/module/specs/NativeBlurhashModule.js +3 -0
  40. package/lib/module/specs/NativeBlurhashModule.js.map +1 -0
  41. package/lib/module/specs/NativeBlurhashView.js +3 -0
  42. package/lib/module/specs/NativeBlurhashView.js.map +1 -0
  43. package/lib/module/utils.js +48 -0
  44. package/lib/module/utils.js.map +1 -0
  45. package/lib/typescript/index.d.ts +90 -0
  46. package/lib/typescript/specs/NativeBlurhashModule.d.ts +9 -0
  47. package/lib/typescript/specs/NativeBlurhashView.d.ts +19 -0
  48. package/lib/typescript/utils.d.ts +22 -0
  49. package/package.json +5 -12
  50. package/harmony/blurhash/ts.ets +0 -26
  51. package/lib/commonjs/blurhash/hvigorfile.js +0 -13
  52. package/lib/commonjs/blurhash/hvigorfile.js.map +0 -1
  53. package/lib/commonjs/blurhash/oh-package.json5 +0 -13
  54. package/lib/commonjs/blurhash/src/main/ets/BlurhashTurboModule.js +0 -49
  55. package/lib/commonjs/blurhash/src/main/ets/BlurhashTurboModule.js.map +0 -1
  56. package/lib/commonjs/blurhash/src/main/ets/Logger.js +0 -66
  57. package/lib/commonjs/blurhash/src/main/ets/Logger.js.map +0 -1
  58. package/lib/commonjs/blurhash/src/main/ets/RNCBlurhashView.js +0 -111
  59. package/lib/commonjs/blurhash/src/main/ets/RNCBlurhashView.js.map +0 -1
  60. package/lib/commonjs/blurhash/src/main/ets/RNCSpecs.js +0 -117
  61. package/lib/commonjs/blurhash/src/main/ets/RNCSpecs.js.map +0 -1
  62. package/lib/commonjs/blurhash/src/main/ets/TMSpecs.js +0 -34
  63. package/lib/commonjs/blurhash/src/main/ets/TMSpecs.js.map +0 -1
  64. package/lib/commonjs/blurhash.har +0 -0
@@ -3,8 +3,9 @@
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
7
  #include "BlurhashViewComponentInstance.h"
7
- #include "Blurhash.h"
8
+ #include "Blurhash.hpp"
8
9
  #include "Props.h"
9
10
  #include <filemanagement/file_uri/oh_file_uri.h>
10
11
  #include "RNBlurhashTurboModule.h"
@@ -12,100 +13,125 @@
12
13
  #include <iomanip>
13
14
  #include <react/renderer/core/ConcreteState.h>
14
15
  #include <sstream>
16
+ #include <cstdio>
15
17
 
16
18
  namespace rnoh {
17
19
 
18
- BlurhashViewComponentInstance::BlurhashViewComponentInstance(Context context)
19
- : CppComponentInstance(std::move(context))
20
- {
20
+ BlurhashViewComponentInstance::BlurhashViewComponentInstance(Context context) : CppComponentInstance(std::move(context)) {
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
31
32
  if (props->blurhash == "") {
32
- m_eventEmitter->onLoadError({"The provided Blurhash string must not be null!"});
33
- };
33
+ if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "The provided Blurhash string must not be empty!"});
34
+ return;
35
+ }
34
36
  if (props->decodeWidth <= 0) {
35
- m_eventEmitter->onLoadError({"decodeWidth must be greater than 0!"});
36
- };
37
+ if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "decodeWidth must be greater than 0!"});
38
+ return;
39
+ }
37
40
  if (props->decodeHeight <= 0) {
38
- m_eventEmitter->onLoadError({"decodeHeight must be greater than 0!"});
39
- };
41
+ if (m_eventEmitter) m_eventEmitter->onLoadError({.message = "decodeHeight must be greater than 0!"});
42
+ return;
43
+ }
40
44
  if (props->decodePunch <= 0) {
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);
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/rn_image_cache/" + absPath;
65
+ }
66
+
67
+ const char *path = absPath.c_str();
68
+ unsigned int length = static_cast<unsigned int>(absPath.size());
49
69
  char *result = nullptr;
50
70
  FileManagement_ErrCode ret = OH_FileUri_GetUriFromPath(path, length, &result);
51
- this->getLocalRootArkUINode().setSource(std::string(result));
52
- if (result != nullptr) {
53
- free(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;
54
74
  }
75
+ std::string uriStr(result);
76
+ this->getLocalRootArkUINode().setSource(uriStr);
77
+ free(result);
55
78
  }
56
79
 
57
- std::string BlurhashViewComponentInstance::decodeImageByBlurhash(const std::string &blurhash,
58
- const int &width, const int &height, const float &punch)
59
- {
80
+ std::string BlurhashViewComponentInstance::decodeImageByBlurhash(const std::string &blurhash, const int &width, const int &height, const float &punch) {
81
+ std::string expectedName = blurhash + ".bmp";
60
82
  blurhash::decode(blurhash, width, height, punch);
61
83
  auto rnInstance = m_deps->rnInstance.lock();
62
84
  auto turboModule = rnInstance->getTurboModule("ImageLoader");
63
85
  auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
64
- auto cache = arkTsTurboModule->callSync("getPrefetchResult", {blurhash + ".bmp"});
65
- return cache.asString();
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;
66
99
  }
67
100
 
68
- BlurhashNode &BlurhashViewComponentInstance::getLocalRootArkUINode()
69
- {
70
- return m_imageNode;
71
- }
101
+ BlurhashNode &BlurhashViewComponentInstance::getLocalRootArkUINode() { return m_imageNode; }
72
102
 
73
- void BlurhashViewComponentInstance::onComplete()
74
- {
75
- m_eventEmitter->onLoadStart({});
76
- if (m_eventEmitter == nullptr) {
77
- return;
103
+ void BlurhashViewComponentInstance::onComplete() {
104
+ if (m_eventEmitter) {
105
+ m_eventEmitter->onLoadStart({});
106
+ m_eventEmitter->onLoadEnd({});
78
107
  }
79
- m_eventEmitter->onLoadEnd({});
80
108
  }
81
109
 
82
- void BlurhashViewComponentInstance::onError(int32_t errorCode)
83
- {
110
+ void BlurhashViewComponentInstance::onError(int32_t errorCode) {
84
111
  if (m_eventEmitter) {
85
- m_eventEmitter->onLoadError({""});
112
+ m_eventEmitter->onLoadError({.message = ""});
86
113
  }
87
114
  }
88
115
 
89
- void BlurhashViewComponentInstance::onLoadStart(SharedConcreteProps const &props)
90
- {
116
+ void BlurhashViewComponentInstance::onLoadStart(SharedConcreteProps const &props) {
91
117
  if (m_eventEmitter) {
92
- m_eventEmitter->onLoadStart({props->blurhash,
93
- props->decodeWidth, props->decodeHeight, props->decodePunch});
118
+ // RN 0.77: DirectEventHandler<null>
119
+ m_eventEmitter->onLoadStart({});
94
120
  }
95
121
  }
96
122
 
97
- facebook::react::ImageResizeMode BlurhashViewComponentInstance::convertToImageResizeMode(
98
- facebook::react::BlurhashViewResizeMode mode)
99
- {
123
+ facebook::react::ImageResizeMode BlurhashViewComponentInstance::convertToImageResizeMode(facebook::react::BlurhashViewResizeMode mode) {
100
124
  switch (mode) {
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;
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;
109
133
  }
134
+ // Fallback to avoid undefined behavior
135
+ return facebook::react::ImageResizeMode::Cover;
110
136
  }
111
137
  } // namespace rnoh
@@ -3,8 +3,7 @@
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 BLURHASHVIEWCOMPONENTINSTANCE_H
7
- #define BLURHASHVIEWCOMPONENTINSTANCE_H
6
+
8
7
  #pragma once
9
8
 
10
9
  #include "EventEmitters.h"
@@ -14,16 +13,15 @@
14
13
  #include "RNOH/arkui/ImageNode.h"
15
14
 
16
15
  namespace rnoh {
17
- class BlurhashViewComponentInstance : public CppComponentInstance<
18
- facebook::react::BlurhashViewShadowNode>, public BlurhashNodeDelegate {
16
+ class BlurhashViewComponentInstance : public CppComponentInstance<facebook::react::BlurhashViewShadowNode>, public BlurhashNodeDelegate {
19
17
  private:
20
18
  BlurhashNode m_imageNode;
21
19
  std::string m_uri;
22
20
 
23
- std::string decodeImageByBlurhash(std::string const &blurhash,
24
- int const &width, int const &height, float const &punch);
21
+ std::string decodeImageByBlurhash(std::string const &blurhash, int const &width, int const &height, float const &punch);
22
+
25
23
  public:
26
- explicit BlurhashViewComponentInstance(Context context);
24
+ BlurhashViewComponentInstance(Context context);
27
25
  void onPropsChanged(SharedConcreteProps const &props) override;
28
26
  void onComplete() override;
29
27
  void onLoadStart(SharedConcreteProps const &props);
@@ -34,4 +32,3 @@ public:
34
32
  BlurhashNode &getLocalRootArkUINode() override;
35
33
  };
36
34
  } // namespace rnoh
37
- #endif
@@ -3,8 +3,7 @@
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 BLURHASHVIEWJSIBINDER_H
7
- #define BLURHASHVIEWJSIBINDER_H
6
+
8
7
  #pragma once
9
8
 
10
9
  #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
@@ -12,8 +11,7 @@
12
11
  namespace rnoh {
13
12
  class BlurhashViewJSIBinder : public ViewComponentJSIBinder {
14
13
  protected:
15
- facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override
16
- {
14
+ facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
17
15
  auto object = ViewComponentJSIBinder::createNativeProps(rt);
18
16
  object.setProperty(rt, "imgUri", true);
19
17
  object.setProperty(rt, "blurhash", true);
@@ -25,14 +23,12 @@ protected:
25
23
  return object;
26
24
  }
27
25
 
28
- facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override
29
- {
26
+ facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
30
27
  facebook::jsi::Object events(rt);
31
- events.setProperty(rt, "topOnLoadStart", createDirectEvent(rt, "onLoadStart"));
32
- events.setProperty(rt, "topOnLoadEnd", createDirectEvent(rt, "onLoadEnd"));
33
- events.setProperty(rt, "topOnLoadError", createDirectEvent(rt, "onLoadError"));
28
+ events.setProperty(rt, "topLoadStart", createDirectEvent(rt, "onLoadStart"));
29
+ events.setProperty(rt, "topLoadEnd", createDirectEvent(rt, "onLoadEnd"));
30
+ events.setProperty(rt, "topLoadError", createDirectEvent(rt, "onLoadError"));
34
31
  return events;
35
32
  }
36
33
  };
37
- } // namespace rnoh
38
- #endif
34
+ } // namespace rnoh
@@ -3,8 +3,7 @@
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 COMPONENTDESCRIPTORS_H
7
- #define COMPONENTDESCRIPTORS_H
6
+
8
7
  #pragma once
9
8
 
10
9
  #include "ShadowNodes.h"
@@ -16,5 +15,4 @@ namespace react {
16
15
  using BlurhashViewComponentDescriptor = ConcreteComponentDescriptor<BlurhashViewShadowNode>;
17
16
 
18
17
  } // namespace react
19
- } // namespace facebook
20
- #endif
18
+ } // namespace facebook
@@ -10,28 +10,27 @@
10
10
  namespace facebook {
11
11
  namespace react {
12
12
 
13
- void BlurhashViewEventEmitter::onLoadError(OnLoadError event) const
14
- {
15
- dispatchEvent("onLoadError", [event = std::move(event)](jsi::Runtime &runtime) {
13
+ void BlurhashViewEventEmitter::onLoadError(OnLoadError event) const {
14
+ dispatchEvent("LoadError", [event = std::move(event)](jsi::Runtime &runtime) {
16
15
  auto payload = jsi::Object(runtime);
17
16
  payload.setProperty(runtime, "message", event.message);
18
17
  return payload;
19
18
  });
20
19
  }
21
20
 
22
- void BlurhashViewEventEmitter::onLoadEnd(OnLoadEnd event) const
23
- {
24
- dispatchEvent("onLoadEnd", [](jsi::Runtime &runtime) {
21
+ void BlurhashViewEventEmitter::onLoadEnd(OnLoadEnd event) const {
22
+ dispatchEvent("LoadEnd", [](jsi::Runtime &runtime) {
25
23
  auto payload = jsi::Object(runtime);
26
24
  return payload;
27
25
  });
28
26
  }
29
- void BlurhashViewEventEmitter::onLoadStart(OnLoadStart event) const
30
- {
31
- dispatchEvent("onLoadStart", [](jsi::Runtime &runtime) {
27
+ void BlurhashViewEventEmitter::onLoadStart(OnLoadStart event) const {
28
+ dispatchEvent("LoadStart", [](jsi::Runtime &runtime) {
32
29
  auto payload = jsi::Object(runtime);
33
30
  return payload;
34
31
  });
35
32
  }
33
+
34
+
36
35
  } // namespace react
37
36
  } // namespace facebook
@@ -3,8 +3,7 @@
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 BLURHASH_EVENTEMITTERS_H
7
- #define BLURHASH_EVENTEMITTERS_H
6
+
8
7
  #pragma once
9
8
 
10
9
  #include <react/renderer/components/view/ViewEventEmitter.h>
@@ -16,6 +15,7 @@ namespace react {
16
15
  class JSI_EXPORT BlurhashViewEventEmitter : public ViewEventEmitter {
17
16
  public:
18
17
  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
+
38
39
  } // namespace react
39
- } // namespace facebook
40
- #endif
40
+ } // namespace facebook
@@ -11,16 +11,15 @@
11
11
  namespace facebook {
12
12
  namespace react {
13
13
 
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})) {}
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
+
25
24
  } // namespace react
26
25
  } // namespace facebook
@@ -3,8 +3,7 @@
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 BLURHASH_PROPS_H
7
- #define BLURHASH_PROPS_H
6
+
8
7
  #pragma once
9
8
 
10
9
  #include <jsi/jsi.h>
@@ -19,9 +18,7 @@ namespace react {
19
18
 
20
19
  enum class BlurhashViewResizeMode { Contain, Cover, Stretch, Center };
21
20
 
22
- inline void fromRawValue(const PropsParserContext &context,
23
- const RawValue &value, BlurhashViewResizeMode &result)
24
- {
21
+ static inline void fromRawValue(const PropsParserContext &context, const RawValue &value, BlurhashViewResizeMode &result) {
25
22
  auto string = (std::string)value;
26
23
  if (string == "contain") {
27
24
  result = BlurhashViewResizeMode::Contain;
@@ -39,20 +36,19 @@ inline void fromRawValue(const PropsParserContext &context,
39
36
  result = BlurhashViewResizeMode::Center;
40
37
  return;
41
38
  }
42
- throw std::runtime_error("Invalid display type");
39
+ abort();
43
40
  }
44
41
 
45
- inline std::string toString(const BlurhashViewResizeMode &value)
46
- {
42
+ static inline std::string toString(const BlurhashViewResizeMode &value) {
47
43
  switch (value) {
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";
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";
56
52
  }
57
53
  }
58
54
 
@@ -61,8 +57,7 @@ enum class decodeWeight { defaltWeight };
61
57
  class JSI_EXPORT BlurhashViewProps final : public ViewProps {
62
58
  public:
63
59
  BlurhashViewProps() = default;
64
- BlurhashViewProps(const PropsParserContext &context,
65
- const BlurhashViewProps &sourceProps, const RawProps &rawProps);
60
+ BlurhashViewProps(const PropsParserContext &context, const BlurhashViewProps &sourceProps, const RawProps &rawProps);
66
61
 
67
62
  #pragma mark - Props
68
63
  std::string imgUri{};
@@ -76,4 +71,3 @@ public:
76
71
 
77
72
  } // namespace react
78
73
  } // namespace facebook
79
- #endif
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  #include "RNBlurhashTurboModule.h"
8
- #include "Blurhash.h"
8
+ #include "Blurhash.hpp"
9
9
  #include <sstream>
10
10
  #include <jsi/jsi.h>
11
11
  #include <react/renderer/components/view/ViewProps.h>
@@ -18,31 +18,25 @@ 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,
22
- react::TurboModule &turboModule, const jsi::Value *args,
23
- size_t count)
24
- {
21
+ static jsi::Value __hostFunction_RNBlurhashInstallModule_createBlurhashFromImage(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args,
22
+ size_t count) {
23
+
25
24
  return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "createBlurhashFromImage", args, count);
26
25
  }
27
26
 
28
- void RNBlurhashTurboModule::clearCosineCache()
29
- {
27
+
28
+ void RNBlurhashTurboModule::clearCosineCache() {
30
29
  ::blurhash::clearCache();
31
30
  return;
32
31
  }
33
32
 
34
- static jsi::Value hostFunction_RNBlurhashInstallModule_clearCosineCache(jsi::Runtime &rt,
35
- react::TurboModule &turboModule, const jsi::Value *args, size_t count)
36
- {
33
+ static jsi::Value __hostFunction_RNBlurhashInstallModule_clearCosineCache(jsi::Runtime &rt, react::TurboModule &turboModule, const jsi::Value *args, size_t count) {
37
34
  static_cast<RNBlurhashTurboModule *>(&turboModule)->clearCosineCache();
38
35
  return jsi::Value::undefined();
39
36
  };
40
37
 
41
38
 
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};
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};
48
42
  }
@@ -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
8
6
  #pragma once
9
7
 
10
8
  #include <ReactCommon/TurboModule.h>
11
9
  #include "RNOH/ArkTSTurboModule.h"
12
10
  namespace rnoh {
11
+
13
12
  class JSI_EXPORT RNBlurhashTurboModule : public ArkTSTurboModule {
14
13
  public:
15
14
  RNBlurhashTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
15
+
16
16
  void clearCosineCache();
17
+
17
18
  };
18
19
  } // namespace rnoh
19
- #endif
@@ -8,7 +8,8 @@
8
8
 
9
9
  namespace facebook {
10
10
  namespace react {
11
- const char BlurhashViewComponentName[] = "BlurhashView";
11
+
12
+ extern const char BlurhashViewComponentName[] = "BlurhashView";
12
13
 
13
14
  } // namespace react
14
15
  } // namespace facebook
@@ -3,8 +3,7 @@
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 BLURHASH_SHADOWNODES_H
7
- #define BLURHASH_SHADOWNODES_H
6
+
8
7
  #pragma once
9
8
  #include "Props.h"
10
9
  #include "EventEmitters.h"
@@ -14,7 +13,8 @@
14
13
  namespace facebook {
15
14
  namespace react {
16
15
 
17
- JSI_EXPORT extern const char BlurhashViewComponentName[32];
16
+ JSI_EXPORT extern const char BlurhashViewComponentName[];
17
+
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
+
25
26
  } // namespace react
26
- } // namespace facebook
27
- #endif
27
+ } // namespace facebook
@@ -9,8 +9,7 @@
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
13
- {
12
+ template <typename T> T SparseArray<T>::get(int key) const {
14
13
  auto it = data.find(key);
15
14
  if (it != data.end()) {
16
15
  return it->second;
@@ -22,10 +21,8 @@ template <typename T> void SparseArray<T>::remove(int key) { data.erase(key); }
22
21
 
23
22
  template <typename T> void SparseArray<T>::clear() { data.clear(); }
24
23
 
25
- template <typename T> bool SparseArray<T>::containsKey(int key) const
26
- {
27
- return data.find(key) != data.end();
28
- }
24
+ template <typename T> bool SparseArray<T>::containsKey(int key) const { return data.find(key) != data.end(); }
25
+
29
26
  // 显式实例化模板类
30
27
  template class SparseArray<std::vector<double>>;
31
- template class SparseArray<std::vector<int>>;
28
+ template class SparseArray<std::vector<int>>;
@@ -4,8 +4,8 @@
4
4
  * found in the LICENSE file.
5
5
  */
6
6
 
7
- #ifndef BLURHASH_SPARSEARRAY_H
8
- #define BLURHASH_SPARSEARRAY_H
7
+ #ifndef SPARSEARRAY_H
8
+ #define SPARSEARRAY_H
9
9
 
10
10
  #include <unordered_map>
11
11
  #include <vector>
@@ -23,18 +23,19 @@
23
23
  */
24
24
 
25
25
  #include "RNOH/ArkJS.h"
26
- #include "Blurhash.h"
26
+ #include "Blurhash.hpp"
27
27
  #include "napi/native_api.h"
28
28
 
29
29
 
30
- static napi_value getEncode(napi_env env, napi_callback_info info)
31
- {
30
+ static napi_value getEncode(napi_env env, napi_callback_info info){
32
31
  ArkJS arkJs(env);
33
32
  auto args = arkJs.getCallbackArgs(info, 3);
34
- std::string filepath = arkJs.getString(args[0]);
33
+ std::string filename = arkJs.getString(args[0]);
35
34
  int components_x = arkJs.getInteger(args[1]);
36
35
  int components_y = arkJs.getInteger(args[2]);
37
- std::string blurhashcode = blurhash::encode(filepath.c_str(), components_x, components_y);
36
+
37
+ std::string blurhashcode = blurhash::encode(filename.c_str(),components_x,components_y);
38
+
38
39
  napi_value val;
39
40
  napi_create_string_utf8(env, blurhashcode.c_str(), blurhashcode.size(), &val);
40
41
  return val;
@@ -1 +1 @@
1
- export const getEncode: (filepath: String, components_x: Number, components_y: Number) => string;
1
+ export const getEncode: (filename: String, components_x: Number, components_y: Number) => string;
@@ -32,7 +32,6 @@ 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'
36
35
 
37
36
  class BlurhashTurboModulesFactory extends TurboModulesFactory {
38
37
  createTurboModule(name: string): TurboModule | null {
@@ -47,13 +46,13 @@ class BlurhashTurboModulesFactory extends TurboModulesFactory {
47
46
  }
48
47
  }
49
48
 
50
- export class BlurhashPackage extends RNOHPackage {
49
+ export class BlurhashPackage extends RNPackage {
51
50
  createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
52
51
  return new BlurhashTurboModulesFactory(ctx);
53
52
  }
54
53
  createDescriptorWrapperFactoryByDescriptorType(ctx: DescriptorWrapperFactoryByDescriptorTypeCtx): DescriptorWrapperFactoryByDescriptorType {
55
54
  return {
56
- "BlurhashView": (ctx) => new BlurhashView.DescriptorWrapper(ctx.descriptor)
55
+ [BlurhashView.NAME]: (ctx) => new BlurhashView.DescriptorWrapper(ctx.descriptor)
57
56
  }
58
57
  }
59
58
  }
@@ -40,7 +40,8 @@ export class RNBlurhashModule extends TurboModule implements BlurhashModule.Spec
40
40
  const RemoteImageLoader = this.ctx.rnInstance.getTurboModule<RemoteImageLoader>("ImageLoader");
41
41
  await imageLoader.prefetchImage(imageUri)
42
42
  const filePath = RemoteImageLoader.getPrefetchResult(imageUri)
43
- const blurhashcode = rnKeysCPPLib.getEncode(filePath.replace('file://', ''),componentsX,componentsY)
43
+ const fileName = filePath.split('/').pop();
44
+ const blurhashcode = rnKeysCPPLib.getEncode(fileName,componentsX,componentsY)
44
45
  return (blurhashcode);
45
46
  }
46
47