@react-native-vector-icons/common 0.0.1-alpha.8 → 11.0.0-alpha.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 (169) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +49 -91
  3. package/android/build.gradle +37 -3
  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 +76 -92
  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 +49 -36
  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/ensure-native-module-available.js +1 -1
  54. package/lib/commonjs/ensure-native-module-available.js.map +1 -1
  55. package/lib/commonjs/index.js +57 -1
  56. package/lib/commonjs/index.js.map +1 -1
  57. package/lib/commonjs/scripts/common.js +49 -0
  58. package/lib/commonjs/scripts/common.js.map +1 -0
  59. package/lib/commonjs/scripts/getFonts.js +6 -40
  60. package/lib/commonjs/scripts/getFonts.js.map +1 -1
  61. package/lib/commonjs/scripts/updatePlist.js +54 -0
  62. package/lib/commonjs/scripts/updatePlist.js.map +1 -0
  63. package/lib/module/NativeVectorIcons.js +2 -0
  64. package/lib/module/NativeVectorIcons.js.map +1 -1
  65. package/lib/module/NativeVectorIcons.web.js +2 -0
  66. package/lib/module/NativeVectorIcons.web.js.map +1 -1
  67. package/lib/module/create-icon-set.js +49 -34
  68. package/lib/module/create-icon-set.js.map +1 -1
  69. package/lib/module/create-icon-source-cache.js +2 -0
  70. package/lib/module/create-icon-source-cache.js.map +1 -1
  71. package/lib/module/dynamicLoading/dynamic-font-loading.js +85 -0
  72. package/lib/module/dynamicLoading/dynamic-font-loading.js.map +1 -0
  73. package/lib/module/dynamicLoading/dynamic-font-loading.web.js +16 -0
  74. package/lib/module/dynamicLoading/dynamic-font-loading.web.js.map +1 -0
  75. package/lib/module/dynamicLoading/dynamic-loading-setting.js +41 -0
  76. package/lib/module/dynamicLoading/dynamic-loading-setting.js.map +1 -0
  77. package/lib/module/dynamicLoading/types.js +2 -0
  78. package/lib/module/dynamicLoading/types.js.map +1 -0
  79. package/lib/module/ensure-native-module-available.js +2 -0
  80. package/lib/module/ensure-native-module-available.js.map +1 -1
  81. package/lib/module/index.js +33 -1
  82. package/lib/module/index.js.map +1 -1
  83. package/lib/module/scripts/common.js +43 -0
  84. package/lib/module/scripts/common.js.map +1 -0
  85. package/lib/module/scripts/getFonts.js +8 -39
  86. package/lib/module/scripts/getFonts.js.map +1 -1
  87. package/lib/module/scripts/updatePlist.js +51 -0
  88. package/lib/module/scripts/updatePlist.js.map +1 -0
  89. package/lib/typescript/commonjs/package.json +1 -0
  90. package/lib/typescript/commonjs/src/NativeVectorIcons.d.ts +8 -0
  91. package/lib/typescript/commonjs/src/NativeVectorIcons.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/NativeVectorIcons.web.d.ts.map +1 -0
  93. package/lib/typescript/commonjs/src/create-icon-set.d.ts +36 -0
  94. package/lib/typescript/commonjs/src/create-icon-set.d.ts.map +1 -0
  95. package/lib/typescript/commonjs/src/create-icon-source-cache.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.d.ts +3 -0
  97. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.web.d.ts +6 -0
  99. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.web.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts +41 -0
  101. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/dynamicLoading/types.d.ts +9 -0
  103. package/lib/typescript/commonjs/src/dynamicLoading/types.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/src/ensure-native-module-available.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/src/index.d.ts +6 -0
  106. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/src/scripts/common.d.ts +2 -0
  108. package/lib/typescript/commonjs/src/scripts/common.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/src/scripts/getFonts.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/src/scripts/updatePlist.d.ts +3 -0
  111. package/lib/typescript/commonjs/src/scripts/updatePlist.d.ts.map +1 -0
  112. package/lib/typescript/module/package.json +1 -0
  113. package/lib/typescript/module/src/NativeVectorIcons.d.ts +8 -0
  114. package/lib/typescript/module/src/NativeVectorIcons.d.ts.map +1 -0
  115. package/lib/typescript/module/src/NativeVectorIcons.web.d.ts +3 -0
  116. package/lib/typescript/module/src/NativeVectorIcons.web.d.ts.map +1 -0
  117. package/lib/typescript/module/src/create-icon-set.d.ts +36 -0
  118. package/lib/typescript/module/src/create-icon-set.d.ts.map +1 -0
  119. package/lib/typescript/module/src/create-icon-source-cache.d.ts +21 -0
  120. package/lib/typescript/module/src/create-icon-source-cache.d.ts.map +1 -0
  121. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.d.ts +3 -0
  122. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.d.ts.map +1 -0
  123. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.web.d.ts +6 -0
  124. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.web.d.ts.map +1 -0
  125. package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts +41 -0
  126. package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts.map +1 -0
  127. package/lib/typescript/module/src/dynamicLoading/types.d.ts +9 -0
  128. package/lib/typescript/module/src/dynamicLoading/types.d.ts.map +1 -0
  129. package/lib/typescript/module/src/ensure-native-module-available.d.ts +2 -0
  130. package/lib/typescript/module/src/ensure-native-module-available.d.ts.map +1 -0
  131. package/lib/typescript/module/src/index.d.ts +6 -0
  132. package/lib/typescript/module/src/index.d.ts.map +1 -0
  133. package/lib/typescript/module/src/scripts/common.d.ts +2 -0
  134. package/lib/typescript/module/src/scripts/common.d.ts.map +1 -0
  135. package/lib/typescript/module/src/scripts/getFonts.d.ts +3 -0
  136. package/lib/typescript/module/src/scripts/getFonts.d.ts.map +1 -0
  137. package/lib/typescript/module/src/scripts/updatePlist.d.ts +3 -0
  138. package/lib/typescript/module/src/scripts/updatePlist.d.ts.map +1 -0
  139. package/package.json +72 -44
  140. package/react-native-vector-icons.podspec +67 -42
  141. package/react-native.config.js +12 -0
  142. package/src/NativeVectorIcons.ts +2 -4
  143. package/src/create-icon-set.tsx +79 -32
  144. package/src/dynamicLoading/dynamic-font-loading.ts +97 -0
  145. package/src/dynamicLoading/dynamic-font-loading.web.ts +15 -0
  146. package/src/dynamicLoading/dynamic-loading-setting.ts +77 -0
  147. package/src/dynamicLoading/types.ts +10 -0
  148. package/src/index.ts +48 -1
  149. package/src/scripts/common.ts +52 -0
  150. package/src/scripts/getFonts.ts +6 -47
  151. package/src/scripts/updatePlist.ts +58 -0
  152. package/android/src/main/java/com/reactnativevectoricons/common/VectorIconsModule.java +0 -121
  153. package/android/src/main/java/com/reactnativevectoricons/common/VectorIconsPackage.java +0 -45
  154. package/android/src/newarch/VectorIconsSpec.java +0 -9
  155. package/android/src/oldarch/VectorIconsSpec.java +0 -18
  156. package/lib/typescript/src/NativeVectorIcons.d.ts +0 -9
  157. package/lib/typescript/src/NativeVectorIcons.d.ts.map +0 -1
  158. package/lib/typescript/src/NativeVectorIcons.web.d.ts.map +0 -1
  159. package/lib/typescript/src/create-icon-set.d.ts +0 -26
  160. package/lib/typescript/src/create-icon-set.d.ts.map +0 -1
  161. package/lib/typescript/src/create-icon-source-cache.d.ts.map +0 -1
  162. package/lib/typescript/src/ensure-native-module-available.d.ts.map +0 -1
  163. package/lib/typescript/src/index.d.ts +0 -3
  164. package/lib/typescript/src/index.d.ts.map +0 -1
  165. package/lib/typescript/src/scripts/getFonts.d.ts.map +0 -1
  166. /package/lib/typescript/{src → commonjs/src}/NativeVectorIcons.web.d.ts +0 -0
  167. /package/lib/typescript/{src → commonjs/src}/create-icon-source-cache.d.ts +0 -0
  168. /package/lib/typescript/{src → commonjs/src}/ensure-native-module-available.d.ts +0 -0
  169. /package/lib/typescript/{src → commonjs/src}/scripts/getFonts.d.ts +0 -0
@@ -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
@@ -1,54 +1,58 @@
1
1
  #import "VectorIcons.h"
2
2
 
3
3
  #import <CoreText/CoreText.h>
4
- #import <React/RCTConvert.h>
5
4
  #import <React/RCTBridge.h>
6
- #import <React/RCTUtils.h>
5
+ #import <React/RCTConvert.h>
7
6
  #import <React/RCTFont.h>
8
-
7
+ #import <React/RCTUtils.h>
9
8
 
10
9
  NSString *const RNVIErrorDomain = @"com.reactnativevectoricons.common";
10
+ enum {
11
+ RNVIGenericError = 1000,
12
+ };
11
13
 
12
14
  @implementation VectorIcons
13
15
  RCT_EXPORT_MODULE()
14
16
 
15
- - (NSString *)hexStringFromColor:(UIColor *)color
16
- {
17
+ - (NSString *)hexStringFromColor:(UIColor *)color {
17
18
  const CGFloat *components = CGColorGetComponents(color.CGColor);
18
19
 
19
20
  CGFloat r = components[0];
20
21
  CGFloat g = components[1];
21
22
  CGFloat b = components[2];
22
23
 
23
- return [NSString stringWithFormat:@"#%02lX%02lX%02lX",
24
- lroundf(r * 255),
25
- lroundf(g * 255),
26
- lroundf(b * 255)];
24
+ return [NSString stringWithFormat:@"#%02lX%02lX%02lX", lroundf(r * 255),
25
+ lroundf(g * 255), lroundf(b * 255)];
27
26
  }
28
27
 
29
- - (NSString *)generateFilePath:(NSString *)glyph withFontName:(NSString *)fontName
30
- withFontSize:(CGFloat)fontSize
31
- withColor:(UIColor *)color
32
- withExtraIdentifier:(NSString *)identifier
33
- {
28
+ - (NSString *)generateFilePath:(NSString *)glyph
29
+ withFontName:(NSString *)fontName
30
+ withFontSize:(CGFloat)fontSize
31
+ withColor:(UIColor *)color
32
+ withExtraIdentifier:(NSString *)identifier {
34
33
  CGFloat screenScale = RCTScreenScale();
35
34
  NSString *hexColor = [self hexStringFromColor:color];
36
- NSString *fileName = [NSString stringWithFormat:@"%@RNVectorIcons_%@_%@_%@_%.f%@@%.fx.png",
37
- NSTemporaryDirectory(),
38
- identifier, fontName, glyph,
39
- fontSize, hexColor, screenScale];
35
+ NSString *fileName =
36
+ [NSString stringWithFormat:@"%@RNVectorIcons_%@_%@_%@_%.f%@@%.fx.png",
37
+ NSTemporaryDirectory(), identifier, fontName,
38
+ glyph, fontSize, hexColor, screenScale];
40
39
 
41
40
  return fileName;
42
41
  }
43
42
 
44
- - (BOOL)createAndSaveGlyphImage:(NSString *)glyph withFont:(UIFont *)font
45
- withFilePath:(NSString *)filePath
46
- withColor:(UIColor *)color
47
- {
48
- if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
43
+ - (BOOL)createAndSaveGlyphImage:(NSString *)glyph
44
+ withFont:(UIFont *)font
45
+ withFilePath:(NSString *)filePath
46
+ withColor:(UIColor *)color {
47
+ if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
49
48
  // No cached icon exists, we need to create it and persist to disk
50
49
 
51
- NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:glyph attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: color}];
50
+ NSAttributedString *attributedString =
51
+ [[NSAttributedString alloc] initWithString:glyph
52
+ attributes:@{
53
+ NSFontAttributeName : font,
54
+ NSForegroundColorAttributeName : color
55
+ }];
52
56
 
53
57
  CGSize iconSize = [attributedString size];
54
58
  UIGraphicsBeginImageContextWithOptions(iconSize, NO, 0.0);
@@ -66,103 +70,83 @@ RCT_EXPORT_MODULE()
66
70
 
67
71
  - (NSString *)createGlyphImagePathForFont:(NSString *)fontName
68
72
  withGlyph:(NSString *)glyph
69
- withFontSize:(CGFloat)fontSize
73
+ withFontSize:(CGFloat)fontSize
70
74
  withColor:(double)color
71
- withError:(NSError **)error
72
- {
75
+ withError:(NSError **)error {
73
76
  UIColor *parsedColor = [RCTConvert UIColor:@(color)];
74
77
  UIFont *font = [UIFont fontWithName:fontName size:fontSize];
75
- NSString *filePath = [self generateFilePath:glyph withFontName:fontName
76
- withFontSize:fontSize
77
- withColor:parsedColor
78
- withExtraIdentifier:@""];
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
+ }
86
+ NSString *filePath = [self generateFilePath:glyph
87
+ withFontName:fontName
88
+ withFontSize:fontSize
89
+ withColor:parsedColor
90
+ withExtraIdentifier:@""];
79
91
 
80
- BOOL success = [self createAndSaveGlyphImage:glyph withFont:font
81
- withFilePath:filePath
82
- withColor:parsedColor];
92
+ BOOL success = [self createAndSaveGlyphImage:glyph
93
+ withFont:font
94
+ withFilePath:filePath
95
+ withColor:parsedColor];
83
96
 
84
97
  if (!success) {
85
- *error = [NSError errorWithDomain:RNVIErrorDomain code:RNVIGenericError userInfo:@{NSLocalizedDescriptionKey: @"Failed to write rendered icon image"}];
98
+ *error = [NSError errorWithDomain:RNVIErrorDomain
99
+ code:RNVIGenericError
100
+ userInfo:@{
101
+ NSLocalizedDescriptionKey :
102
+ @"Failed to write rendered icon image"
103
+ }];
86
104
  return nil;
87
105
  }
88
106
  return filePath;
89
107
  }
90
108
 
91
- RCT_EXPORT_METHOD(
92
- getImageForFont:(NSString *)fontName
93
- glyph:(NSString *)glyph
94
- fontSize:(CGFloat)fontSize
95
- color:(double)color
96
- resolve:(RCTPromiseResolveBlock)resolve
97
- reject:(RCTPromiseRejectBlock)reject
98
- ) {
109
+ RCT_EXPORT_METHOD(getImageForFont
110
+ : (NSString *)fontName glyph
111
+ : (NSString *)glyph fontSize
112
+ : (CGFloat)fontSize color
113
+ : (double)color resolve
114
+ : (RCTPromiseResolveBlock)resolve reject
115
+ : (RCTPromiseRejectBlock)reject) {
99
116
  NSError *error = nil;
100
117
  NSString *filePath = [self createGlyphImagePathForFont:fontName
101
118
  withGlyph:glyph
102
- withFontSize:fontSize
119
+ withFontSize:fontSize
103
120
  withColor:color
104
121
  withError:&error];
105
122
  if (error != nil) {
106
- reject([NSString stringWithFormat:@"%ld", (long)error.code], error.localizedDescription, error);
123
+ reject([NSString stringWithFormat:@"%ld", (long)error.code],
124
+ error.localizedDescription, error);
107
125
  } else {
108
126
  resolve(filePath);
109
127
  }
110
128
  }
111
129
 
112
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(
113
- getImageForFontSync:(NSString *)fontName
114
- glyph:(NSString *)glyph
115
- fontSize:(CGFloat)fontSize
116
- color:(double)color
117
- ) {
130
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getImageForFontSync
131
+ : (NSString *)fontName glyph
132
+ : (NSString *)glyph fontSize
133
+ : (CGFloat)fontSize color
134
+ : (double)color) {
118
135
  NSError *error = nil;
119
- return [self createGlyphImagePathForFont:fontName
136
+ NSString* glyphImage = [self createGlyphImagePathForFont:fontName
120
137
  withGlyph:glyph
121
- withFontSize:fontSize
138
+ withFontSize:fontSize
122
139
  withColor:color
123
140
  withError:&error];
124
- }
125
-
126
- RCT_EXPORT_METHOD(
127
- loadFontWithFileName:(NSString *)fontFileName
128
- extension:(NSString *)extension
129
- subdirectory:(NSString *)subdirectory
130
- resolve:(RCTPromiseResolveBlock)resolve
131
- reject:(RCTPromiseRejectBlock)reject
132
- ) {
133
- NSBundle *bundle = [NSBundle bundleForClass:[self class]];
134
- NSURL *fontURL = [bundle URLForResource:fontFileName withExtension:extension subdirectory:subdirectory];
135
- NSData *fontData = [NSData dataWithContentsOfURL:fontURL];
136
-
137
- CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)fontData);
138
- CGFontRef font = CGFontCreateWithDataProvider(provider);
139
-
140
- if (font) {
141
- CFErrorRef errorRef = NULL;
142
- if (CTFontManagerRegisterGraphicsFont(font, &errorRef) == NO) {
143
- NSError *error = (__bridge NSError *)errorRef;
144
- if (error.code == kCTFontManagerErrorAlreadyRegistered || error.code == kCTFontManagerErrorDuplicatedName) {
145
- // NSLog(@"Loaded font already %@/%@.%@", subdirectory, fontFileName, extension);
146
- resolve(nil);
147
- } else {
148
- NSString *errorMessage = [NSString stringWithFormat:@"Font '%@' failed to load", fontFileName];
149
- reject(@"font_load_failed", errorMessage, error);
150
- }
151
- } else {
152
- // NSLog(@"Loaded font %@/%@.%@", subdirectory, fontFileName, extension);
153
- resolve(nil);
154
- }
155
-
156
- CFRelease(font);
141
+ if (error == nil && glyphImage != nil) {
142
+ return glyphImage;
157
143
  } else {
158
- // TODO: Should we reject back to javascript?
159
- NSLog(@"RNVI: failed to find font %@/%@.%@", subdirectory, fontFileName, extension);
160
- }
144
+ NSString *reason = error ? error.localizedDescription : @"Failed to create glyph image";
161
145
 
162
- if (provider) {
163
- CFRelease(provider);
146
+ @throw [NSException exceptionWithName:@"RNVectorIconsException"
147
+ reason:reason
148
+ userInfo:nil];
164
149
  }
165
-
166
150
  }
167
151
 
168
152
  // Don't compile this code when we build for the old architecture.
@@ -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