@react-native-vector-icons/common 12.0.1 → 12.2.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.
- package/README.md +50 -38
- package/lib/commonjs/create-icon-set.js +12 -53
- package/lib/commonjs/create-icon-set.js.map +1 -1
- package/lib/commonjs/create-icon-source-cache.js +0 -2
- package/lib/commonjs/create-icon-source-cache.js.map +1 -1
- package/lib/commonjs/defaults.js +9 -0
- package/lib/commonjs/defaults.js.map +1 -0
- package/lib/commonjs/dynamicLoading/dynamic-font-loading.js +10 -2
- package/lib/commonjs/dynamicLoading/dynamic-font-loading.js.map +1 -1
- package/lib/commonjs/dynamicLoading/dynamic-loading-setting.js +15 -5
- package/lib/commonjs/dynamicLoading/dynamic-loading-setting.js.map +1 -1
- package/lib/commonjs/get-image-library.js +25 -5
- package/lib/commonjs/get-image-library.js.map +1 -1
- package/lib/commonjs/get-image-source.js +58 -0
- package/lib/commonjs/get-image-source.js.map +1 -0
- package/lib/commonjs/index.js +3 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/scripts/common.js.map +1 -1
- package/lib/commonjs/scripts/updatePlist.js.map +1 -1
- package/lib/module/create-icon-set.js +11 -52
- package/lib/module/create-icon-set.js.map +1 -1
- package/lib/module/create-icon-source-cache.js +0 -2
- package/lib/module/create-icon-source-cache.js.map +1 -1
- package/lib/module/defaults.js +5 -0
- package/lib/module/defaults.js.map +1 -0
- package/lib/module/dynamicLoading/dynamic-font-loading.js +10 -2
- package/lib/module/dynamicLoading/dynamic-font-loading.js.map +1 -1
- package/lib/module/dynamicLoading/dynamic-loading-setting.js +13 -4
- package/lib/module/dynamicLoading/dynamic-loading-setting.js.map +1 -1
- package/lib/module/get-image-library.js +26 -5
- package/lib/module/get-image-library.js.map +1 -1
- package/lib/module/get-image-source.js +52 -0
- package/lib/module/get-image-source.js.map +1 -0
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/scripts/common.js.map +1 -1
- package/lib/module/scripts/updatePlist.js.map +1 -1
- package/lib/typescript/commonjs/src/create-icon-set.d.ts +0 -2
- package/lib/typescript/commonjs/src/create-icon-set.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/create-icon-source-cache.d.ts +0 -1
- package/lib/typescript/commonjs/src/create-icon-source-cache.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/defaults.d.ts +3 -0
- package/lib/typescript/commonjs/src/defaults.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts +20 -1
- package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/get-image-library.d.ts +4 -1
- package/lib/typescript/commonjs/src/get-image-library.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/get-image-source.d.ts +11 -0
- package/lib/typescript/commonjs/src/get-image-source.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -3
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/scripts/common.d.ts.map +1 -1
- package/lib/typescript/module/src/create-icon-set.d.ts +0 -2
- package/lib/typescript/module/src/create-icon-set.d.ts.map +1 -1
- package/lib/typescript/module/src/create-icon-source-cache.d.ts +0 -1
- package/lib/typescript/module/src/create-icon-source-cache.d.ts.map +1 -1
- package/lib/typescript/module/src/defaults.d.ts +3 -0
- package/lib/typescript/module/src/defaults.d.ts.map +1 -0
- package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.d.ts.map +1 -1
- package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts +20 -1
- package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts.map +1 -1
- package/lib/typescript/module/src/get-image-library.d.ts +4 -1
- package/lib/typescript/module/src/get-image-library.d.ts.map +1 -1
- package/lib/typescript/module/src/get-image-source.d.ts +11 -0
- package/lib/typescript/module/src/get-image-source.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -3
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/scripts/common.d.ts.map +1 -1
- package/package.json +12 -3
- package/src/create-icon-set.tsx +16 -69
- package/src/create-icon-source-cache.ts +1 -3
- package/src/defaults.ts +2 -0
- package/src/dynamicLoading/dynamic-font-loading.ts +9 -3
- package/src/dynamicLoading/dynamic-loading-setting.ts +36 -11
- package/src/get-image-library.ts +30 -9
- package/src/get-image-source.ts +74 -0
- package/src/index.ts +4 -3
- package/src/scripts/common.ts +1 -0
- package/src/scripts/updatePlist.ts +1 -0
- package/android/generated/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeVectorIconsSpec.java +0 -42
- package/android/generated/android/app/build/generated/source/codegen/jni/CMakeLists.txt +0 -36
- package/android/generated/android/app/build/generated/source/codegen/jni/RNVectorIconsSpec-generated.cpp +0 -38
- package/android/generated/android/app/build/generated/source/codegen/jni/RNVectorIconsSpec.h +0 -31
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.cpp +0 -22
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.h +0 -24
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/EventEmitters.cpp +0 -16
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/EventEmitters.h +0 -17
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/Props.cpp +0 -19
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/Props.h +0 -18
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/RNVectorIconsSpecJSI-generated.cpp +0 -40
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/RNVectorIconsSpecJSI.h +0 -76
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/ShadowNodes.cpp +0 -17
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/ShadowNodes.h +0 -23
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/States.cpp +0 -16
- package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNVectorIconsSpec/States.h +0 -19
- package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec-generated.mm +0 -2321
- package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec.h +0 -2761
- package/ios/generated/build/generated/ios/FBReactNativeSpecJSI-generated.cpp +0 -2929
- package/ios/generated/build/generated/ios/FBReactNativeSpecJSI.h +0 -7727
- package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.h +0 -18
- package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.mm +0 -33
- package/ios/generated/build/generated/ios/RNVectorIconsSpec/RNVectorIconsSpec-generated.mm +0 -46
- package/ios/generated/build/generated/ios/RNVectorIconsSpec/RNVectorIconsSpec.h +0 -68
- package/ios/generated/build/generated/ios/RNVectorIconsSpecJSI-generated.cpp +0 -40
- package/ios/generated/build/generated/ios/RNVectorIconsSpecJSI.h +0 -76
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.cpp +0 -22
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/ComponentDescriptors.h +0 -24
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/EventEmitters.cpp +0 -16
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/EventEmitters.h +0 -17
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/Props.cpp +0 -19
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/Props.h +0 -18
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/RCTComponentViewHelpers.h +0 -18
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/ShadowNodes.cpp +0 -17
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/ShadowNodes.h +0 -23
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/States.cpp +0 -16
- package/ios/generated/build/generated/ios/react/renderer/components/RNVectorIconsSpec/States.h +0 -19
- package/lib/commonjs/dynamicLoading/dynamic-font-loading.web.js +0 -20
- package/lib/commonjs/dynamicLoading/dynamic-font-loading.web.js.map +0 -1
- package/lib/module/dynamicLoading/dynamic-font-loading.web.js +0 -16
- package/lib/module/dynamicLoading/dynamic-font-loading.web.js.map +0 -1
- package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.web.d.ts +0 -6
- package/lib/typescript/commonjs/src/dynamicLoading/dynamic-font-loading.web.d.ts.map +0 -1
- package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.web.d.ts +0 -6
- package/lib/typescript/module/src/dynamicLoading/dynamic-font-loading.web.d.ts.map +0 -1
- package/src/dynamicLoading/dynamic-font-loading.web.ts +0 -15
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
1
|
+
export type { CreateIconSetOptions, IconProps } from './create-icon-set';
|
|
2
|
+
export { createIconSet } from './create-icon-set';
|
|
3
|
+
export { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from './defaults';
|
|
4
|
+
export { isDynamicLoadingEnabled, isDynamicLoadingSupported, setDynamicLoadingEnabled, setDynamicLoadingErrorCallback, } from './dynamicLoading/dynamic-loading-setting';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,0CAA0C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/common.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/common.ts"],"names":[],"mappings":"AA8CA,eAAO,MAAM,YAAY,GAAI,qBAAqB,MAAM,aAMvD,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React, { type Ref } from 'react';
|
|
2
2
|
import { Text, type TextProps, type TextStyle } from 'react-native';
|
|
3
3
|
import type { FontSource } from './dynamicLoading/types';
|
|
4
|
-
export declare const DEFAULT_ICON_SIZE = 12;
|
|
5
|
-
export declare const DEFAULT_ICON_COLOR = "black";
|
|
6
4
|
type ValueData = {
|
|
7
5
|
uri: string;
|
|
8
6
|
scale: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-icon-set.d.ts","sourceRoot":"","sources":["../../../../src/create-icon-set.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAc,KAAK,GAAG,EAAa,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"create-icon-set.d.ts","sourceRoot":"","sources":["../../../../src/create-icon-set.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAc,KAAK,GAAG,EAAa,MAAM,OAAO,CAAC;AAE/D,OAAO,EAAY,IAAI,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAM9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD,KAAK,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAChD,KAAK,0BAA0B,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,KAAK,SAAS,GAAG,SAAS,CAAC;AACrH,KAAK,sBAAsB,CAAC,EAAE,IAAI,CAChC,IAAI,EAAE,EAAE,EACR,IAAI,CAAC,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,KACvB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;AAEpC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,SAAS,GAAG;IACrC,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC3B,QAAQ,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;CACtB,CAAC;AAEF,KAAK,aAAa,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE,CAC9D,SAAS,GAAG;IACV,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC3B,QAAQ,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;CACtB,GAAG,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAC9B,GAAG;IACF,cAAc,EAAE,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC;IACjD,kBAAkB,EAAE,0BAA0B,CAAC,MAAM,EAAE,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CAChC,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7D,QAAQ,EAAE,EAAE,EACZ,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAC7B,aAAa,CAAC,EAAE,CAAC,CAAC;AACrB,wBAAgB,aAAa,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7D,QAAQ,EAAE,EAAE,EACZ,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -14,7 +14,6 @@ type Value = {
|
|
|
14
14
|
export default function createIconSourceCache(): {
|
|
15
15
|
setValue: (key: string, value: ValueData) => Map<string, Value>;
|
|
16
16
|
setError: (key: string, error: Error) => Map<string, Value>;
|
|
17
|
-
has: (key: string) => boolean;
|
|
18
17
|
get: (key: string) => ValueData | undefined;
|
|
19
18
|
};
|
|
20
19
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-icon-source-cache.d.ts","sourceRoot":"","sources":["../../../../src/create-icon-source-cache.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,UAAU,UAAU,CAAC;AAC3B,QAAA,MAAM,UAAU,UAAU,CAAC;AAE3B,KAAK,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,OAAO,UAAU,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,UAAU,CAAC;IAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC;AAErG,MAAM,CAAC,OAAO,UAAU,qBAAqB;oBAGpB,MAAM,SAAS,SAAS;oBAExB,MAAM,SAAS,KAAK;eAEzB,MAAM;
|
|
1
|
+
{"version":3,"file":"create-icon-source-cache.d.ts","sourceRoot":"","sources":["../../../../src/create-icon-source-cache.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,UAAU,UAAU,CAAC;AAC3B,QAAA,MAAM,UAAU,UAAU,CAAC;AAE3B,KAAK,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,OAAO,UAAU,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,UAAU,CAAC;IAAC,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC;AAErG,MAAM,CAAC,OAAO,UAAU,qBAAqB;oBAGpB,MAAM,SAAS,SAAS;oBAExB,MAAM,SAAS,KAAK;eAEzB,MAAM;EAczB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../../src/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,kBAAkB,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-font-loading.d.ts","sourceRoot":"","sources":["../../../../../src/dynamicLoading/dynamic-font-loading.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dynamic-font-loading.d.ts","sourceRoot":"","sources":["../../../../../src/dynamicLoading/dynamic-font-loading.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,SAAS,CAAC;AAkFzD,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
|
|
@@ -2,15 +2,27 @@ import type { FontSource } from './types';
|
|
|
2
2
|
type ExpoAssetModule = {
|
|
3
3
|
downloadAsync: (uri: string, hash: string | undefined, type: string) => Promise<string>;
|
|
4
4
|
};
|
|
5
|
+
export type LoadAsyncAsset = string | {
|
|
6
|
+
uri: string;
|
|
7
|
+
display: string;
|
|
8
|
+
};
|
|
5
9
|
type ExpoFontLoaderModule = {
|
|
6
10
|
getLoadedFonts: () => string[];
|
|
7
|
-
loadAsync: (fontFamilyAlias: string,
|
|
11
|
+
loadAsync: (fontFamilyAlias: string, asset: LoadAsyncAsset) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
type ExpoFontUtilsModule = {
|
|
14
|
+
renderToImageAsync: (glyph: string, options: {
|
|
15
|
+
fontFamily?: string;
|
|
16
|
+
size?: number;
|
|
17
|
+
color?: number;
|
|
18
|
+
}) => Promise<string>;
|
|
8
19
|
};
|
|
9
20
|
declare global {
|
|
10
21
|
interface ExpoGlobal {
|
|
11
22
|
modules: {
|
|
12
23
|
ExpoAsset?: ExpoAssetModule;
|
|
13
24
|
ExpoFontLoader?: ExpoFontLoaderModule;
|
|
25
|
+
ExpoFontUtils?: ExpoFontUtilsModule;
|
|
14
26
|
};
|
|
15
27
|
}
|
|
16
28
|
var expo: ExpoGlobal | undefined;
|
|
@@ -21,6 +33,13 @@ type ExpoGlobalType = {
|
|
|
21
33
|
ExpoFontLoader: ExpoFontLoaderModule;
|
|
22
34
|
};
|
|
23
35
|
};
|
|
36
|
+
export declare function getIsRenderToImageSupported(globalObj: any): globalObj is {
|
|
37
|
+
expo: {
|
|
38
|
+
modules: {
|
|
39
|
+
ExpoFontUtils: ExpoFontUtilsModule;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
24
43
|
export declare function assertExpoModulesPresent(globalObj: unknown): asserts globalObj is {
|
|
25
44
|
expo: ExpoGlobalType;
|
|
26
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-loading-setting.d.ts","sourceRoot":"","sources":["../../../../../src/dynamicLoading/dynamic-loading-setting.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dynamic-loading-setting.d.ts","sourceRoot":"","sources":["../../../../../src/dynamicLoading/dynamic-loading-setting.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,KAAK,eAAe,GAAG;IAGrB,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACzF,CAAC;AAGF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvE,KAAK,oBAAoB,GAAG;IAG1B,cAAc,EAAE,MAAM,MAAM,EAAE,CAAC;IAC/B,SAAS,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9E,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,kBAAkB,EAAE,CAClB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QACP,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,KACE,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB,OAAO,EAAE;YACP,SAAS,CAAC,EAAE,eAAe,CAAC;YAC5B,cAAc,CAAC,EAAE,oBAAoB,CAAC;YACtC,aAAa,CAAC,EAAE,mBAAmB,CAAC;SACrC,CAAC;KACH;IAGD,IAAI,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;CAClC;AAED,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE;QACP,SAAS,EAAE,eAAe,CAAC;QAC3B,cAAc,EAAE,oBAAoB,CAAC;KACtC,CAAC;CACH,CAAC;AAeF,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS,IAAI;IACxE,IAAI,EAAE;QACJ,OAAO,EAAE;YACP,aAAa,EAAE,mBAAmB,CAAC;SACpC,CAAC;KACH,CAAC;CACH,CAEA;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAI1G;AASD,eAAO,MAAM,yBAAyB,eAAiC,CAAC;AAExE;;;;;;;KAOK;AACL,eAAO,MAAM,wBAAwB,GAAI,OAAO,OAAO,KAAG,OAczD,CAAC;AAEF;;KAEK;AACL,eAAO,MAAM,uBAAuB,eAAkC,CAAC;AAEvE,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,KAAK,IAAI,CAAC;AAIlG;;KAEK;AACL,eAAO,MAAM,8BAA8B,GAAI,UAAU,aAAa,SAErE,CAAC;AAEF,eAAO,MAAM,gBAAgB,iCAAoC,CAAC"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export declare const ensureGetImageAvailable: () => typeof import("@react-native-vector-icons/get-image")
|
|
1
|
+
export declare const ensureGetImageAvailable: () => typeof import("@react-native-vector-icons/get-image") | {
|
|
2
|
+
getImageForFont: (fontReference: string, glyph: string, size: number, color: number) => Promise<string>;
|
|
3
|
+
getImageForFontSync: () => never;
|
|
4
|
+
};
|
|
2
5
|
//# sourceMappingURL=get-image-library.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-image-library.d.ts","sourceRoot":"","sources":["../../../../src/get-image-library.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-image-library.d.ts","sourceRoot":"","sources":["../../../../src/get-image-library.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,uBAAuB;qCAQS,MAAM,SAAS,MAAM,QAAQ,MAAM,SAAS,MAAM;;CAgB9F,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TextStyle } from 'react-native';
|
|
2
|
+
import type createIconSourceCache from './create-icon-source-cache';
|
|
3
|
+
export declare const getImageSourceSync: (imageSourceCache: ReturnType<typeof createIconSourceCache>, fontReference: string, glyph: string, size?: number, color?: TextStyle["color"]) => {
|
|
4
|
+
uri: string;
|
|
5
|
+
scale: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const getImageSource: (imageSourceCache: ReturnType<typeof createIconSourceCache>, fontReference: string, glyph: string, size?: number, color?: TextStyle["color"]) => Promise<{
|
|
8
|
+
uri: string;
|
|
9
|
+
scale: number;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=get-image-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-image-source.d.ts","sourceRoot":"","sources":["../../../../src/get-image-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAC;AAIpE,eAAO,MAAM,kBAAkB,GAC7B,kBAAkB,UAAU,CAAC,OAAO,qBAAqB,CAAC,EAC1D,eAAe,MAAM,EACrB,OAAO,MAAM,EACb,aAAwB,EACxB,QAAO,SAAS,CAAC,OAAO,CAAsB;;;CA2B/C,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,kBAAkB,UAAU,CAAC,OAAO,qBAAqB,CAAC,EAC1D,eAAe,MAAM,EACrB,OAAO,MAAM,EACb,aAAwB,EACxB,QAAO,SAAS,CAAC,OAAO,CAAsB;;;EA2B/C,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
1
|
+
export type { CreateIconSetOptions, IconProps } from './create-icon-set';
|
|
2
|
+
export { createIconSet } from './create-icon-set';
|
|
3
|
+
export { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from './defaults';
|
|
4
|
+
export { isDynamicLoadingEnabled, isDynamicLoadingSupported, setDynamicLoadingEnabled, setDynamicLoadingErrorCallback, } from './dynamicLoading/dynamic-loading-setting';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,0CAA0C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/common.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../../src/scripts/common.ts"],"names":[],"mappings":"AA8CA,eAAO,MAAM,YAAY,GAAI,qBAAqB,MAAM,aAMvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-vector-icons/common",
|
|
3
|
-
"version": "12.0
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "Customizable Icons for React Native with support for image source and full styling.",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/commonjs/index.js",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/plist": "^3.0.5",
|
|
79
|
-
"@types/react": "^
|
|
79
|
+
"@types/react": "^19.0.12",
|
|
80
80
|
"del-cli": "^6.0.0",
|
|
81
81
|
"onchange": "^7.1.0",
|
|
82
82
|
"react-native-builder-bob": "^0.35.2",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"react": "*",
|
|
87
87
|
"react-native": "*",
|
|
88
|
-
"@react-native-vector-icons/get-image": "^12.0
|
|
88
|
+
"@react-native-vector-icons/get-image": "^12.1.0"
|
|
89
89
|
},
|
|
90
90
|
"peerDependenciesMeta": {
|
|
91
91
|
"@react-native-vector-icons/get-image": {
|
|
@@ -131,6 +131,15 @@
|
|
|
131
131
|
"type": "library",
|
|
132
132
|
"version": "0.41.2"
|
|
133
133
|
},
|
|
134
|
+
"nx": {
|
|
135
|
+
"targets": {
|
|
136
|
+
"build": {
|
|
137
|
+
"dependsOn": [
|
|
138
|
+
"@react-native-vector-icons/get-image:build"
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
134
143
|
"scripts": {
|
|
135
144
|
"clean": "del-cli lib",
|
|
136
145
|
"watch": "onchange 'src/**' --initial -- pnpm run prepare"
|
package/src/create-icon-set.tsx
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
2
|
import React, { forwardRef, type Ref, useEffect } from 'react';
|
|
3
|
-
|
|
4
3
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
5
|
-
import {
|
|
4
|
+
import { Platform, Text, type TextProps, type TextStyle } from 'react-native';
|
|
6
5
|
|
|
7
6
|
import createIconSourceCache from './create-icon-source-cache';
|
|
7
|
+
import { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from './defaults';
|
|
8
8
|
import { dynamicLoader } from './dynamicLoading/dynamic-font-loading';
|
|
9
9
|
import { isDynamicLoadingEnabled } from './dynamicLoading/dynamic-loading-setting';
|
|
10
10
|
import type { FontSource } from './dynamicLoading/types';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
export const DEFAULT_ICON_SIZE = 12;
|
|
14
|
-
export const DEFAULT_ICON_COLOR = 'black';
|
|
11
|
+
import { getImageSource as getImageSourceImpl, getImageSourceSync as getImageSourceSyncImpl } from './get-image-source';
|
|
15
12
|
|
|
16
13
|
type ValueData = { uri: string; scale: number };
|
|
17
14
|
type GetImageSourceSyncIconFunc<GM> = (name: GM, size?: number, color?: TextStyle['color']) => ValueData | undefined;
|
|
@@ -65,7 +62,11 @@ export function createIconSet<GM extends Record<string, number>>(
|
|
|
65
62
|
): IconComponent<GM> {
|
|
66
63
|
const { postScriptName, fontFileName, fontStyle } =
|
|
67
64
|
typeof postScriptNameOrOptions === 'string'
|
|
68
|
-
? {
|
|
65
|
+
? {
|
|
66
|
+
postScriptName: postScriptNameOrOptions,
|
|
67
|
+
fontFileName: fontFileNameParam,
|
|
68
|
+
fontStyle: fontStyleParam,
|
|
69
|
+
}
|
|
69
70
|
: postScriptNameOrOptions;
|
|
70
71
|
|
|
71
72
|
const fontBasename = fontFileName ? fontFileName.replace(/\.(otf|ttf)$/, '') : postScriptName;
|
|
@@ -83,13 +84,13 @@ export function createIconSet<GM extends Record<string, number>>(
|
|
|
83
84
|
};
|
|
84
85
|
|
|
85
86
|
const resolveGlyph = (name: keyof GM) => {
|
|
86
|
-
const glyph = glyphMap[name]
|
|
87
|
+
const glyph = glyphMap[name];
|
|
87
88
|
|
|
88
89
|
if (typeof glyph === 'number') {
|
|
89
90
|
return String.fromCodePoint(glyph);
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
return
|
|
93
|
+
return '?';
|
|
93
94
|
};
|
|
94
95
|
|
|
95
96
|
const Icon = ({
|
|
@@ -153,69 +154,15 @@ export function createIconSet<GM extends Record<string, number>>(
|
|
|
153
154
|
|
|
154
155
|
const imageSourceCache = createIconSourceCache();
|
|
155
156
|
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
color: TextStyle['color'] = DEFAULT_ICON_COLOR,
|
|
160
|
-
) => {
|
|
161
|
-
const NativeIconAPI = ensureGetImageAvailable();
|
|
162
|
-
|
|
163
|
-
const glyph = resolveGlyph(name);
|
|
164
|
-
const processedColor = processColor(color);
|
|
165
|
-
const cacheKey = `${glyph}:${size}:${String(processedColor)}`;
|
|
166
|
-
|
|
167
|
-
if (imageSourceCache.has(cacheKey)) {
|
|
168
|
-
// FIXME: Should this check if it's an error and throw it again?
|
|
169
|
-
return imageSourceCache.get(cacheKey);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
const imagePath = NativeIconAPI.getImageForFontSync(
|
|
174
|
-
fontReference,
|
|
175
|
-
glyph,
|
|
176
|
-
size,
|
|
177
|
-
processedColor as number, // FIXME what if a non existant colour was passed in?
|
|
178
|
-
);
|
|
179
|
-
const value = { uri: imagePath, scale: PixelRatio.get() };
|
|
180
|
-
imageSourceCache.setValue(cacheKey, value);
|
|
181
|
-
return value;
|
|
182
|
-
} catch (error) {
|
|
183
|
-
imageSourceCache.setError(cacheKey, error as Error);
|
|
184
|
-
throw error;
|
|
157
|
+
const getImageSource: GetImageSourceIconFunc<keyof GM> = async (name, size, color) => {
|
|
158
|
+
if (typeof postScriptNameOrOptions === 'object' && typeof postScriptNameOrOptions.fontSource !== 'undefined') {
|
|
159
|
+
await dynamicLoader.loadFontAsync(fontReference, postScriptNameOrOptions.fontSource);
|
|
185
160
|
}
|
|
161
|
+
return getImageSourceImpl(imageSourceCache, fontReference, resolveGlyph(name), size, color);
|
|
186
162
|
};
|
|
187
163
|
|
|
188
|
-
const
|
|
189
|
-
name
|
|
190
|
-
size = DEFAULT_ICON_SIZE,
|
|
191
|
-
color: TextStyle['color'] = DEFAULT_ICON_COLOR,
|
|
192
|
-
) => {
|
|
193
|
-
const NativeIconAPI = ensureGetImageAvailable();
|
|
194
|
-
|
|
195
|
-
const glyph = resolveGlyph(name);
|
|
196
|
-
const processedColor = processColor(color);
|
|
197
|
-
const cacheKey = `${glyph}:${size}:${String(processedColor)}`;
|
|
198
|
-
|
|
199
|
-
if (imageSourceCache.has(cacheKey)) {
|
|
200
|
-
// FIXME: Should this check if it's an error and throw it again?
|
|
201
|
-
return imageSourceCache.get(cacheKey);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
const imagePath = await NativeIconAPI.getImageForFont(
|
|
206
|
-
fontReference,
|
|
207
|
-
glyph,
|
|
208
|
-
size,
|
|
209
|
-
processedColor as number, // FIXME what if a non existant colour was passed in?
|
|
210
|
-
);
|
|
211
|
-
const value = { uri: imagePath, scale: PixelRatio.get() };
|
|
212
|
-
imageSourceCache.setValue(cacheKey, value);
|
|
213
|
-
return value;
|
|
214
|
-
} catch (error) {
|
|
215
|
-
imageSourceCache.setError(cacheKey, error as Error);
|
|
216
|
-
throw error;
|
|
217
|
-
}
|
|
218
|
-
};
|
|
164
|
+
const getImageSourceSync: GetImageSourceSyncIconFunc<keyof GM> = (name, size, color) =>
|
|
165
|
+
getImageSourceSyncImpl(imageSourceCache, fontReference, resolveGlyph(name), size, color);
|
|
219
166
|
|
|
220
167
|
const IconNamespace = Object.assign(WrappedIcon, {
|
|
221
168
|
getImageSource,
|
|
@@ -12,8 +12,6 @@ export default function createIconSourceCache() {
|
|
|
12
12
|
|
|
13
13
|
const setError = (key: string, error: Error) => cache.set(key, { type: TYPE_ERROR, data: error });
|
|
14
14
|
|
|
15
|
-
const has = (key: string) => cache.has(key);
|
|
16
|
-
|
|
17
15
|
const get = (key: string) => {
|
|
18
16
|
const value = cache.get(key);
|
|
19
17
|
if (!value) {
|
|
@@ -27,5 +25,5 @@ export default function createIconSourceCache() {
|
|
|
27
25
|
return data;
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
return { setValue, setError,
|
|
28
|
+
return { setValue, setError, get };
|
|
31
29
|
}
|
package/src/defaults.ts
ADDED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* The following imports are always present when react native is installed
|
|
3
3
|
* in the future, more explicit apis will be exposed by the core, including typings
|
|
4
4
|
* */
|
|
5
|
+
import { Image, Platform } from 'react-native';
|
|
6
|
+
|
|
5
7
|
// @ts-expect-error missing types
|
|
6
8
|
// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
|
|
7
9
|
import { getAssetByID } from '@react-native/assets-registry/registry';
|
|
8
|
-
|
|
9
|
-
import { assertExpoModulesPresent, getErrorCallback } from './dynamic-loading-setting';
|
|
10
|
+
|
|
11
|
+
import { assertExpoModulesPresent, getErrorCallback, type LoadAsyncAsset } from './dynamic-loading-setting';
|
|
10
12
|
import type { DynamicLoader, FontSource } from './types';
|
|
11
13
|
|
|
12
14
|
const loadPromises: { [fontSource: string]: Promise<void> } = {};
|
|
@@ -33,7 +35,11 @@ const loadFontAsync = async (fontFamily: string, fontSource: FontSource): Promis
|
|
|
33
35
|
return expoModules.ExpoAsset.downloadAsync(uri, hash, type);
|
|
34
36
|
})();
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
const asset = Platform.select<LoadAsyncAsset>({
|
|
39
|
+
web: { uri: localUri, display: 'auto' },
|
|
40
|
+
default: localUri,
|
|
41
|
+
});
|
|
42
|
+
await expoModules.ExpoFontLoader.loadAsync(fontFamily, asset);
|
|
37
43
|
} catch (error) {
|
|
38
44
|
console.error(`Failed to load font ${fontFamily}`, error); // eslint-disable-line no-console
|
|
39
45
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
1
3
|
import type { FontSource } from './types';
|
|
2
4
|
|
|
3
5
|
type ExpoAssetModule = {
|
|
@@ -6,11 +8,25 @@ type ExpoAssetModule = {
|
|
|
6
8
|
downloadAsync: (uri: string, hash: string | undefined, type: string) => Promise<string>;
|
|
7
9
|
};
|
|
8
10
|
|
|
11
|
+
// this is a file:// uri on native, or an object with uri and display on web
|
|
12
|
+
export type LoadAsyncAsset = string | { uri: string; display: string };
|
|
13
|
+
|
|
9
14
|
type ExpoFontLoaderModule = {
|
|
10
15
|
// definition from
|
|
11
16
|
// https://github.com/expo/expo/blob/1f5a5991d14aad09282d1ce1612b44d30e7e7d3d/packages/expo-font/ios/FontLoaderModule.swift#L18
|
|
12
17
|
getLoadedFonts: () => string[];
|
|
13
|
-
loadAsync: (fontFamilyAlias: string,
|
|
18
|
+
loadAsync: (fontFamilyAlias: string, asset: LoadAsyncAsset) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type ExpoFontUtilsModule = {
|
|
22
|
+
renderToImageAsync: (
|
|
23
|
+
glyph: string,
|
|
24
|
+
options: {
|
|
25
|
+
fontFamily?: string;
|
|
26
|
+
size?: number;
|
|
27
|
+
color?: number;
|
|
28
|
+
},
|
|
29
|
+
) => Promise<string>;
|
|
14
30
|
};
|
|
15
31
|
|
|
16
32
|
declare global {
|
|
@@ -18,6 +34,7 @@ declare global {
|
|
|
18
34
|
modules: {
|
|
19
35
|
ExpoAsset?: ExpoAssetModule;
|
|
20
36
|
ExpoFontLoader?: ExpoFontLoaderModule;
|
|
37
|
+
ExpoFontUtils?: ExpoFontUtilsModule;
|
|
21
38
|
};
|
|
22
39
|
}
|
|
23
40
|
|
|
@@ -38,19 +55,31 @@ function getIsDynamicLoadingSupported(globalObj: any): globalObj is {
|
|
|
38
55
|
} {
|
|
39
56
|
return (
|
|
40
57
|
globalObj?.expo &&
|
|
41
|
-
typeof globalObj.expo.modules?.ExpoAsset?.downloadAsync === 'function' &&
|
|
58
|
+
(Platform.OS === 'web' || typeof globalObj.expo.modules?.ExpoAsset?.downloadAsync === 'function') &&
|
|
42
59
|
typeof globalObj.expo.modules?.ExpoFontLoader?.getLoadedFonts === 'function' &&
|
|
43
60
|
typeof globalObj.expo.modules?.ExpoFontLoader?.loadAsync === 'function'
|
|
44
61
|
);
|
|
45
62
|
}
|
|
46
63
|
|
|
64
|
+
// biome-ignore lint/suspicious/noExplicitAny: this is used internally with globalThis
|
|
65
|
+
export function getIsRenderToImageSupported(globalObj: any): globalObj is {
|
|
66
|
+
expo: {
|
|
67
|
+
modules: {
|
|
68
|
+
ExpoFontUtils: ExpoFontUtilsModule;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
} {
|
|
72
|
+
return globalObj?.expo && typeof globalObj.expo.modules?.ExpoFontUtils?.renderToImageAsync === 'function';
|
|
73
|
+
}
|
|
74
|
+
|
|
47
75
|
export function assertExpoModulesPresent(globalObj: unknown): asserts globalObj is { expo: ExpoGlobalType } {
|
|
48
76
|
if (!getIsDynamicLoadingSupported(globalObj)) {
|
|
49
|
-
throw new Error('Dynamic font loading
|
|
77
|
+
throw new Error('Dynamic font loading not supported. Upgrade to latest expo and expo-font.');
|
|
50
78
|
}
|
|
51
79
|
}
|
|
52
80
|
|
|
53
|
-
const hasNecessaryExpoModules =
|
|
81
|
+
const hasNecessaryExpoModules =
|
|
82
|
+
(Platform.OS === 'web' || !!globalThis.expo?.modules?.ExpoAsset) && !!globalThis.expo?.modules?.ExpoFontLoader;
|
|
54
83
|
|
|
55
84
|
const hasNecessaryExpoFeatures = getIsDynamicLoadingSupported(globalThis);
|
|
56
85
|
|
|
@@ -70,8 +99,8 @@ export const setDynamicLoadingEnabled = (value: boolean): boolean => {
|
|
|
70
99
|
if (!hasNecessaryExpoFeatures) {
|
|
71
100
|
if (process.env.NODE_ENV !== 'production' && !!value) {
|
|
72
101
|
const message = hasNecessaryExpoModules
|
|
73
|
-
? 'Expo is installed, but does not support dynamic font loading. Make sure to use Expo SDK
|
|
74
|
-
: 'Necessary Expo modules not found. Dynamic font loading is not available
|
|
102
|
+
? 'Expo is installed, but does not support dynamic font loading. Make sure to use Expo SDK 54 or newer.'
|
|
103
|
+
: 'Necessary Expo modules not found. Dynamic font loading is not available when necessary Expo modules are not present.';
|
|
75
104
|
console.error(message); // eslint-disable-line no-console
|
|
76
105
|
}
|
|
77
106
|
return false;
|
|
@@ -87,11 +116,7 @@ export const setDynamicLoadingEnabled = (value: boolean): boolean => {
|
|
|
87
116
|
* */
|
|
88
117
|
export const isDynamicLoadingEnabled = () => dynamicFontLoadingEnabled;
|
|
89
118
|
|
|
90
|
-
type ErrorCallback = (args: {
|
|
91
|
-
error: Error;
|
|
92
|
-
fontFamily: string;
|
|
93
|
-
fontSource: FontSource;
|
|
94
|
-
}) => void;
|
|
119
|
+
type ErrorCallback = (args: { error: Error; fontFamily: string; fontSource: FontSource }) => void;
|
|
95
120
|
|
|
96
121
|
let dynamicLoadingErrorCallback: undefined | ErrorCallback;
|
|
97
122
|
|
package/src/get-image-library.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getIsRenderToImageSupported } from './dynamicLoading/dynamic-loading-setting';
|
|
2
|
+
|
|
1
3
|
// eslint-disable-next-line import/no-mutable-exports
|
|
2
4
|
let NativeIconAPI: typeof import('@react-native-vector-icons/get-image') | null = null;
|
|
3
5
|
|
|
@@ -5,17 +7,36 @@ try {
|
|
|
5
7
|
// eslint-disable-next-line global-require,import/no-extraneous-dependencies,@typescript-eslint/no-require-imports
|
|
6
8
|
NativeIconAPI = require('@react-native-vector-icons/get-image');
|
|
7
9
|
} catch {
|
|
8
|
-
//
|
|
10
|
+
// if this fails, it's likely due to:
|
|
11
|
+
// "Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'VectorIcons' could not be found. ..."
|
|
12
|
+
// No warning at this stage.
|
|
9
13
|
}
|
|
10
14
|
|
|
15
|
+
const globalRef = globalThis;
|
|
16
|
+
const hasExpoRenderToImage = getIsRenderToImageSupported(globalRef);
|
|
17
|
+
|
|
11
18
|
export const ensureGetImageAvailable = () => {
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
);
|
|
19
|
+
if (NativeIconAPI) {
|
|
20
|
+
NativeIconAPI.ensureNativeModuleAvailable();
|
|
21
|
+
return NativeIconAPI;
|
|
16
22
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
if (hasExpoRenderToImage) {
|
|
24
|
+
const { ExpoFontUtils } = globalRef.expo.modules;
|
|
25
|
+
return {
|
|
26
|
+
getImageForFont: async (fontReference: string, glyph: string, size: number, color: number) =>
|
|
27
|
+
ExpoFontUtils.renderToImageAsync(glyph, {
|
|
28
|
+
fontFamily: fontReference,
|
|
29
|
+
size,
|
|
30
|
+
color,
|
|
31
|
+
}),
|
|
32
|
+
getImageForFontSync: () => {
|
|
33
|
+
throw new Error(
|
|
34
|
+
'You attempted to call `getImageForFontSync`. Expo dev client with `@react-native-vector-icons/get-image` installed is required for this. Alternatively, call `getImageForFont` or generate the image yourself and bundle it with the app.',
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
throw new Error(
|
|
40
|
+
'Error in getImageSource / getImageSourceSync: You need to either (1) install `@react-native-vector-icons/get-image` or (2) use Expo SDK 53+ (Expo dev client or Expo Go). Check your setup and rebuild the app.',
|
|
41
|
+
);
|
|
21
42
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { TextStyle } from 'react-native';
|
|
2
|
+
import { PixelRatio, processColor } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type createIconSourceCache from './create-icon-source-cache';
|
|
5
|
+
import { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from './defaults';
|
|
6
|
+
import { ensureGetImageAvailable } from './get-image-library';
|
|
7
|
+
|
|
8
|
+
export const getImageSourceSync = (
|
|
9
|
+
imageSourceCache: ReturnType<typeof createIconSourceCache>,
|
|
10
|
+
fontReference: string,
|
|
11
|
+
glyph: string,
|
|
12
|
+
size = DEFAULT_ICON_SIZE,
|
|
13
|
+
color: TextStyle['color'] = DEFAULT_ICON_COLOR,
|
|
14
|
+
) => {
|
|
15
|
+
const NativeIconAPI = ensureGetImageAvailable();
|
|
16
|
+
|
|
17
|
+
const processedColor = processColor(color);
|
|
18
|
+
const cacheKey = `${glyph}:${size}:${String(processedColor)}`;
|
|
19
|
+
|
|
20
|
+
const maybeCachedValue = imageSourceCache.get(cacheKey);
|
|
21
|
+
if (maybeCachedValue !== undefined) {
|
|
22
|
+
// FIXME: Should this check if it's an error and throw it again?
|
|
23
|
+
return maybeCachedValue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const imagePath = NativeIconAPI.getImageForFontSync(
|
|
28
|
+
fontReference,
|
|
29
|
+
glyph,
|
|
30
|
+
size,
|
|
31
|
+
processedColor as number, // FIXME what if a non existent colour was passed in?
|
|
32
|
+
);
|
|
33
|
+
const value = { uri: imagePath, scale: PixelRatio.get() };
|
|
34
|
+
imageSourceCache.setValue(cacheKey, value);
|
|
35
|
+
return value;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
imageSourceCache.setError(cacheKey, error as Error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const getImageSource = async (
|
|
43
|
+
imageSourceCache: ReturnType<typeof createIconSourceCache>,
|
|
44
|
+
fontReference: string,
|
|
45
|
+
glyph: string,
|
|
46
|
+
size = DEFAULT_ICON_SIZE,
|
|
47
|
+
color: TextStyle['color'] = DEFAULT_ICON_COLOR,
|
|
48
|
+
) => {
|
|
49
|
+
const NativeIconAPI = ensureGetImageAvailable();
|
|
50
|
+
|
|
51
|
+
const processedColor = processColor(color);
|
|
52
|
+
const cacheKey = `${glyph}:${size}:${String(processedColor)}`;
|
|
53
|
+
|
|
54
|
+
const maybeCachedValue = imageSourceCache.get(cacheKey);
|
|
55
|
+
if (maybeCachedValue !== undefined) {
|
|
56
|
+
// FIXME: Should this check if it's an error and throw it again?
|
|
57
|
+
return maybeCachedValue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const imagePath = await NativeIconAPI.getImageForFont(
|
|
62
|
+
fontReference,
|
|
63
|
+
glyph,
|
|
64
|
+
size,
|
|
65
|
+
processedColor as number, // FIXME what if a non existent colour was passed in?
|
|
66
|
+
);
|
|
67
|
+
const value = { uri: imagePath, scale: PixelRatio.get() };
|
|
68
|
+
imageSourceCache.setValue(cacheKey, value);
|
|
69
|
+
return value;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
imageSourceCache.setError(cacheKey, error as Error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export type { CreateIconSetOptions, IconProps } from './create-icon-set';
|
|
2
|
+
export { createIconSet } from './create-icon-set';
|
|
3
|
+
export { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from './defaults';
|
|
3
4
|
export {
|
|
4
|
-
setDynamicLoadingEnabled,
|
|
5
5
|
isDynamicLoadingEnabled,
|
|
6
6
|
isDynamicLoadingSupported,
|
|
7
|
+
setDynamicLoadingEnabled,
|
|
7
8
|
setDynamicLoadingErrorCallback,
|
|
8
9
|
} from './dynamicLoading/dynamic-loading-setting';
|