@react-native-vector-icons/common 0.0.1-alpha.8 → 11.0.0-alpha.1

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 (175) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +49 -91
  3. package/android/build.gradle +37 -3
  4. package/android/generated/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeVectorIconsSpec.java +42 -0
  5. package/android/generated/android/app/build/generated/source/codegen/jni/CMakeLists.txt +49 -0
  6. package/android/generated/android/app/build/generated/source/codegen/jni/RNVectorIconsSpec-generated.cpp +38 -0
  7. package/android/generated/android/app/build/generated/source/codegen/jni/RNVectorIconsSpec.h +31 -0
  8. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.cpp +22 -0
  9. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.h +24 -0
  10. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/EventEmitters.cpp +16 -0
  11. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/EventEmitters.h +17 -0
  12. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/Props.cpp +19 -0
  13. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/Props.h +18 -0
  14. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/RNVectorIconsSpecJSI-generated.cpp +40 -0
  15. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/RNVectorIconsSpecJSI.h +76 -0
  16. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/ShadowNodes.cpp +17 -0
  17. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/ShadowNodes.h +23 -0
  18. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/States.cpp +16 -0
  19. package/android/generated/android/app/build/generated/source/codegen/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/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec-generated.mm +1881 -0
  28. package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec.h +2321 -0
  29. package/ios/generated/build/generated/ios/FBReactNativeSpecJSI-generated.cpp +2785 -0
  30. package/ios/generated/build/generated/ios/FBReactNativeSpecJSI.h +7511 -0
  31. package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.h +18 -0
  32. package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.mm +33 -0
  33. package/ios/generated/build/generated/ios/RNVectorIconsSpec/RNVectorIconsSpec-generated.mm +36 -0
  34. package/ios/generated/build/generated/ios/RNVectorIconsSpec/RNVectorIconsSpec.h +58 -0
  35. package/ios/generated/build/generated/ios/RNVectorIconsSpecJSI-generated.cpp +40 -0
  36. package/ios/generated/build/generated/ios/RNVectorIconsSpecJSI.h +76 -0
  37. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.cpp +22 -0
  38. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.h +24 -0
  39. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/EventEmitters.cpp +16 -0
  40. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/EventEmitters.h +17 -0
  41. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/Props.cpp +19 -0
  42. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/Props.h +18 -0
  43. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/RCTComponentViewHelpers.h +18 -0
  44. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/ShadowNodes.cpp +17 -0
  45. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/ShadowNodes.h +23 -0
  46. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/States.cpp +16 -0
  47. package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/States.h +19 -0
  48. package/lib/commonjs/NativeVectorIcons.js.map +1 -1
  49. package/lib/commonjs/create-icon-set.js +49 -36
  50. package/lib/commonjs/create-icon-set.js.map +1 -1
  51. package/lib/commonjs/dynamicLoading/dynamic-font-loading.js +92 -0
  52. package/lib/commonjs/dynamicLoading/dynamic-font-loading.js.map +1 -0
  53. package/lib/commonjs/dynamicLoading/dynamic-font-loading.web.js +20 -0
  54. package/lib/commonjs/dynamicLoading/dynamic-font-loading.web.js.map +1 -0
  55. package/lib/commonjs/dynamicLoading/dynamic-loading-setting.js +50 -0
  56. package/lib/commonjs/dynamicLoading/dynamic-loading-setting.js.map +1 -0
  57. package/lib/commonjs/dynamicLoading/types.js +2 -0
  58. package/lib/commonjs/dynamicLoading/types.js.map +1 -0
  59. package/lib/commonjs/ensure-native-module-available.js +1 -1
  60. package/lib/commonjs/ensure-native-module-available.js.map +1 -1
  61. package/lib/commonjs/index.js +57 -1
  62. package/lib/commonjs/index.js.map +1 -1
  63. package/lib/commonjs/scripts/common.js +49 -0
  64. package/lib/commonjs/scripts/common.js.map +1 -0
  65. package/lib/commonjs/scripts/getFonts.js +6 -40
  66. package/lib/commonjs/scripts/getFonts.js.map +1 -1
  67. package/lib/commonjs/scripts/updatePlist.js +54 -0
  68. package/lib/commonjs/scripts/updatePlist.js.map +1 -0
  69. package/lib/module/NativeVectorIcons.js +2 -0
  70. package/lib/module/NativeVectorIcons.js.map +1 -1
  71. package/lib/module/NativeVectorIcons.web.js +2 -0
  72. package/lib/module/NativeVectorIcons.web.js.map +1 -1
  73. package/lib/module/create-icon-set.js +49 -34
  74. package/lib/module/create-icon-set.js.map +1 -1
  75. package/lib/module/create-icon-source-cache.js +2 -0
  76. package/lib/module/create-icon-source-cache.js.map +1 -1
  77. package/lib/module/dynamicLoading/dynamic-font-loading.js +85 -0
  78. package/lib/module/dynamicLoading/dynamic-font-loading.js.map +1 -0
  79. package/lib/module/dynamicLoading/dynamic-font-loading.web.js +16 -0
  80. package/lib/module/dynamicLoading/dynamic-font-loading.web.js.map +1 -0
  81. package/lib/module/dynamicLoading/dynamic-loading-setting.js +41 -0
  82. package/lib/module/dynamicLoading/dynamic-loading-setting.js.map +1 -0
  83. package/lib/module/dynamicLoading/types.js +2 -0
  84. package/lib/module/dynamicLoading/types.js.map +1 -0
  85. package/lib/module/ensure-native-module-available.js +2 -0
  86. package/lib/module/ensure-native-module-available.js.map +1 -1
  87. package/lib/module/index.js +33 -1
  88. package/lib/module/index.js.map +1 -1
  89. package/lib/module/scripts/common.js +43 -0
  90. package/lib/module/scripts/common.js.map +1 -0
  91. package/lib/module/scripts/getFonts.js +8 -39
  92. package/lib/module/scripts/getFonts.js.map +1 -1
  93. package/lib/module/scripts/updatePlist.js +51 -0
  94. package/lib/module/scripts/updatePlist.js.map +1 -0
  95. package/lib/typescript/commonjs/package.json +1 -0
  96. package/lib/typescript/commonjs/src/NativeVectorIcons.d.ts +8 -0
  97. package/lib/typescript/commonjs/src/NativeVectorIcons.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/NativeVectorIcons.web.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/src/create-icon-set.d.ts +36 -0
  100. package/lib/typescript/commonjs/src/create-icon-set.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/src/create-icon-source-cache.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.d.ts +3 -0
  103. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.web.d.ts +6 -0
  105. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.web.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts +41 -0
  107. package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts.map +1 -0
  108. package/lib/typescript/commonjs/src/dynamicLoading/types.d.ts +9 -0
  109. package/lib/typescript/commonjs/src/dynamicLoading/types.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/src/ensure-native-module-available.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/src/index.d.ts +6 -0
  112. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/src/scripts/common.d.ts +2 -0
  114. package/lib/typescript/commonjs/src/scripts/common.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/src/scripts/getFonts.d.ts.map +1 -0
  116. package/lib/typescript/commonjs/src/scripts/updatePlist.d.ts +3 -0
  117. package/lib/typescript/commonjs/src/scripts/updatePlist.d.ts.map +1 -0
  118. package/lib/typescript/module/package.json +1 -0
  119. package/lib/typescript/module/src/NativeVectorIcons.d.ts +8 -0
  120. package/lib/typescript/module/src/NativeVectorIcons.d.ts.map +1 -0
  121. package/lib/typescript/module/src/NativeVectorIcons.web.d.ts +3 -0
  122. package/lib/typescript/module/src/NativeVectorIcons.web.d.ts.map +1 -0
  123. package/lib/typescript/module/src/create-icon-set.d.ts +36 -0
  124. package/lib/typescript/module/src/create-icon-set.d.ts.map +1 -0
  125. package/lib/typescript/module/src/create-icon-source-cache.d.ts +21 -0
  126. package/lib/typescript/module/src/create-icon-source-cache.d.ts.map +1 -0
  127. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.d.ts +3 -0
  128. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.d.ts.map +1 -0
  129. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.web.d.ts +6 -0
  130. package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.web.d.ts.map +1 -0
  131. package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts +41 -0
  132. package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts.map +1 -0
  133. package/lib/typescript/module/src/dynamicLoading/types.d.ts +9 -0
  134. package/lib/typescript/module/src/dynamicLoading/types.d.ts.map +1 -0
  135. package/lib/typescript/module/src/ensure-native-module-available.d.ts +2 -0
  136. package/lib/typescript/module/src/ensure-native-module-available.d.ts.map +1 -0
  137. package/lib/typescript/module/src/index.d.ts +6 -0
  138. package/lib/typescript/module/src/index.d.ts.map +1 -0
  139. package/lib/typescript/module/src/scripts/common.d.ts +2 -0
  140. package/lib/typescript/module/src/scripts/common.d.ts.map +1 -0
  141. package/lib/typescript/module/src/scripts/getFonts.d.ts +3 -0
  142. package/lib/typescript/module/src/scripts/getFonts.d.ts.map +1 -0
  143. package/lib/typescript/module/src/scripts/updatePlist.d.ts +3 -0
  144. package/lib/typescript/module/src/scripts/updatePlist.d.ts.map +1 -0
  145. package/package.json +72 -44
  146. package/react-native-vector-icons.podspec +67 -42
  147. package/react-native.config.js +13 -0
  148. package/src/NativeVectorIcons.ts +2 -4
  149. package/src/create-icon-set.tsx +79 -32
  150. package/src/dynamicLoading/dynamic-font-loading.ts +97 -0
  151. package/src/dynamicLoading/dynamic-font-loading.web.ts +15 -0
  152. package/src/dynamicLoading/dynamic-loading-setting.ts +77 -0
  153. package/src/dynamicLoading/types.ts +10 -0
  154. package/src/index.ts +48 -1
  155. package/src/scripts/common.ts +52 -0
  156. package/src/scripts/getFonts.ts +6 -47
  157. package/src/scripts/updatePlist.ts +58 -0
  158. package/android/src/main/java/com/reactnativevectoricons/common/VectorIconsModule.java +0 -121
  159. package/android/src/main/java/com/reactnativevectoricons/common/VectorIconsPackage.java +0 -45
  160. package/android/src/newarch/VectorIconsSpec.java +0 -9
  161. package/android/src/oldarch/VectorIconsSpec.java +0 -18
  162. package/lib/typescript/src/NativeVectorIcons.d.ts +0 -9
  163. package/lib/typescript/src/NativeVectorIcons.d.ts.map +0 -1
  164. package/lib/typescript/src/NativeVectorIcons.web.d.ts.map +0 -1
  165. package/lib/typescript/src/create-icon-set.d.ts +0 -26
  166. package/lib/typescript/src/create-icon-set.d.ts.map +0 -1
  167. package/lib/typescript/src/create-icon-source-cache.d.ts.map +0 -1
  168. package/lib/typescript/src/ensure-native-module-available.d.ts.map +0 -1
  169. package/lib/typescript/src/index.d.ts +0 -3
  170. package/lib/typescript/src/index.d.ts.map +0 -1
  171. package/lib/typescript/src/scripts/getFonts.d.ts.map +0 -1
  172. /package/lib/typescript/{src → commonjs/src}/NativeVectorIcons.web.d.ts +0 -0
  173. /package/lib/typescript/{src → commonjs/src}/create-icon-source-cache.d.ts +0 -0
  174. /package/lib/typescript/{src → commonjs/src}/ensure-native-module-available.d.ts +0 -0
  175. /package/lib/typescript/{src → commonjs/src}/scripts/getFonts.d.ts +0 -0
@@ -11,66 +11,91 @@ Pod::Spec.new do |s|
11
11
  s.license = package["license"]
12
12
  s.authors = package["author"]
13
13
 
14
- s.platforms = { :ios => "12.0", :tvos => "9.0" }
15
- s.source = { :git => "https://github.com/react-native-vector-icons/react-native-vector-icons.git", :tag => "#{s.version}" }
14
+ s.platforms = { :ios => min_ios_version_supported, :tvos => "9.0", :visionos => "1.0" }
15
+ s.source = { :git => package["repository"]["url"], :tag => "v#{s.version}" }
16
16
 
17
- s.source_files = "ios/**/*.{h,m,mm}"
17
+ s.source_files = "ios/**/*.{h,m,mm,cpp}"
18
+
19
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
20
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
21
+ if respond_to?(:install_modules_dependencies, true)
22
+ install_modules_dependencies(s)
23
+ else
24
+ s.dependency "React-Core"
25
+
26
+ # Don't install the dependencies when we run `pod install` in the old architecture.
27
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
28
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
29
+ s.pod_target_xcconfig = {
30
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
31
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
32
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
33
+ }
34
+ s.dependency "React-Codegen"
35
+ s.dependency "RCT-Folly"
36
+ s.dependency "RCTRequired"
37
+ s.dependency "RCTTypeSafety"
38
+ s.dependency "ReactCommon/turbomodule/core"
39
+ end
40
+ end
18
41
 
19
42
  s.script_phase = {
20
43
  :name => 'Copy Fonts',
21
44
  :script => "
22
45
  set -e
23
46
 
24
- # NOTE: This whole script is a bit of a hack
47
+ # This script borrows from the standard resource copy script https://gist.github.com/vonovak/d8f1a37804438f05bae22be1e8cd53c1
25
48
  # We need two key bits of information
26
- # Project Root - Always above the pods dir
49
+ # Project Root - Where the package.json for the RN app lives
27
50
  # Xcode Build Dir to copy the fonts into - We look for the directory that ends in .app
28
51
 
29
- echo START:RNVI_COPY_FONTS
52
+ echo \"(RNVI) START_COPY_FONTS\"
53
+
54
+ echo \"(RNVI) PWD: $(pwd)\"
30
55
 
31
- echo PWD: $(pwd)
32
- echo PODS_ROOT: \"$PODS_ROOT\"
33
- echo PODS_CONFIGURATION_BUILD_DIR: \"$PODS_CONFIGURATION_BUILD_DIR\"
56
+ #############
57
+ # Find the fonts we need to copy
58
+ #############
34
59
 
60
+ # Assume the project root is always two directories above the POD_ROOT
61
+ echo \"(RNVI) PODS_ROOT: $PODS_ROOT\"
35
62
  PROJECT_ROOT=\"${PODS_ROOT}/../..\"
36
- echo \"PROJECT_ROOT: $PROJECT_ROOT\"
63
+ echo \"(RNVI) PROJECT_ROOT: $PROJECT_ROOT\"
64
+
65
+ # Items we need to copy for rsync
66
+ RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt
67
+
68
+ node \"${PODS_TARGET_SRCROOT}/lib/commonjs/scripts/getFonts.js\" \"$PROJECT_ROOT\"/package.json > \"$RESOURCES_TO_COPY\"
37
69
 
70
+ #############
71
+ # Find the destination we copy to
72
+ #############
73
+
74
+ echo \"(RNVI) PODS_CONFIGURATION_BUILD_DIR: $PODS_CONFIGURATION_BUILD_DIR\"
38
75
  XCODE_DIR=$(ls -d \"$PODS_CONFIGURATION_BUILD_DIR\"/*.app)
39
- DEST_DIR=\"${XCODE_DIR}/react-native-vector-icons\"
40
- echo XCODE_DIR: \"$XCODE_DIR\"
41
- echo DEST_DIR: \"$DEST_DIR\"
76
+ echo \"(RNVI) XCODE_DIR: $XCODE_DIR\"
77
+ DEST_DIR=\"${XCODE_DIR}\"
78
+ echo \"(RNVI) DEST_DIR: $DEST_DIR\"
79
+ echo I $INSTALL_DIR
42
80
  mkdir -p \"$DEST_DIR\"
43
81
 
44
- FONT_LIST=$(node \"#{__dir__}/lib/commonjs/scripts/getFonts.js\" \"$PROJECT_ROOT\")
45
- for font in $FONT_LIST; do
46
- echo Copying font $font
47
- cp $font \"$DEST_DIR\"
48
- done
82
+ #############
83
+ # Copy the fonts
84
+ #############
85
+ echo \"(RNVI) Copying the following files to $DEST_DIR\"
86
+ cat \"$RESOURCES_TO_COPY\" | sed 's/^/(RNVI) /'
87
+
88
+ # NOTE: Should we add --delete and remove old fonts automagically? NOt doing it yet as it feels risky
89
+ rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from=\"$RESOURCES_TO_COPY\" / \"$DEST_DIR\"
90
+ # TODO: How do we test this is right?
91
+ if [[ \"${ACTION}\" == \"install\" ]] && [[ \"${SKIP_INSTALL}\" == \"NO\" ]]; then
92
+ mkdir -p \"${INSTALL_DIR}/react-native-vector-icons\"
93
+ rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from=\"$RESOURCES_TO_COPY\" / \"${INSTALL_DIR}/react-native-vector-icons\"
94
+ fi
95
+
96
+ rm -f \"$RESOURCES_TO_COPY\"
49
97
 
50
- echo END:RNVI_COPY_FONTS
98
+ echo \"(RNVI) END:RNVI_COPY_FONTS\"
51
99
  ",
52
100
  }
53
-
54
- # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
55
- # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
56
- if respond_to?(:install_modules_dependencies, true)
57
- install_modules_dependencies(s)
58
- else
59
- s.dependency "React-Core"
60
-
61
- # Don't install the dependencies when we run `pod install` in the old architecture.
62
- if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
63
- s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
64
- s.pod_target_xcconfig = {
65
- "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
66
- "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
67
- "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
68
- }
69
- s.dependency "React-Codegen"
70
- s.dependency "RCT-Folly"
71
- s.dependency "RCTRequired"
72
- s.dependency "RCTTypeSafety"
73
- s.dependency "ReactCommon/turbomodule/core"
74
- end
75
- end
76
101
  end
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @type {import('@react-native-community/cli-types').UserDependencyConfig}
3
+ */
4
+ module.exports = {
5
+ dependency: {
6
+ platforms: {
7
+ android: {
8
+ // NOTE: We aren't shipping generated files as this eesm to break react 0.73 due to missing include paths for react-native
9
+ cmakeListsPath: 'build/generated/source/codegen/jni/CMakeLists.txt',
10
+ },
11
+ },
12
+ },
13
+ };
@@ -2,11 +2,9 @@ import type { TurboModule } from 'react-native';
2
2
  import { TurboModuleRegistry } from 'react-native';
3
3
 
4
4
  export interface Spec extends TurboModule {
5
- getImageForFont(fontName: string, glyph: string, fontSize: number, color: number): Promise<string>;
5
+ getImageForFont(fontFamilyName: string, glyph: string, fontSize: number, color: number): Promise<string>;
6
6
 
7
- getImageForFontSync(fontName: string, glyph: string, fontSize: number, color: number): string;
8
-
9
- loadFontWithFileName(fontFileName: string, extension: string, subdirectory?: string): Promise<void>;
7
+ getImageForFontSync(fontFamilyName: string, glyph: string, fontSize: number, color: number): string;
10
8
  }
11
9
 
12
10
  export default TurboModuleRegistry.getEnforcing<Spec>('VectorIcons');
@@ -1,14 +1,25 @@
1
- import React, { forwardRef, type Ref } from 'react';
1
+ import React, { forwardRef, type Ref, useEffect } from 'react';
2
2
 
3
3
  import { PixelRatio, Platform, Text, type TextProps, type TextStyle, processColor } from 'react-native';
4
4
 
5
5
  import NativeIconAPI from './NativeVectorIcons';
6
6
  import createIconSourceCache from './create-icon-source-cache';
7
+ import { dynamicLoader } from './dynamicLoading/dynamic-font-loading';
8
+ import { isDynamicLoadingEnabled } from './dynamicLoading/dynamic-loading-setting';
9
+ import type { FontSource } from './dynamicLoading/types';
7
10
  import ensureNativeModuleAvailable from './ensure-native-module-available';
8
11
 
9
12
  export const DEFAULT_ICON_SIZE = 12;
10
13
  export const DEFAULT_ICON_COLOR = 'black';
11
14
 
15
+ type ValueData = { uri: string; scale: number };
16
+ type GetImageSourceSyncIconFunc<GM> = (name: GM, size?: number, color?: TextStyle['color']) => ValueData | undefined;
17
+ type GetImageSourceIconFunc<GM> = (
18
+ name: GM,
19
+ size?: number,
20
+ color?: TextStyle['color'],
21
+ ) => Promise<ValueData | undefined>;
22
+
12
23
  export type IconProps<T> = TextProps & {
13
24
  name: T;
14
25
  size?: number;
@@ -16,20 +27,53 @@ export type IconProps<T> = TextProps & {
16
27
  innerRef?: Ref<Text>;
17
28
  };
18
29
 
19
- export const createIconSet = <GM extends Record<string, number>>(
30
+ type IconComponent<GM extends Record<string, number>> = React.FC<
31
+ TextProps & {
32
+ name: keyof GM;
33
+ size?: number;
34
+ color?: TextStyle['color'];
35
+ innerRef?: Ref<Text>;
36
+ } & React.RefAttributes<Text>
37
+ > & {
38
+ getImageSource: GetImageSourceIconFunc<keyof GM>;
39
+ getImageSourceSync: GetImageSourceSyncIconFunc<keyof GM>;
40
+ };
41
+
42
+ export type CreateIconSetOptions = {
43
+ postScriptName: string;
44
+ fontFileName: string;
45
+ fontSource?: FontSource;
46
+ fontStyle?: TextProps['style'];
47
+ };
48
+
49
+ export function createIconSet<GM extends Record<string, number>>(
20
50
  glyphMap: GM,
21
- fontFamily: string,
22
- fontFile: string,
51
+ postScriptName: string,
52
+ fontFileName: string,
23
53
  fontStyle?: TextProps['style'],
24
- ) => {
25
- // Android doesn't care about actual fontFamily name, it will only look in fonts folder.
26
- const fontBasename = fontFile ? fontFile.replace(/\.(otf|ttf)$/, '') : fontFamily;
54
+ ): IconComponent<GM>;
55
+ export function createIconSet<GM extends Record<string, number>>(
56
+ glyphMap: GM,
57
+ options: CreateIconSetOptions,
58
+ ): IconComponent<GM>;
59
+ export function createIconSet<GM extends Record<string, number>>(
60
+ glyphMap: GM,
61
+ postScriptNameOrOptions: string | CreateIconSetOptions,
62
+ fontFileNameParam?: string,
63
+ fontStyleParam?: TextProps['style'],
64
+ ): IconComponent<GM> {
65
+ const { postScriptName, fontFileName, fontStyle } =
66
+ typeof postScriptNameOrOptions === 'string'
67
+ ? { postScriptName: postScriptNameOrOptions, fontFileName: fontFileNameParam, fontStyle: fontStyleParam }
68
+ : postScriptNameOrOptions;
69
+
70
+ const fontBasename = fontFileName ? fontFileName.replace(/\.(otf|ttf)$/, '') : postScriptName;
27
71
 
28
72
  const fontReference = Platform.select({
29
- windows: `/Assets/${fontFile}#${fontFamily}`,
73
+ windows: `/Assets/${fontFileName}#${postScriptName}`,
30
74
  android: fontBasename,
31
75
  web: fontBasename,
32
- default: fontFamily,
76
+ default: postScriptName,
33
77
  });
34
78
 
35
79
  const resolveGlyph = (name: keyof GM) => {
@@ -45,14 +89,37 @@ export const createIconSet = <GM extends Record<string, number>>(
45
89
  const Icon = ({
46
90
  name,
47
91
  size = DEFAULT_ICON_SIZE,
48
- color,
92
+ color = DEFAULT_ICON_COLOR,
49
93
  style,
50
94
  children,
51
95
  allowFontScaling = false,
52
96
  innerRef,
53
97
  ...props
54
98
  }: IconProps<keyof GM>) => {
55
- const glyph = name ? resolveGlyph(name as string) : '';
99
+ const [isFontLoaded, setIsFontLoaded] = React.useState(
100
+ isDynamicLoadingEnabled() ? dynamicLoader.isLoaded(fontReference) : true,
101
+ );
102
+ const glyph = isFontLoaded && name ? resolveGlyph(name) : '';
103
+
104
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the dependencies never change
105
+ useEffect(() => {
106
+ let isMounted = true;
107
+
108
+ if (
109
+ !isFontLoaded &&
110
+ typeof postScriptNameOrOptions === 'object' &&
111
+ typeof postScriptNameOrOptions.fontSource !== 'undefined'
112
+ ) {
113
+ dynamicLoader.loadFontAsync(fontReference, postScriptNameOrOptions.fontSource).finally(() => {
114
+ if (isMounted) {
115
+ setIsFontLoaded(true);
116
+ }
117
+ });
118
+ }
119
+ return () => {
120
+ isMounted = false;
121
+ };
122
+ }, []);
56
123
 
57
124
  const styleDefaults = {
58
125
  fontSize: size,
@@ -150,30 +217,10 @@ export const createIconSet = <GM extends Record<string, number>>(
150
217
  }
151
218
  };
152
219
 
153
- const loadFont = async () => {
154
- if (Platform.OS !== 'ios') {
155
- return;
156
- }
157
- ensureNativeModuleAvailable();
158
-
159
- const [filename, extension] = fontFile.split('.'); // FIXME: what if filename has two dots?
160
- if (!filename) {
161
- // NOTE: Thie is impossible but TypeScript doesn't know that
162
- throw new Error('Font needs a filename.');
163
- }
164
- if (!extension) {
165
- throw new Error('Font needs a filename extensison.');
166
- }
167
-
168
- await NativeIconAPI.loadFontWithFileName(filename, extension, 'react-native-vector-icons');
169
- };
170
-
171
- loadFont();
172
-
173
220
  const IconNamespace = Object.assign(WrappedIcon, {
174
221
  getImageSource,
175
222
  getImageSourceSync,
176
223
  });
177
224
 
178
225
  return IconNamespace;
179
- };
226
+ }
@@ -0,0 +1,97 @@
1
+ /*
2
+ * The following imports are always present when react native is installed
3
+ * in the future, more explicit apis will be exposed by the core, including typings
4
+ * */
5
+ // @ts-expect-error missing types
6
+ // eslint-disable-next-line import/no-extraneous-dependencies
7
+ import { getAssetByID } from '@react-native/assets-registry/registry';
8
+ import type { Image } from 'react-native';
9
+ // @ts-expect-error missing types
10
+ import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
11
+ import { getErrorCallback } from './dynamic-loading-setting';
12
+ import type { DynamicLoader, FontSource } from './types';
13
+
14
+ const loadPromises: { [fontSource: string]: Promise<void> } = {};
15
+
16
+ const loadFontAsync = async (fontFamily: string, fontSource: FontSource): Promise<void> => {
17
+ const expoModules = globalThis?.expo?.modules;
18
+ if (!expoModules) {
19
+ throw new Error('Expo is not available. Dynamic font loading is not available.');
20
+ }
21
+
22
+ if (loadPromises[fontFamily]) {
23
+ return loadPromises[fontFamily];
24
+ }
25
+
26
+ loadPromises[fontFamily] = (async function LoadFont() {
27
+ try {
28
+ const localUri = await (() => {
29
+ if (typeof fontSource === 'string') {
30
+ // a local filesystem uri
31
+ return fontSource;
32
+ }
33
+ // a module id
34
+ const { uri, type, hash } = getLocalFontUrl(fontSource, fontFamily);
35
+ return expoModules.ExpoAsset.downloadAsync(uri, hash, type);
36
+ })();
37
+
38
+ await expoModules.ExpoFontLoader.loadAsync(fontFamily, localUri);
39
+ } catch (error) {
40
+ console.error(`Failed to load font ${fontFamily}`, error); // eslint-disable-line no-console
41
+
42
+ getErrorCallback()?.({
43
+ error: error as Error,
44
+ fontFamily,
45
+ fontSource,
46
+ });
47
+ } finally {
48
+ delete loadPromises[fontFamily];
49
+ }
50
+ })();
51
+
52
+ return loadPromises[fontFamily];
53
+ };
54
+
55
+ type AssetRegistryEntry = {
56
+ name: string;
57
+ httpServerLocation: string;
58
+ hash: string;
59
+ type: string; // file extension
60
+ };
61
+
62
+ const getLocalFontUrl = (fontModuleId: number, fontFamily: string) => {
63
+ const assetMeta: AssetRegistryEntry = getAssetByID(fontModuleId);
64
+ if (!assetMeta) {
65
+ throw new Error(`no asset found for font family "${fontFamily}", moduleId: ${String(fontModuleId)}`);
66
+ }
67
+
68
+ const resolver: typeof Image.resolveAssetSource = resolveAssetSource;
69
+ const assetSource = resolver(fontModuleId);
70
+
71
+ return { ...assetMeta, ...assetSource };
72
+ };
73
+
74
+ const loadedFontsCache: { [name: string]: boolean } = {};
75
+
76
+ const isLoadedNative = (fontFamily: string) => {
77
+ if (fontFamily in loadedFontsCache) {
78
+ return true;
79
+ }
80
+
81
+ const { expo } = globalThis;
82
+ if (!expo) {
83
+ throw new Error('Expo is not available. Dynamic font loading is not available.');
84
+ }
85
+
86
+ const loadedNativeFonts = expo.modules.ExpoFontLoader.getLoadedFonts();
87
+ loadedNativeFonts.forEach((font) => {
88
+ loadedFontsCache[font] = true;
89
+ });
90
+
91
+ return fontFamily in loadedFontsCache;
92
+ };
93
+
94
+ export const dynamicLoader: DynamicLoader = {
95
+ isLoaded: isLoadedNative,
96
+ loadFontAsync,
97
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * dynamic font loading isn't supported on web
3
+ * */
4
+ import type { DynamicLoader, FontSource } from './types';
5
+
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
+ const loadFontAsync = async (_fontFamily: string, _fontSource: FontSource): Promise<void> => undefined;
8
+
9
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
+ const isLoaded = (_fontFamily: string) => true;
11
+
12
+ export const dynamicLoader: DynamicLoader = {
13
+ isLoaded,
14
+ loadFontAsync,
15
+ };
@@ -0,0 +1,77 @@
1
+ import type { FontSource } from './types';
2
+
3
+ declare global {
4
+ interface ExpoGlobal {
5
+ modules: {
6
+ ExpoAsset: {
7
+ // definition from
8
+ // https://github.com/expo/expo/blob/1f5a5991d14aad09282d1ce1612b44d30e7e7d3d/packages/expo-asset/ios/AssetModule.swift#L23
9
+ downloadAsync: (uri: string, hash: string | undefined, type: string) => Promise<string>;
10
+ };
11
+ ExpoFontLoader: {
12
+ // definition from
13
+ // https://github.com/expo/expo/blob/1f5a5991d14aad09282d1ce1612b44d30e7e7d3d/packages/expo-font/ios/FontLoaderModule.swift#L18
14
+ getLoadedFonts: () => string[];
15
+ loadAsync: (fontFamilyAlias: string, fileUri: string) => Promise<void>;
16
+ };
17
+ };
18
+ }
19
+
20
+ // eslint-disable-next-line vars-on-top
21
+ var expo: ExpoGlobal | undefined;
22
+ }
23
+
24
+ const hasNecessaryExpoModules = !!globalThis.expo?.modules?.ExpoAsset && !!globalThis.expo?.modules?.ExpoFontLoader;
25
+
26
+ const hasNecessaryExpoFeatures =
27
+ hasNecessaryExpoModules && typeof globalThis.expo?.modules.ExpoFontLoader.getLoadedFonts === 'function';
28
+
29
+ let dynamicFontLoadingEnabled = hasNecessaryExpoFeatures;
30
+
31
+ export const isDynamicLoadingSupported = () => hasNecessaryExpoFeatures;
32
+
33
+ /**
34
+ * Set whether dynamic loading of fonts is enabled.
35
+ * Currently, the presence of Expo Asset and Font Loader modules is a prerequisite for enabling.
36
+ * In the future, React Native core apis will be used for dynamic font loading.
37
+ *
38
+ * @param value - whether dynamic loading of fonts is enabled
39
+ * @returns `true` if dynamic loading of fonts was successfully set. `false` otherwise.
40
+ * */
41
+ export const setDynamicLoadingEnabled = (value: boolean): boolean => {
42
+ if (!hasNecessaryExpoFeatures) {
43
+ if (process.env.NODE_ENV !== 'production' && !!value) {
44
+ const message = hasNecessaryExpoModules
45
+ ? 'Expo is installed, but does not support dynamic font loading. Make sure to use Expo SDK 52 or newer.'
46
+ : 'Necessary Expo modules not found. Dynamic font loading is not available on Web or when necessary Expo modules are not present.';
47
+ console.error(message); // eslint-disable-line no-console
48
+ }
49
+ return false;
50
+ }
51
+
52
+ dynamicFontLoadingEnabled = !!value;
53
+
54
+ return true;
55
+ };
56
+
57
+ /**
58
+ * Whether dynamic loading of fonts is enabled.
59
+ * */
60
+ export const isDynamicLoadingEnabled = () => dynamicFontLoadingEnabled;
61
+
62
+ type ErrorCallback = (args: {
63
+ error: Error;
64
+ fontFamily: string;
65
+ fontSource: FontSource;
66
+ }) => void;
67
+
68
+ let dynamicLoadingErrorCallback: undefined | ErrorCallback;
69
+
70
+ /**
71
+ * Set a callback to be called when an error occurs during dynamic font loading.
72
+ * */
73
+ export const setDynamicLoadingErrorCallback = (callback: ErrorCallback) => {
74
+ dynamicLoadingErrorCallback = callback;
75
+ };
76
+
77
+ export const getErrorCallback = () => dynamicLoadingErrorCallback;
@@ -0,0 +1,10 @@
1
+ // the result of calling require('path')
2
+ type ModuleId = number;
3
+ type LocalFileSystemUri = string;
4
+
5
+ export type FontSource = ModuleId | LocalFileSystemUri;
6
+
7
+ export type DynamicLoader = {
8
+ loadFontAsync: (fontFamily: string, fontSource: FontSource) => Promise<void>;
9
+ isLoaded: (fontFamily: string) => boolean;
10
+ };
package/src/index.ts CHANGED
@@ -1,2 +1,49 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
1
3
  export { createIconSet, DEFAULT_ICON_SIZE, DEFAULT_ICON_COLOR } from './create-icon-set';
2
- export type { IconProps } from './create-icon-set';
4
+ export type { IconProps, CreateIconSetOptions } from './create-icon-set';
5
+ export {
6
+ setDynamicLoadingEnabled,
7
+ isDynamicLoadingEnabled,
8
+ isDynamicLoadingSupported,
9
+ setDynamicLoadingErrorCallback,
10
+ } from './dynamicLoading/dynamic-loading-setting';
11
+
12
+ const LINKING_ERROR = `
13
+ The package '@react-native-vector-icons/common' doesn't seem to be linked. Make sure:
14
+ ${Platform.select({ ios: "- You have run 'pod install'\n", default: '' })}
15
+ - You rebuilt the app after installing the package\n'
16
+ - You are not using Expo Go
17
+ `;
18
+
19
+ // @ts-expect-error : NativeModules type is incomplete
20
+ const isTurboModuleEnabled = global.__turboModuleProxy != null; // eslint-disable-line no-underscore-dangle
21
+
22
+ const VectorIconsModule = isTurboModuleEnabled
23
+ ? require('./NativeVectorIcons').default // eslint-disable-line @typescript-eslint/no-require-imports
24
+ : NativeModules.VectorIcons;
25
+
26
+ const VectorIcons = VectorIconsModule
27
+ ? VectorIconsModule
28
+ : new Proxy(
29
+ {},
30
+ {
31
+ get() {
32
+ throw new Error(LINKING_ERROR);
33
+ },
34
+ },
35
+ );
36
+
37
+ // TODO: Do we want to expose this as a public API?
38
+ export function getImageForFont(
39
+ fontFamilyName: string,
40
+ glyph: string,
41
+ fontSize: number,
42
+ color: number,
43
+ ): Promise<string> {
44
+ return VectorIcons.getImageForFont(fontFamilyName, glyph, fontSize, color);
45
+ }
46
+
47
+ export function getImageForFontSync(fontFamilyName: string, glyph: string, fontSize: number, color: number): string {
48
+ return VectorIcons.getImageForFontSync(fontFamilyName, glyph, fontSize, color);
49
+ }
@@ -0,0 +1,52 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { resolveNodeModuleDir } from '@react-native-community/cli-tools';
4
+
5
+ const getPackageJson = (filename: string) => {
6
+ const packageData = fs.readFileSync(filename, 'utf-8');
7
+ const packageJson = JSON.parse(packageData);
8
+
9
+ return packageJson;
10
+ };
11
+
12
+ const getPackageFontDirectories = (packageJsonFilename: string) => {
13
+ const rootPackageJson = getPackageJson(packageJsonFilename);
14
+ const dependencies = Object.keys(rootPackageJson.dependencies || {});
15
+
16
+ const packageDirs: string[] = [];
17
+ dependencies.forEach((dependency) => {
18
+ const dir = resolveNodeModuleDir(packageJsonFilename, dependency);
19
+ const packageJson = getPackageJson(`${dir}/package.json`);
20
+ if (packageJson.keywords?.includes?.('react-native-vector-icons-icon')) {
21
+ packageDirs.push(`${dir}/fonts`);
22
+ }
23
+ });
24
+
25
+ return packageDirs;
26
+ };
27
+
28
+ const getLocalFontsDir = (packageJsonFilename: string) => {
29
+ const rootPackageJson = getPackageJson(packageJsonFilename);
30
+ const config = rootPackageJson.reactNativeVectorIcons || {};
31
+
32
+ return `${path.dirname(packageJsonFilename)}/${config.fontDir || 'rnvi-fonts'}`;
33
+ };
34
+
35
+ const getFonts = (fontDir: string) => {
36
+ if (!fs.existsSync(fontDir)) {
37
+ return [];
38
+ }
39
+
40
+ const fonts = fs.readdirSync(fontDir);
41
+ const fontPaths = fonts.map((font) => `${fontDir}/${font}`);
42
+
43
+ return fontPaths;
44
+ };
45
+
46
+ export const getFontPaths = (packageJsonFilename: string) => {
47
+ const packageDirs = getPackageFontDirectories(packageJsonFilename);
48
+ packageDirs.push(getLocalFontsDir(packageJsonFilename));
49
+ const fonts = packageDirs.map(getFonts);
50
+
51
+ return fonts.flat();
52
+ };