@react-native-vector-icons/common 0.0.1-alpha.20 → 0.0.1-alpha.23

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 (163) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +40 -182
  3. package/android/build.gradle +36 -2
  4. package/android/generated/java/com/reactnativevectoricons/common/NativeVectorIconsSpec.java +42 -0
  5. package/android/generated/jni/CMakeLists.txt +49 -0
  6. package/android/generated/jni/RNVectorIconsSpec-generated.cpp +38 -0
  7. package/android/generated/jni/RNVectorIconsSpec.h +31 -0
  8. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.cpp +22 -0
  9. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.h +24 -0
  10. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/EventEmitters.cpp +16 -0
  11. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/EventEmitters.h +17 -0
  12. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/Props.cpp +19 -0
  13. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/Props.h +18 -0
  14. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/RNVectorIconsSpecJSI-generated.cpp +40 -0
  15. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/RNVectorIconsSpecJSI.h +76 -0
  16. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/ShadowNodes.cpp +17 -0
  17. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/ShadowNodes.h +23 -0
  18. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/States.cpp +16 -0
  19. package/android/generated/jni/react/renderer/components/RNVectorIconsSpec/States.h +19 -0
  20. package/android/src/main/AndroidManifestNew.xml +1 -1
  21. package/android/src/main/java/com/reactnativevectoricons/common/VectorIconsModule.kt +90 -0
  22. package/android/src/main/java/com/reactnativevectoricons/common/VectorIconsPackage.kt +35 -0
  23. package/android/src/newarch/VectorIconsSpec.kt +7 -0
  24. package/android/src/oldarch/VectorIconsSpec.kt +38 -0
  25. package/ios/VectorIcons.h +13 -17
  26. package/ios/VectorIcons.mm +21 -51
  27. package/ios/generated/RNVectorIconsSpec/ComponentDescriptors.cpp +22 -0
  28. package/ios/generated/RNVectorIconsSpec/ComponentDescriptors.h +24 -0
  29. package/ios/generated/RNVectorIconsSpec/EventEmitters.cpp +16 -0
  30. package/ios/generated/RNVectorIconsSpec/EventEmitters.h +17 -0
  31. package/ios/generated/RNVectorIconsSpec/Props.cpp +19 -0
  32. package/ios/generated/RNVectorIconsSpec/Props.h +18 -0
  33. package/ios/generated/RNVectorIconsSpec/RCTComponentViewHelpers.h +18 -0
  34. package/ios/generated/RNVectorIconsSpec/RNVectorIconsSpec-generated.mm +36 -0
  35. package/ios/generated/RNVectorIconsSpec/RNVectorIconsSpec.h +58 -0
  36. package/ios/generated/RNVectorIconsSpec/ShadowNodes.cpp +17 -0
  37. package/ios/generated/RNVectorIconsSpec/ShadowNodes.h +23 -0
  38. package/ios/generated/RNVectorIconsSpec/States.cpp +16 -0
  39. package/ios/generated/RNVectorIconsSpec/States.h +19 -0
  40. package/ios/generated/RNVectorIconsSpecJSI-generated.cpp +40 -0
  41. package/ios/generated/RNVectorIconsSpecJSI.h +76 -0
  42. package/lib/commonjs/NativeVectorIcons.js.map +1 -1
  43. package/lib/commonjs/create-icon-set.js +48 -19
  44. package/lib/commonjs/create-icon-set.js.map +1 -1
  45. package/lib/commonjs/dynamicLoading/dynamic-font-loading.js +92 -0
  46. package/lib/commonjs/dynamicLoading/dynamic-font-loading.js.map +1 -0
  47. package/lib/commonjs/dynamicLoading/dynamic-font-loading.web.js +20 -0
  48. package/lib/commonjs/dynamicLoading/dynamic-font-loading.web.js.map +1 -0
  49. package/lib/commonjs/dynamicLoading/dynamic-loading-setting.js +50 -0
  50. package/lib/commonjs/dynamicLoading/dynamic-loading-setting.js.map +1 -0
  51. package/lib/commonjs/dynamicLoading/types.js +2 -0
  52. package/lib/commonjs/dynamicLoading/types.js.map +1 -0
  53. package/lib/commonjs/index.js +57 -1
  54. package/lib/commonjs/index.js.map +1 -1
  55. package/lib/commonjs/scripts/getFonts.js +1 -1
  56. package/lib/commonjs/scripts/updatePlist.js +1 -1
  57. package/lib/module/NativeVectorIcons.js +2 -0
  58. package/lib/module/NativeVectorIcons.js.map +1 -1
  59. package/lib/module/NativeVectorIcons.web.js +2 -0
  60. package/lib/module/NativeVectorIcons.web.js.map +1 -1
  61. package/lib/module/create-icon-set.js +49 -18
  62. package/lib/module/create-icon-set.js.map +1 -1
  63. package/lib/module/create-icon-source-cache.js +2 -0
  64. package/lib/module/create-icon-source-cache.js.map +1 -1
  65. package/lib/module/dynamicLoading/dynamic-font-loading.js +85 -0
  66. package/lib/module/dynamicLoading/dynamic-font-loading.js.map +1 -0
  67. package/lib/module/dynamicLoading/dynamic-font-loading.web.js +16 -0
  68. package/lib/module/dynamicLoading/dynamic-font-loading.web.js.map +1 -0
  69. package/lib/module/dynamicLoading/dynamic-loading-setting.js +41 -0
  70. package/lib/module/dynamicLoading/dynamic-loading-setting.js.map +1 -0
  71. package/lib/module/dynamicLoading/types.js +2 -0
  72. package/lib/module/dynamicLoading/types.js.map +1 -0
  73. package/lib/module/ensure-native-module-available.js +2 -0
  74. package/lib/module/ensure-native-module-available.js.map +1 -1
  75. package/lib/module/index.js +33 -1
  76. package/lib/module/index.js.map +1 -1
  77. package/lib/module/scripts/common.js +2 -0
  78. package/lib/module/scripts/common.js.map +1 -1
  79. package/lib/module/scripts/getFonts.js +3 -1
  80. package/lib/module/scripts/getFonts.js.map +1 -1
  81. package/lib/module/scripts/updatePlist.js +3 -1
  82. package/lib/module/scripts/updatePlist.js.map +1 -1
  83. package/lib/typescript/commonjs/package.json +1 -0
  84. package/lib/typescript/commonjs/src/NativeVectorIcons.d.ts +8 -0
  85. package/lib/typescript/commonjs/src/NativeVectorIcons.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/src/NativeVectorIcons.web.d.ts.map +1 -0
  87. package/lib/typescript/commonjs/src/create-icon-set.d.ts +36 -0
  88. package/lib/typescript/commonjs/src/create-icon-set.d.ts.map +1 -0
  89. package/lib/typescript/commonjs/src/create-icon-source-cache.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.d.ts +3 -0
  91. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.web.d.ts +6 -0
  93. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.web.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts +41 -0
  95. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/src/dynamicLoading/types.d.ts +9 -0
  97. package/lib/typescript/commonjs/src/dynamicLoading/types.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/ensure-native-module-available.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/src/index.d.ts +6 -0
  100. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/src/scripts/common.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/scripts/getFonts.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/src/scripts/updatePlist.d.ts.map +1 -0
  104. package/lib/typescript/module/package.json +1 -0
  105. package/lib/typescript/module/src/NativeVectorIcons.d.ts +8 -0
  106. package/lib/typescript/module/src/NativeVectorIcons.d.ts.map +1 -0
  107. package/lib/typescript/module/src/NativeVectorIcons.web.d.ts +3 -0
  108. package/lib/typescript/module/src/NativeVectorIcons.web.d.ts.map +1 -0
  109. package/lib/typescript/module/src/create-icon-set.d.ts +36 -0
  110. package/lib/typescript/module/src/create-icon-set.d.ts.map +1 -0
  111. package/lib/typescript/module/src/create-icon-source-cache.d.ts +21 -0
  112. package/lib/typescript/module/src/create-icon-source-cache.d.ts.map +1 -0
  113. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.d.ts +3 -0
  114. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.d.ts.map +1 -0
  115. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.web.d.ts +6 -0
  116. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.web.d.ts.map +1 -0
  117. package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts +41 -0
  118. package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts.map +1 -0
  119. package/lib/typescript/module/src/dynamicLoading/types.d.ts +9 -0
  120. package/lib/typescript/module/src/dynamicLoading/types.d.ts.map +1 -0
  121. package/lib/typescript/module/src/ensure-native-module-available.d.ts +2 -0
  122. package/lib/typescript/module/src/ensure-native-module-available.d.ts.map +1 -0
  123. package/lib/typescript/module/src/index.d.ts +6 -0
  124. package/lib/typescript/module/src/index.d.ts.map +1 -0
  125. package/lib/typescript/module/src/scripts/common.d.ts +2 -0
  126. package/lib/typescript/module/src/scripts/common.d.ts.map +1 -0
  127. package/lib/typescript/module/src/scripts/getFonts.d.ts +3 -0
  128. package/lib/typescript/module/src/scripts/getFonts.d.ts.map +1 -0
  129. package/lib/typescript/module/src/scripts/updatePlist.d.ts +3 -0
  130. package/lib/typescript/module/src/scripts/updatePlist.d.ts.map +1 -0
  131. package/package.json +66 -43
  132. package/react-native-vector-icons.podspec +26 -26
  133. package/react-native.config.js +12 -0
  134. package/src/NativeVectorIcons.ts +2 -4
  135. package/src/create-icon-set.tsx +79 -12
  136. package/src/dynamicLoading/dynamic-font-loading.ts +97 -0
  137. package/src/dynamicLoading/dynamic-font-loading.web.ts +15 -0
  138. package/src/dynamicLoading/dynamic-loading-setting.ts +77 -0
  139. package/src/dynamicLoading/types.ts +10 -0
  140. package/src/index.ts +48 -1
  141. package/src/scripts/getFonts.ts +1 -1
  142. package/android/src/main/java/com/reactnativevectoricons/common/VectorIconsModule.java +0 -121
  143. package/android/src/main/java/com/reactnativevectoricons/common/VectorIconsPackage.java +0 -45
  144. package/android/src/newarch/VectorIconsSpec.java +0 -9
  145. package/android/src/oldarch/VectorIconsSpec.java +0 -18
  146. package/lib/typescript/src/NativeVectorIcons.d.ts +0 -9
  147. package/lib/typescript/src/NativeVectorIcons.d.ts.map +0 -1
  148. package/lib/typescript/src/NativeVectorIcons.web.d.ts.map +0 -1
  149. package/lib/typescript/src/create-icon-set.d.ts +0 -26
  150. package/lib/typescript/src/create-icon-set.d.ts.map +0 -1
  151. package/lib/typescript/src/create-icon-source-cache.d.ts.map +0 -1
  152. package/lib/typescript/src/ensure-native-module-available.d.ts.map +0 -1
  153. package/lib/typescript/src/index.d.ts +0 -3
  154. package/lib/typescript/src/index.d.ts.map +0 -1
  155. package/lib/typescript/src/scripts/common.d.ts.map +0 -1
  156. package/lib/typescript/src/scripts/getFonts.d.ts.map +0 -1
  157. package/lib/typescript/src/scripts/updatePlist.d.ts.map +0 -1
  158. /package/lib/typescript/{src → commonjs/src}/NativeVectorIcons.web.d.ts +0 -0
  159. /package/lib/typescript/{src → commonjs/src}/create-icon-source-cache.d.ts +0 -0
  160. /package/lib/typescript/{src → commonjs/src}/ensure-native-module-available.d.ts +0 -0
  161. /package/lib/typescript/{src → commonjs/src}/scripts/common.d.ts +0 -0
  162. /package/lib/typescript/{src → commonjs/src}/scripts/getFonts.d.ts +0 -0
  163. /package/lib/typescript/{src → commonjs/src}/scripts/updatePlist.d.ts +0 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleCpp.js
8
+ */
9
+
10
+ #include "RNVectorIconsSpecJSI.h"
11
+
12
+ namespace facebook::react {
13
+
14
+ static jsi::Value __hostFunction_NativeVectorIconsCxxSpecJSI_getImageForFont(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
15
+ return static_cast<NativeVectorIconsCxxSpecJSI *>(&turboModule)->getImageForFont(
16
+ rt,
17
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
18
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt),
19
+ count <= 2 ? throw jsi::JSError(rt, "Expected argument in position 2 to be passed") : args[2].asNumber(),
20
+ count <= 3 ? throw jsi::JSError(rt, "Expected argument in position 3 to be passed") : args[3].asNumber()
21
+ );
22
+ }
23
+ static jsi::Value __hostFunction_NativeVectorIconsCxxSpecJSI_getImageForFontSync(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
24
+ return static_cast<NativeVectorIconsCxxSpecJSI *>(&turboModule)->getImageForFontSync(
25
+ rt,
26
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
27
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt),
28
+ count <= 2 ? throw jsi::JSError(rt, "Expected argument in position 2 to be passed") : args[2].asNumber(),
29
+ count <= 3 ? throw jsi::JSError(rt, "Expected argument in position 3 to be passed") : args[3].asNumber()
30
+ );
31
+ }
32
+
33
+ NativeVectorIconsCxxSpecJSI::NativeVectorIconsCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
34
+ : TurboModule("VectorIcons", jsInvoker) {
35
+ methodMap_["getImageForFont"] = MethodMetadata {4, __hostFunction_NativeVectorIconsCxxSpecJSI_getImageForFont};
36
+ methodMap_["getImageForFontSync"] = MethodMetadata {4, __hostFunction_NativeVectorIconsCxxSpecJSI_getImageForFontSync};
37
+ }
38
+
39
+
40
+ } // namespace facebook::react
@@ -0,0 +1,76 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleH.js
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <ReactCommon/TurboModule.h>
13
+ #include <react/bridging/Bridging.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+ class JSI_EXPORT NativeVectorIconsCxxSpecJSI : public TurboModule {
19
+ protected:
20
+ NativeVectorIconsCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
21
+
22
+ public:
23
+ virtual jsi::Value getImageForFont(jsi::Runtime &rt, jsi::String fontFamilyName, jsi::String glyph, double fontSize, double color) = 0;
24
+ virtual jsi::String getImageForFontSync(jsi::Runtime &rt, jsi::String fontFamilyName, jsi::String glyph, double fontSize, double color) = 0;
25
+
26
+ };
27
+
28
+ template <typename T>
29
+ class JSI_EXPORT NativeVectorIconsCxxSpec : public TurboModule {
30
+ public:
31
+ jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
32
+ return delegate_.get(rt, propName);
33
+ }
34
+
35
+ static constexpr std::string_view kModuleName = "VectorIcons";
36
+
37
+ protected:
38
+ NativeVectorIconsCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
39
+ : TurboModule(std::string{NativeVectorIconsCxxSpec::kModuleName}, jsInvoker),
40
+ delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
41
+
42
+
43
+ private:
44
+ class Delegate : public NativeVectorIconsCxxSpecJSI {
45
+ public:
46
+ Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
47
+ NativeVectorIconsCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
48
+
49
+ }
50
+
51
+ jsi::Value getImageForFont(jsi::Runtime &rt, jsi::String fontFamilyName, jsi::String glyph, double fontSize, double color) override {
52
+ static_assert(
53
+ bridging::getParameterCount(&T::getImageForFont) == 5,
54
+ "Expected getImageForFont(...) to have 5 parameters");
55
+
56
+ return bridging::callFromJs<jsi::Value>(
57
+ rt, &T::getImageForFont, jsInvoker_, instance_, std::move(fontFamilyName), std::move(glyph), std::move(fontSize), std::move(color));
58
+ }
59
+ jsi::String getImageForFontSync(jsi::Runtime &rt, jsi::String fontFamilyName, jsi::String glyph, double fontSize, double color) override {
60
+ static_assert(
61
+ bridging::getParameterCount(&T::getImageForFontSync) == 5,
62
+ "Expected getImageForFontSync(...) to have 5 parameters");
63
+
64
+ return bridging::callFromJs<jsi::String>(
65
+ rt, &T::getImageForFontSync, jsInvoker_, instance_, std::move(fontFamilyName), std::move(glyph), std::move(fontSize), std::move(color));
66
+ }
67
+
68
+ private:
69
+ friend class NativeVectorIconsCxxSpec;
70
+ T *instance_;
71
+ };
72
+
73
+ Delegate delegate_;
74
+ };
75
+
76
+ } // namespace facebook::react
@@ -0,0 +1,17 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeCpp.js
9
+ */
10
+
11
+ #include "ShadowNodes.h"
12
+
13
+ namespace facebook::react {
14
+
15
+
16
+
17
+ } // namespace facebook::react
@@ -0,0 +1,23 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateShadowNodeH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include "EventEmitters.h"
14
+ #include "Props.h"
15
+ #include "States.h"
16
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
17
+ #include <jsi/jsi.h>
18
+
19
+ namespace facebook::react {
20
+
21
+
22
+
23
+ } // namespace facebook::react
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateStateCpp.js
9
+ */
10
+ #include "States.h"
11
+
12
+ namespace facebook::react {
13
+
14
+
15
+
16
+ } // namespace facebook::react
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateStateH.js
8
+ */
9
+ #pragma once
10
+
11
+ #ifdef ANDROID
12
+ #include <folly/dynamic.h>
13
+ #endif
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+
19
+ } // namespace facebook::react
@@ -1,2 +1,2 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
- </manifest>
2
+ </manifest>
@@ -0,0 +1,90 @@
1
+ package com.reactnativevectoricons.common
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactMethod
5
+ import com.facebook.react.bridge.Promise
6
+
7
+ import com.facebook.react.util.RNLog
8
+ import com.facebook.react.views.text.ReactFontManager
9
+
10
+ import android.graphics.*
11
+
12
+ import java.io.File
13
+ import java.io.FileOutputStream
14
+ import java.io.IOException
15
+
16
+ class VectorIconsModule internal constructor(context: ReactApplicationContext) :
17
+ VectorIconsSpec(context) {
18
+
19
+ override fun getName(): String {
20
+ return NAME
21
+ }
22
+
23
+ @ReactMethod
24
+ override fun getImageForFont(fontFamilyName: String, glyph: String, fontSize: Double, color: Double, promise: Promise) {
25
+ try {
26
+ val imagePath = getImageForFontSync(fontFamilyName, glyph, fontSize, color)
27
+ promise.resolve(imagePath)
28
+ } catch (e: Throwable) {
29
+ promise.reject("Failed to get image for font family \"$fontFamilyName\":${e.message}", e)
30
+ }
31
+ }
32
+
33
+ @ReactMethod(isBlockingSynchronousMethod = true)
34
+ override fun getImageForFontSync(fontFamilyName: String, glyph: String, fontSize: Double, color: Double): String {
35
+ val context = reactApplicationContext
36
+ val cacheFolder = context.cacheDir
37
+ val cacheFolderPath = "${cacheFolder.absolutePath}/"
38
+
39
+ val scale = context.resources.displayMetrics.density
40
+ val scaleSuffix = "@${if (scale == scale.toInt().toFloat()) scale.toInt() else scale}x"
41
+ val size = Math.round(fontSize * scale).toInt()
42
+ val cacheKey = "$fontFamilyName:$glyph:$color"
43
+ val hash = cacheKey.hashCode().toString(32)
44
+ val cacheFilePath = "${cacheFolderPath}${hash}_${fontSize}${scaleSuffix}.png"
45
+ val cacheFileUrl = "file://$cacheFilePath"
46
+ val cacheFile = File(cacheFilePath)
47
+
48
+ if (cacheFile.exists()) {
49
+ return cacheFileUrl
50
+ }
51
+
52
+ val typeface = ReactFontManager.getInstance().getTypeface(fontFamilyName, Typeface.NORMAL, context.assets)
53
+ if (typeface == Typeface.DEFAULT) {
54
+ RNLog.w(context, "getImageForFontSync: the lookup for $fontFamilyName returned the default typeface, this likely means that the font is not available on the device.")
55
+ }
56
+ val paint =
57
+ Paint().apply {
58
+ this.typeface = typeface
59
+ this.color = color.toInt()
60
+ textSize = size.toFloat()
61
+ isAntiAlias = true
62
+ }
63
+ val textBounds = Rect()
64
+ paint.getTextBounds(glyph, 0, glyph.length, textBounds)
65
+
66
+ val offsetX = 0
67
+ val offsetY = size - paint.fontMetrics.bottom.toInt()
68
+
69
+ val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888)
70
+ val canvas = Canvas(bitmap)
71
+ canvas.drawText(glyph, offsetX.toFloat(), offsetY.toFloat(), paint)
72
+
73
+ try {
74
+ FileOutputStream(cacheFile).use { fos ->
75
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos)
76
+ fos.flush()
77
+ return cacheFileUrl
78
+ }
79
+ } catch (e: IOException) {
80
+ // we're rethrowing this as a runtime exception because we can't change the method signature
81
+ // to `throws IOException`
82
+ // that would be at odds with the codegen-generated spec
83
+ throw RuntimeException(e)
84
+ }
85
+ }
86
+
87
+ companion object {
88
+ const val NAME = "VectorIcons"
89
+ }
90
+ }
@@ -0,0 +1,35 @@
1
+ package com.reactnativevectoricons.common
2
+
3
+ import com.facebook.react.TurboReactPackage
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.NativeModule
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+ import com.facebook.react.module.model.ReactModuleInfo
8
+ import java.util.HashMap
9
+
10
+ class VectorIconsPackage : TurboReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return if (name == VectorIconsModule.NAME) {
13
+ VectorIconsModule(reactContext)
14
+ } else {
15
+ null
16
+ }
17
+ }
18
+
19
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
+ return ReactModuleInfoProvider {
21
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
+ val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
23
+ moduleInfos[VectorIconsModule.NAME] = ReactModuleInfo(
24
+ VectorIconsModule.NAME, // name
25
+ VectorIconsModule.NAME, // className
26
+ false, // canOverrideExistingModule
27
+ false, // needsEagerInit
28
+ false, // hasConstants NOTE: This is deprecated but we need it to keep compatability with RN <= 0.72
29
+ false, // isCxxModule
30
+ isTurboModule // isTurboModule
31
+ )
32
+ moduleInfos
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,7 @@
1
+ package com.reactnativevectoricons.common
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+
5
+ abstract class VectorIconsSpec internal constructor(context: ReactApplicationContext) :
6
+ NativeVectorIconsSpec(context) {
7
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior.
5
+ *
6
+ * Instead turn on new architecture, make JS spec file changes, re-run codegen (you can trigger that by rebuilding) and copy codegen result here.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJavaSpec.js
9
+ *
10
+ * @nolint
11
+ */
12
+
13
+ package com.reactnativevectoricons.common
14
+
15
+ import com.facebook.proguard.annotations.DoNotStrip
16
+ import com.facebook.react.bridge.Promise
17
+ import com.facebook.react.bridge.ReactApplicationContext
18
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
19
+ import com.facebook.react.bridge.ReactMethod
20
+ import com.facebook.react.turbomodule.core.interfaces.TurboModule
21
+
22
+ abstract class VectorIconsSpec internal constructor(context: ReactApplicationContext) :
23
+ ReactContextBaseJavaModule(context) {
24
+
25
+ companion object {
26
+ const val NAME = "VectorIcons"
27
+ }
28
+
29
+ override fun getName(): String = NAME
30
+
31
+ @ReactMethod
32
+ @DoNotStrip
33
+ abstract fun getImageForFont(fontFamilyName: String, glyph: String, fontSize: Double, color: Double, promise: Promise)
34
+
35
+ @ReactMethod(isBlockingSynchronousMethod = true)
36
+ @DoNotStrip
37
+ abstract fun getImageForFontSync(fontFamilyName: String, glyph: String, fontSize: Double, color: Double): String
38
+ }
package/ios/VectorIcons.h CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  #ifdef RCT_NEW_ARCH_ENABLED
3
- #import "VectorIconsSpec.h"
3
+ #import "RNVectorIconsSpec.h"
4
4
 
5
5
  @interface VectorIcons : NSObject <NativeVectorIconsSpec>
6
6
  #else
@@ -9,20 +9,16 @@
9
9
  @interface VectorIcons : NSObject <RCTBridgeModule>
10
10
  #endif
11
11
 
12
- FOUNDATION_EXPORT NSString *const RNVIErrorDomain;
13
-
14
- enum {
15
- RNVIGenericError = 1000,
16
- };
17
-
18
-
19
- - (NSString *)hexStringFromColor:(UIColor *)color;
20
- - (NSString *)generateFilePath:(NSString *)glyph withFontName:(NSString *)fontName
21
- withFontSize:(CGFloat)fontSize
22
- withColor:(UIColor *)color
23
- withExtraIdentifier:(NSString *)identifier;
24
- - (BOOL)createAndSaveGlyphImage:(NSString *)glyph withFont:(UIFont *)font
25
- withFilePath:(NSString *)filePath
26
- withColor:(UIColor *)color;
27
-
12
+ // - (NSString *)hexStringFromColor:(UIColor *)color;
13
+ // - (NSString *)generateFilePath:(NSString *)glyph withFontName:(NSString
14
+ // *)fontName
15
+ // withFontSize:(CGFloat)fontSize
16
+ // withColor:(UIColor *)color
17
+ // withExtraIdentifier:(NSString
18
+ // *)identifier;
19
+ // - (BOOL)createAndSaveGlyphImage:(NSString *)glyph withFont:(UIFont *)font
20
+ // withFilePath:(NSString
21
+ // *)filePath
22
+ // withColor:(UIColor *)color;
23
+ //
28
24
  @end
@@ -7,6 +7,9 @@
7
7
  #import <React/RCTUtils.h>
8
8
 
9
9
  NSString *const RNVIErrorDomain = @"com.reactnativevectoricons.common";
10
+ enum {
11
+ RNVIGenericError = 1000,
12
+ };
10
13
 
11
14
  @implementation VectorIcons
12
15
  RCT_EXPORT_MODULE()
@@ -72,6 +75,14 @@ RCT_EXPORT_MODULE()
72
75
  withError:(NSError **)error {
73
76
  UIColor *parsedColor = [RCTConvert UIColor:@(color)];
74
77
  UIFont *font = [UIFont fontWithName:fontName size:fontSize];
78
+ if (!font) {
79
+ *error = [NSError errorWithDomain:RNVIErrorDomain
80
+ code:RNVIGenericError
81
+ userInfo:@{
82
+ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"No font found for font name \"%@\". Make sure the font is included in info.plist.", fontName]
83
+ }];
84
+ return nil;
85
+ }
75
86
  NSString *filePath = [self generateFilePath:glyph
76
87
  withFontName:fontName
77
88
  withFontSize:fontSize
@@ -122,69 +133,28 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getImageForFontSync
122
133
  : (CGFloat)fontSize color
123
134
  : (double)color) {
124
135
  NSError *error = nil;
125
- return [self createGlyphImagePathForFont:fontName
136
+ NSString* glyphImage = [self createGlyphImagePathForFont:fontName
126
137
  withGlyph:glyph
127
138
  withFontSize:fontSize
128
139
  withColor:color
129
140
  withError:&error];
130
- }
131
-
132
- RCT_EXPORT_METHOD(loadFontWithFileName
133
- : (NSString *)fontFileName extension
134
- : (NSString *)extension subdirectory
135
- : (NSString *)subdirectory resolve
136
- : (RCTPromiseResolveBlock)resolve reject
137
- : (RCTPromiseRejectBlock)reject) {
138
- NSBundle *bundle = [NSBundle bundleForClass:[self class]];
139
- NSURL *fontURL = [bundle URLForResource:fontFileName
140
- withExtension:extension
141
- subdirectory:subdirectory];
142
- NSData *fontData = [NSData dataWithContentsOfURL:fontURL];
143
-
144
- CGDataProviderRef provider =
145
- CGDataProviderCreateWithCFData((CFDataRef)fontData);
146
- CGFontRef font = CGFontCreateWithDataProvider(provider);
147
-
148
- if (font) {
149
- CFErrorRef errorRef = NULL;
150
- if (CTFontManagerRegisterGraphicsFont(font, &errorRef) == NO) {
151
- NSError *error = (__bridge NSError *)errorRef;
152
- if (error.code == kCTFontManagerErrorAlreadyRegistered ||
153
- error.code == kCTFontManagerErrorDuplicatedName) {
154
- // NSLog(@"Loaded font already %@/%@.%@", subdirectory, fontFileName,
155
- // extension);
156
- resolve(nil);
157
- } else {
158
- NSString *errorMessage = [NSString
159
- stringWithFormat:@"Font '%@' failed to load", fontFileName];
160
- reject(@"font_load_failed", errorMessage, error);
161
- }
162
- } else {
163
- // NSLog(@"Loaded font %@/%@.%@", subdirectory, fontFileName, extension);
164
- resolve(nil);
165
- }
166
-
167
- if (errorRef) {
168
- CFRelease(errorRef);
169
- }
170
-
171
- CFRelease(font);
141
+ if (error == nil && glyphImage != nil) {
142
+ return glyphImage;
172
143
  } else {
173
- // TODO: Should we reject back to javascript?
174
- NSLog(@"RNVI: failed to find font %@/%@.%@", subdirectory, fontFileName,
175
- extension);
176
- }
144
+ NSString *reason = error ? error.localizedDescription : @"Failed to create glyph image";
177
145
 
178
- if (provider) {
179
- CFRelease(provider);
146
+ @throw [NSException exceptionWithName:@"RNVectorIconsException"
147
+ reason:reason
148
+ userInfo:nil];
180
149
  }
181
150
  }
182
151
 
183
152
  // Don't compile this code when we build for the old architecture.
184
153
  #ifdef RCT_NEW_ARCH_ENABLED
185
154
  - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
186
- (const facebook::react::ObjCTurboModule::InitParams &)params {
187
- return std::make_shared<facebook::react::NativeVectorIconsSpecJSI>(params);
155
+ (const facebook::react::ObjCTurboModule::InitParams &)params
156
+ {
157
+ return std::make_shared<facebook::react::NativeVectorIconsSpecJSI>(params);
188
158
  }
189
159
  #endif
190
160
 
@@ -0,0 +1,22 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateComponentDescriptorCpp.js
9
+ */
10
+
11
+ #include "ComponentDescriptors.h"
12
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
13
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
14
+
15
+ namespace facebook::react {
16
+
17
+ void RNVectorIconsSpec_registerComponentDescriptorsFromCodegen(
18
+ std::shared_ptr<const ComponentDescriptorProviderRegistry> registry) {
19
+
20
+ }
21
+
22
+ } // namespace facebook::react
@@ -0,0 +1,24 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateComponentDescriptorH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include "ShadowNodes.h"
14
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
15
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
16
+
17
+ namespace facebook::react {
18
+
19
+
20
+
21
+ void RNVectorIconsSpec_registerComponentDescriptorsFromCodegen(
22
+ std::shared_ptr<const ComponentDescriptorProviderRegistry> registry);
23
+
24
+ } // namespace facebook::react
@@ -0,0 +1,16 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateEventEmitterCpp.js
9
+ */
10
+
11
+ #include "EventEmitters.h"
12
+
13
+
14
+ namespace facebook::react {
15
+
16
+ } // namespace facebook::react
@@ -0,0 +1,17 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateEventEmitterH.js
9
+ */
10
+ #pragma once
11
+
12
+ #include <react/renderer/components/view/ViewEventEmitter.h>
13
+
14
+
15
+ namespace facebook::react {
16
+
17
+ } // namespace facebook::react
@@ -0,0 +1,19 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsCpp.js
9
+ */
10
+
11
+ #include "Props.h"
12
+ #include <react/renderer/core/PropsParserContext.h>
13
+ #include <react/renderer/core/propsConversions.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+
19
+ } // namespace facebook::react
@@ -0,0 +1,18 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GeneratePropsH.js
9
+ */
10
+ #pragma once
11
+
12
+
13
+
14
+ namespace facebook::react {
15
+
16
+
17
+
18
+ } // namespace facebook::react
@@ -0,0 +1,18 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateComponentHObjCpp.js
8
+ */
9
+
10
+ #import <Foundation/Foundation.h>
11
+ #import <React/RCTDefines.h>
12
+ #import <React/RCTLog.h>
13
+
14
+ NS_ASSUME_NONNULL_BEGIN
15
+
16
+
17
+
18
+ NS_ASSUME_NONNULL_END