@react-native-vector-icons/common 12.4.0 → 12.4.2
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 +8 -26
- package/lib/commonjs/create-icon-set.js +2 -3
- package/lib/commonjs/create-icon-set.js.map +1 -1
- package/lib/commonjs/create-icon-source-cache.js +3 -26
- package/lib/commonjs/create-icon-source-cache.js.map +1 -1
- package/lib/commonjs/dynamicLoading/dynamic-loading-setting.js +14 -7
- package/lib/commonjs/dynamicLoading/dynamic-loading-setting.js.map +1 -1
- package/lib/commonjs/get-image-library.js +9 -6
- package/lib/commonjs/get-image-library.js.map +1 -1
- package/lib/commonjs/get-image-source.js +15 -28
- package/lib/commonjs/get-image-source.js.map +1 -1
- package/lib/module/create-icon-set.js +1 -1
- package/lib/module/create-icon-set.js.map +1 -1
- package/lib/module/create-icon-source-cache.js +3 -26
- package/lib/module/create-icon-source-cache.js.map +1 -1
- package/lib/module/dynamicLoading/dynamic-loading-setting.js +14 -7
- package/lib/module/dynamicLoading/dynamic-loading-setting.js.map +1 -1
- package/lib/module/get-image-library.js +9 -6
- package/lib/module/get-image-library.js.map +1 -1
- package/lib/module/get-image-source.js +15 -28
- package/lib/module/get-image-source.js.map +1 -1
- package/lib/typescript/commonjs/src/create-icon-source-cache.d.ts +2 -12
- package/lib/typescript/commonjs/src/create-icon-source-cache.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/dynamicLoading/dynamic-loading-setting.d.ts +19 -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.map +1 -1
- package/lib/typescript/commonjs/src/get-image-source.d.ts +1 -1
- package/lib/typescript/commonjs/src/get-image-source.d.ts.map +1 -1
- package/lib/typescript/module/src/create-icon-source-cache.d.ts +2 -12
- package/lib/typescript/module/src/create-icon-source-cache.d.ts.map +1 -1
- package/lib/typescript/module/src/dynamicLoading/dynamic-loading-setting.d.ts +19 -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.map +1 -1
- package/lib/typescript/module/src/get-image-source.d.ts +1 -1
- package/lib/typescript/module/src/get-image-source.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/create-icon-set.tsx +1 -1
- package/src/create-icon-source-cache.ts +5 -23
- package/src/dynamicLoading/dynamic-loading-setting.ts +34 -10
- package/src/get-image-library.ts +6 -4
- package/src/get-image-source.ts +14 -31
package/README.md
CHANGED
|
@@ -45,12 +45,12 @@ RNVI comes with the following supported icons. You can [search NPM](https://www.
|
|
|
45
45
|
|
|
46
46
|
- [`AntDesign`](https://ant.design/components/icon) from Ant Group (v4.4.2 with _449_ icons)
|
|
47
47
|
- [`Feather`](http://feathericons.com) created by Cole Bemis & Contributors (v4.29.2 featuring _287_ icons)
|
|
48
|
-
- [`FontAwesome`](https://fontawesome.com/search) designed by Fonticons, Inc. (v7.
|
|
48
|
+
- [`FontAwesome`](https://fontawesome.com/search) designed by Fonticons, Inc. (v7.2.0 featuring _2,806_ free and _75,767_ pro icons)
|
|
49
49
|
- [`Foundation`](http://zurb.com/playground/foundation-icon-fonts-3) by ZURB, Inc. (v3.0 with _283_ icons)
|
|
50
50
|
- [`Ionicons`](https://ionic.io/ionicons) crafted by Ionic (v8.0.9 containing _1,357_ icons)
|
|
51
51
|
- [`MaterialDesignIcons`](https://pictogrammers.com/library/mdi/) from MaterialDesignIcons.com (v7.4.47 including _7448_ icons)
|
|
52
|
-
- [`Octicons`](https://primer.style/foundations/icons) designed by GitHub, Inc. (v19.
|
|
53
|
-
- [`Lucide`](https://lucide.dev/) designed by Lucide, (v0.
|
|
52
|
+
- [`Octicons`](https://primer.style/foundations/icons) designed by GitHub, Inc. (v19.22.0 with _339_ icons)
|
|
53
|
+
- [`Lucide`](https://lucide.dev/) designed by Lucide, (v0.576.0 with _1,639_ icons)
|
|
54
54
|
|
|
55
55
|
### No longer maintained upstream
|
|
56
56
|
|
|
@@ -73,16 +73,12 @@ See [MIGRATION.md](MIGRATION.md) if you are migrating from `react-native-vector-
|
|
|
73
73
|
1. Install the packages for the icons you want to use
|
|
74
74
|
|
|
75
75
|
```sh
|
|
76
|
-
npm install @react-native-vector-icons/
|
|
76
|
+
npm install @react-native-vector-icons/fontawesome-free-solid @react-native-vector-icons/evil-icons
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
1. Depending on the platform you're targeting (iOS/Android/Windows), follow the appropriate setup instructions below.
|
|
80
80
|
1. If you are using one of the following fonts, refer to their guides for further instructions
|
|
81
81
|
|
|
82
|
-
- [FontAwesome 6](packages/fontawesome6/README.md)
|
|
83
|
-
- [FontAwesome 6 Pro](packages/fontawesome6-pro/README.md)
|
|
84
|
-
- [FontAwesome 5](packages/fontawesome5/README.md)
|
|
85
|
-
- [FontAwesome 5 Pro](packages/fontawesome5-pro/README.md)
|
|
86
82
|
- [Fontello](packages/fontello/README.md)
|
|
87
83
|
- [Icomoon](packages/icomoon/README.md)
|
|
88
84
|
|
|
@@ -92,7 +88,7 @@ Refer to the guide for [Expo](./docs/SETUP-EXPO.md), [React Native](./docs/SETUP
|
|
|
92
88
|
|
|
93
89
|
### Font location customisation
|
|
94
90
|
|
|
95
|
-
For fonts like
|
|
91
|
+
For fonts like the FontAwesome Pro as well as fontello and icomoon where you provide the fonts the default location for the font files is `rnvi-fonts` in the same directory as your package.json. This can be customized by setting the `fontDir` property in your `package.json` file.
|
|
96
92
|
|
|
97
93
|
```json
|
|
98
94
|
{
|
|
@@ -107,9 +103,9 @@ For fonts like fontawesome6-pro, fontello and icomoon where you provide the font
|
|
|
107
103
|
You can either use one of the bundled icons above or roll your own custom font.
|
|
108
104
|
|
|
109
105
|
```js
|
|
110
|
-
import {
|
|
106
|
+
import { FontAwesomeFreeSolid } from "@react-native-vector-icons/fontawesome-free-solid";
|
|
111
107
|
|
|
112
|
-
<
|
|
108
|
+
<FontAwesomeFreeSolid name="rocket" size={30} color="#900" />;
|
|
113
109
|
```
|
|
114
110
|
|
|
115
111
|
### Props
|
|
@@ -140,20 +136,6 @@ By combining some of these you can create for example :
|
|
|
140
136
|

|
|
141
137
|

|
|
142
138
|
|
|
143
|
-
## Multi-Style Fonts
|
|
144
|
-
|
|
145
|
-
Some fonts today use multiple styles, FontAwesome 6 for example, which is supported by this library. The usage is pretty much the same as the standard `Icon` component:
|
|
146
|
-
|
|
147
|
-
```jsx
|
|
148
|
-
import { FontAwesome5 } from "@react-native-vector-icons/fontawesome5";
|
|
149
|
-
|
|
150
|
-
<FontAwesome5 name="comments" size={30} color="#900" />; // Defaults to regular
|
|
151
|
-
|
|
152
|
-
<FontAwesome5 name="comments" size={30} color="#900" iconType="solid" />
|
|
153
|
-
|
|
154
|
-
<FontAwesome5 name="comments" size={30} color="#900" iconType="light" />
|
|
155
|
-
```
|
|
156
|
-
|
|
157
139
|
## Usage as PNG Image/Source Object
|
|
158
140
|
|
|
159
141
|
Convenient way to plug this in into other components that rely on bitmap images rather than scalable vector icons. Takes the arguments `name`, `size` and `color` as described above.
|
|
@@ -222,7 +204,7 @@ animation library
|
|
|
222
204
|
|
|
223
205
|
Fonts can be available in an app statically (since build time) or loaded dynamically at runtime. The latter can be useful e.g. for apps that use over-the-air updates and want to load new fonts with an update, or when you need to use a font from a remote location.
|
|
224
206
|
|
|
225
|
-
Dynamic loading in `@react-native-vector-icons` is currently limited to those fonts that are bundled within the provided packages: it doesn't support Pro fonts (such as FontAwesome
|
|
207
|
+
Dynamic loading in `@react-native-vector-icons` is currently limited to those fonts that are bundled within the provided packages: it doesn't support Pro fonts (such as FontAwesome Pro). However, loading of custom fonts is not difficult to implement: use `createIconSet` as seen in [custom fonts](#custom-fonts) paragraph to obtain a icon font family with dynamic font loading enabled. See any of the free font packages for reference.
|
|
226
208
|
|
|
227
209
|
By default, dynamic loading is enabled if you run Expo SDK >= 52. It doesn't change the way you work with the package: If rendering an icon requires a font that is not known to the app, it will be loaded automatically and icon will render as expected.
|
|
228
210
|
|
|
@@ -6,13 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createIconSet = createIconSet;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
|
-
var _createIconSourceCache =
|
|
9
|
+
var _createIconSourceCache = require("./create-icon-source-cache.js");
|
|
10
10
|
var _defaults = require("./defaults.js");
|
|
11
11
|
var _dynamicFontLoading = require("./dynamicLoading/dynamic-font-loading.js");
|
|
12
12
|
var _dynamicLoadingSetting = require("./dynamicLoading/dynamic-loading-setting.js");
|
|
13
13
|
var _getImageSource = require("./get-image-source.js");
|
|
14
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
15
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
17
16
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
18
17
|
|
|
@@ -94,7 +93,7 @@ function createIconSet(glyphMap, postScriptNameOrOptions, fontFileNameParam, fon
|
|
|
94
93
|
...props
|
|
95
94
|
}));
|
|
96
95
|
WrappedIcon.displayName = `Icon(${postScriptName})`;
|
|
97
|
-
const imageSourceCache = (0, _createIconSourceCache.
|
|
96
|
+
const imageSourceCache = (0, _createIconSourceCache.createIconSourceCache)();
|
|
98
97
|
const getImageSource = async (name, size, color) => {
|
|
99
98
|
if (typeof postScriptNameOrOptions === 'object' && typeof postScriptNameOrOptions.fontSource !== 'undefined') {
|
|
100
99
|
await _dynamicFontLoading.dynamicLoader.loadFontAsync(fontReference, postScriptNameOrOptions.fontSource);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_createIconSourceCache","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_createIconSourceCache","_defaults","_dynamicFontLoading","_dynamicLoadingSetting","_getImageSource","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","createIconSet","glyphMap","postScriptNameOrOptions","fontFileNameParam","fontStyleParam","postScriptName","fontFileName","fontStyle","fontBasename","replace","fontReference","Platform","select","windows","android","styleOverrides","fontFamily","fontWeight","resolveGlyph","name","glyph","String","fromCodePoint","Icon","size","DEFAULT_ICON_SIZE","color","DEFAULT_ICON_COLOR","style","children","allowFontScaling","innerRef","props","isFontLoaded","setIsFontLoaded","React","useState","isDynamicLoadingEnabled","dynamicLoader","isLoaded","useEffect","isMounted","fontSource","loadFontAsync","finally","styleDefaults","fontSize","newProps","jsxs","Text","ref","selectable","WrappedIcon","forwardRef","jsx","displayName","imageSourceCache","createIconSourceCache","getImageSource","getImageSourceImpl","getImageSourceSync","getImageSourceSyncImpl","IconNamespace","assign"],"sourceRoot":"../../src","sources":["create-icon-set.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,sBAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,sBAAA,GAAAL,OAAA;AAEA,IAAAM,eAAA,GAAAN,OAAA;AAAwH,IAAAO,WAAA,GAAAP,OAAA;AAAA,SAAAD,wBAAAS,CAAA,EAAAC,CAAA,6BAA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CAACjC,aAAa,EAAER,uBAAuB,CAACwC,UAAU,CAAC;IACtF;IACA,OAAO,IAAAiB,8BAAkB,EAACH,gBAAgB,EAAE9C,aAAa,EAAEQ,YAAY,CAACC,IAAI,CAAC,EAAEK,IAAI,EAAEE,KAAK,CAAC;EAC7F,CAAC;EAED,MAAMkC,kBAAwD,GAAGA,CAACzC,IAAI,EAAEK,IAAI,EAAEE,KAAK,KACjF,IAAAmC,kCAAsB,EAACL,gBAAgB,EAAE9C,aAAa,EAAEQ,YAAY,CAACC,IAAI,CAAC,EAAEK,IAAI,EAAEE,KAAK,CAAC;EAE1F,MAAMoC,aAAa,GAAGjE,MAAM,CAACkE,MAAM,CAACX,WAAW,EAAE;IAC/CM,cAAc;IACdE;EACF,CAAC,CAAC;EAEF,OAAOE,aAAa;AACtB","ignoreList":[]}
|
|
@@ -3,36 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
const TYPE_VALUE = 'value';
|
|
8
|
-
const TYPE_ERROR = 'error';
|
|
6
|
+
exports.createIconSourceCache = createIconSourceCache;
|
|
9
7
|
function createIconSourceCache() {
|
|
10
8
|
const cache = new Map();
|
|
11
|
-
const setValue = (key, value) => cache.set(key,
|
|
12
|
-
|
|
13
|
-
data: value
|
|
14
|
-
});
|
|
15
|
-
const setError = (key, error) => cache.set(key, {
|
|
16
|
-
type: TYPE_ERROR,
|
|
17
|
-
data: error
|
|
18
|
-
});
|
|
19
|
-
const get = key => {
|
|
20
|
-
const value = cache.get(key);
|
|
21
|
-
if (!value) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
const {
|
|
25
|
-
type,
|
|
26
|
-
data
|
|
27
|
-
} = value;
|
|
28
|
-
if (type === TYPE_ERROR) {
|
|
29
|
-
throw data;
|
|
30
|
-
}
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
9
|
+
const setValue = (key, value) => cache.set(key, value);
|
|
10
|
+
const get = key => cache.get(key);
|
|
33
11
|
return {
|
|
34
12
|
setValue,
|
|
35
|
-
setError,
|
|
36
13
|
get
|
|
37
14
|
};
|
|
38
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createIconSourceCache","cache","Map","setValue","key","value","set","get"],"sourceRoot":"../../src","sources":["create-icon-source-cache.ts"],"mappings":";;;;;;AAEO,SAASA,qBAAqBA,CAAA,EAAG;EACtC,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAoB,CAAC;EAE1C,MAAMC,QAAQ,GAAGA,CAACC,GAAW,EAAEC,KAAgB,KAAKJ,KAAK,CAACK,GAAG,CAACF,GAAG,EAAEC,KAAK,CAAC;EAEzE,MAAME,GAAG,GAAIH,GAAW,IAAKH,KAAK,CAACM,GAAG,CAACH,GAAG,CAAC;EAE3C,OAAO;IAAED,QAAQ;IAAEI;EAAI,CAAC;AAC1B","ignoreList":[]}
|
|
@@ -10,6 +10,9 @@ exports.setDynamicLoadingErrorCallback = exports.setDynamicLoadingEnabled = expo
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
// this is a file:// uri on native, or an object with uri and display on web
|
|
12
12
|
|
|
13
|
+
// RenderToImageResult needs to be usable as the `source` prop for image,
|
|
14
|
+
// so it must stay compatible with ImageURISource type
|
|
15
|
+
|
|
13
16
|
// biome-ignore lint/suspicious/noExplicitAny: this is used internally with globalThis
|
|
14
17
|
function getIsDynamicLoadingSupported(globalObj) {
|
|
15
18
|
return globalObj?.expo && (_reactNative.Platform.OS === 'web' || typeof globalObj.expo.modules?.ExpoAsset?.downloadAsync === 'function') && typeof globalObj.expo.modules?.ExpoFontLoader?.getLoadedFonts === 'function' && typeof globalObj.expo.modules?.ExpoFontLoader?.loadAsync === 'function';
|
|
@@ -24,10 +27,13 @@ function assertExpoModulesPresent(globalObj) {
|
|
|
24
27
|
throw new Error('Dynamic font loading not supported. Upgrade to latest expo and expo-font.');
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
// Detection of Expo modules is deferred to first use so that import order
|
|
32
|
+
// doesn't matter. By the time a component renders, all imports (including Expo)
|
|
33
|
+
// have been evaluated and globalThis.expo is available.
|
|
34
|
+
|
|
35
|
+
let dynamicFontLoadingOverride = null;
|
|
36
|
+
const isDynamicLoadingSupported = () => getIsDynamicLoadingSupported(globalThis);
|
|
31
37
|
|
|
32
38
|
/**
|
|
33
39
|
* Set whether dynamic loading of fonts is enabled.
|
|
@@ -39,14 +45,15 @@ const isDynamicLoadingSupported = () => hasNecessaryExpoFeatures;
|
|
|
39
45
|
* */
|
|
40
46
|
exports.isDynamicLoadingSupported = isDynamicLoadingSupported;
|
|
41
47
|
const setDynamicLoadingEnabled = value => {
|
|
42
|
-
if (!
|
|
48
|
+
if (!getIsDynamicLoadingSupported(globalThis)) {
|
|
43
49
|
if (process.env.NODE_ENV !== 'production' && !!value) {
|
|
50
|
+
const hasNecessaryExpoModules = (_reactNative.Platform.OS === 'web' || !!globalThis.expo?.modules?.ExpoAsset) && !!globalThis.expo?.modules?.ExpoFontLoader;
|
|
44
51
|
const message = hasNecessaryExpoModules ? 'Expo is installed, but does not support dynamic font loading. Make sure to use Expo SDK 54 or newer.' : 'Necessary Expo modules not found. Dynamic font loading is not available when necessary Expo modules are not present.';
|
|
45
52
|
console.error(message); // eslint-disable-line no-console
|
|
46
53
|
}
|
|
47
54
|
return false;
|
|
48
55
|
}
|
|
49
|
-
|
|
56
|
+
dynamicFontLoadingOverride = !!value;
|
|
50
57
|
return true;
|
|
51
58
|
};
|
|
52
59
|
|
|
@@ -54,7 +61,7 @@ const setDynamicLoadingEnabled = value => {
|
|
|
54
61
|
* Whether dynamic loading of fonts is enabled.
|
|
55
62
|
* */
|
|
56
63
|
exports.setDynamicLoadingEnabled = setDynamicLoadingEnabled;
|
|
57
|
-
const isDynamicLoadingEnabled = () =>
|
|
64
|
+
const isDynamicLoadingEnabled = () => dynamicFontLoadingOverride ?? getIsDynamicLoadingSupported(globalThis);
|
|
58
65
|
exports.isDynamicLoadingEnabled = isDynamicLoadingEnabled;
|
|
59
66
|
let dynamicLoadingErrorCallback;
|
|
60
67
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","getIsDynamicLoadingSupported","globalObj","expo","Platform","OS","modules","ExpoAsset","downloadAsync","ExpoFontLoader","getLoadedFonts","loadAsync","getIsRenderToImageSupported","ExpoFontUtils","renderToImageAsync","assertExpoModulesPresent","Error","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","getIsDynamicLoadingSupported","globalObj","expo","Platform","OS","modules","ExpoAsset","downloadAsync","ExpoFontLoader","getLoadedFonts","loadAsync","getIsRenderToImageSupported","ExpoFontUtils","renderToImageAsync","assertExpoModulesPresent","Error","dynamicFontLoadingOverride","isDynamicLoadingSupported","globalThis","exports","setDynamicLoadingEnabled","value","process","env","NODE_ENV","hasNecessaryExpoModules","message","console","error","isDynamicLoadingEnabled","dynamicLoadingErrorCallback","setDynamicLoadingErrorCallback","callback","getErrorCallback"],"sourceRoot":"../../../src","sources":["dynamicLoading/dynamic-loading-setting.ts"],"mappings":";;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAUA;;AAUA;AACA;;AAoDA;AACA,SAASC,4BAA4BA,CAACC,SAAc,EAElD;EACA,OACEA,SAAS,EAAEC,IAAI,KACdC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAI,OAAOH,SAAS,CAACC,IAAI,CAACG,OAAO,EAAEC,SAAS,EAAEC,aAAa,KAAK,UAAU,CAAC,IACjG,OAAON,SAAS,CAACC,IAAI,CAACG,OAAO,EAAEG,cAAc,EAAEC,cAAc,KAAK,UAAU,IAC5E,OAAOR,SAAS,CAACC,IAAI,CAACG,OAAO,EAAEG,cAAc,EAAEE,SAAS,KAAK,UAAU;A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,0BAA0B,IAAIhB,4BAA4B,CAACkB,UAAU,CAAC;AAACC,OAAA,CAAAU,uBAAA,GAAAA,uBAAA;AAIzE,IAAIC,2BAAsD;;AAE1D;AACA;AACA;AACO,MAAMC,8BAA8B,GAAIC,QAAuB,IAAK;EACzEF,2BAA2B,GAAGE,QAAQ;AACxC,CAAC;AAACb,OAAA,CAAAY,8BAAA,GAAAA,8BAAA;AAEK,MAAME,gBAAgB,GAAGA,CAAA,KAAMH,2BAA2B;AAACX,OAAA,CAAAc,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -27,17 +27,20 @@ const ensureGetImageAvailable = () => {
|
|
|
27
27
|
ExpoFontUtils
|
|
28
28
|
} = globalRef.expo.modules;
|
|
29
29
|
return {
|
|
30
|
-
getImageForFont: async (fontReference, glyph, size, color) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
getImageForFont: async (fontReference, glyph, size, color) => {
|
|
31
|
+
const result = await ExpoFontUtils.renderToImageAsync(glyph, {
|
|
32
|
+
fontFamily: fontReference,
|
|
33
|
+
size,
|
|
34
|
+
color
|
|
35
|
+
});
|
|
36
|
+
return result.uri;
|
|
37
|
+
},
|
|
35
38
|
getImageForFontSync: () => {
|
|
36
39
|
throw new Error('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.');
|
|
37
40
|
}
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
|
-
throw new Error('Error in getImageSource / getImageSourceSync: You need to either (1) install `@react-native-vector-icons/get-image` or (2) use Expo SDK
|
|
43
|
+
throw new Error('Error in getImageSource / getImageSourceSync: You need to either (1) install `@react-native-vector-icons/get-image` or (2) use Expo SDK 54+ (Expo dev client or Expo Go). Check your setup and rebuild the app.');
|
|
41
44
|
};
|
|
42
45
|
exports.ensureGetImageAvailable = ensureGetImageAvailable;
|
|
43
46
|
//# sourceMappingURL=get-image-library.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dynamicLoadingSetting","require","NativeIconAPI","globalRef","globalThis","hasExpoRenderToImage","getIsRenderToImageSupported","ensureGetImageAvailable","ensureNativeModuleAvailable","ExpoFontUtils","expo","modules","getImageForFont","fontReference","glyph","size","color","renderToImageAsync","fontFamily","getImageForFontSync","Error","exports"],"sourceRoot":"../../src","sources":["get-image-library.ts"],"mappings":";;;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAEA;AACA,IAAIC,aAA2E,GAAG,IAAI;AAEtF,IAAI;EACF;EACAA,aAAa,GAAGD,OAAO,CAAC,sCAAsC,CAAC;AACjE,CAAC,CAAC,MAAM;EACN;EACA;EACA;AAAA;AAGF,MAAME,SAAS,GAAGC,UAAU;AAC5B,MAAMC,oBAAoB,GAAG,IAAAC,kDAA2B,EAACH,SAAS,CAAC;AAE5D,MAAMI,uBAAuB,GAAGA,CAAA,KAAM;EAC3C,IAAIL,aAAa,EAAE;IACjBA,aAAa,CAACM,2BAA2B,CAAC,CAAC;IAC3C,OAAON,aAAa;EACtB;EACA,IAAIG,oBAAoB,EAAE;IACxB,MAAM;MAAEI;IAAc,CAAC,GAAGN,SAAS,CAACO,IAAI,CAACC,OAAO;IAChD,OAAO;MACLC,eAAe,EAAE,MAAAA,CAAOC,aAAqB,EAAEC,KAAa,EAAEC,IAAY,EAAEC,KAAa,
|
|
1
|
+
{"version":3,"names":["_dynamicLoadingSetting","require","NativeIconAPI","globalRef","globalThis","hasExpoRenderToImage","getIsRenderToImageSupported","ensureGetImageAvailable","ensureNativeModuleAvailable","ExpoFontUtils","expo","modules","getImageForFont","fontReference","glyph","size","color","result","renderToImageAsync","fontFamily","uri","getImageForFontSync","Error","exports"],"sourceRoot":"../../src","sources":["get-image-library.ts"],"mappings":";;;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAEA;AACA,IAAIC,aAA2E,GAAG,IAAI;AAEtF,IAAI;EACF;EACAA,aAAa,GAAGD,OAAO,CAAC,sCAAsC,CAAC;AACjE,CAAC,CAAC,MAAM;EACN;EACA;EACA;AAAA;AAGF,MAAME,SAAS,GAAGC,UAAU;AAC5B,MAAMC,oBAAoB,GAAG,IAAAC,kDAA2B,EAACH,SAAS,CAAC;AAE5D,MAAMI,uBAAuB,GAAGA,CAAA,KAAM;EAC3C,IAAIL,aAAa,EAAE;IACjBA,aAAa,CAACM,2BAA2B,CAAC,CAAC;IAC3C,OAAON,aAAa;EACtB;EACA,IAAIG,oBAAoB,EAAE;IACxB,MAAM;MAAEI;IAAc,CAAC,GAAGN,SAAS,CAACO,IAAI,CAACC,OAAO;IAChD,OAAO;MACLC,eAAe,EAAE,MAAAA,CAAOC,aAAqB,EAAEC,KAAa,EAAEC,IAAY,EAAEC,KAAa,KAAK;QAC5F,MAAMC,MAAM,GAAG,MAAMR,aAAa,CAACS,kBAAkB,CAACJ,KAAK,EAAE;UAC3DK,UAAU,EAAEN,aAAa;UACzBE,IAAI;UACJC;QACF,CAAC,CAAC;QACF,OAAOC,MAAM,CAACG,GAAG;MACnB,CAAC;MACDC,mBAAmB,EAAEA,CAAA,KAAM;QACzB,MAAM,IAAIC,KAAK,CACb,2OACF,CAAC;MACH;IACF,CAAC;EACH;EACA,MAAM,IAAIA,KAAK,CACb,iNACF,CAAC;AACH,CAAC;AAACC,OAAA,CAAAhB,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
|
@@ -13,22 +13,16 @@ const getImageSourceSync = (imageSourceCache, fontReference, glyph, size = _defa
|
|
|
13
13
|
const cacheKey = `${glyph}:${size}:${String(processedColor)}`;
|
|
14
14
|
const maybeCachedValue = imageSourceCache.get(cacheKey);
|
|
15
15
|
if (maybeCachedValue !== undefined) {
|
|
16
|
-
// FIXME: Should this check if it's an error and throw it again?
|
|
17
16
|
return maybeCachedValue;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return value;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
imageSourceCache.setError(cacheKey, error);
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
18
|
+
const imagePath = NativeIconAPI.getImageForFontSync(fontReference, glyph, size, processedColor // FIXME what if a non existent colour was passed in?,
|
|
19
|
+
);
|
|
20
|
+
const value = {
|
|
21
|
+
uri: imagePath,
|
|
22
|
+
scale: _reactNative.PixelRatio.get()
|
|
23
|
+
};
|
|
24
|
+
imageSourceCache.setValue(cacheKey, value);
|
|
25
|
+
return value;
|
|
32
26
|
};
|
|
33
27
|
exports.getImageSourceSync = getImageSourceSync;
|
|
34
28
|
const getImageSource = async (imageSourceCache, fontReference, glyph, size = _defaults.DEFAULT_ICON_SIZE, color = _defaults.DEFAULT_ICON_COLOR) => {
|
|
@@ -37,22 +31,15 @@ const getImageSource = async (imageSourceCache, fontReference, glyph, size = _de
|
|
|
37
31
|
const cacheKey = `${glyph}:${size}:${String(processedColor)}`;
|
|
38
32
|
const maybeCachedValue = imageSourceCache.get(cacheKey);
|
|
39
33
|
if (maybeCachedValue !== undefined) {
|
|
40
|
-
// FIXME: Should this check if it's an error and throw it again?
|
|
41
34
|
return maybeCachedValue;
|
|
42
35
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
imageSourceCache.setValue(cacheKey, value);
|
|
51
|
-
return value;
|
|
52
|
-
} catch (error) {
|
|
53
|
-
imageSourceCache.setError(cacheKey, error);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
36
|
+
const imagePath = await NativeIconAPI.getImageForFont(fontReference, glyph, size, processedColor);
|
|
37
|
+
const value = {
|
|
38
|
+
uri: imagePath,
|
|
39
|
+
scale: _reactNative.PixelRatio.get()
|
|
40
|
+
};
|
|
41
|
+
imageSourceCache.setValue(cacheKey, value);
|
|
42
|
+
return value;
|
|
56
43
|
};
|
|
57
44
|
exports.getImageSource = getImageSource;
|
|
58
45
|
//# sourceMappingURL=get-image-source.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_defaults","_getImageLibrary","getImageSourceSync","imageSourceCache","fontReference","glyph","size","DEFAULT_ICON_SIZE","color","DEFAULT_ICON_COLOR","NativeIconAPI","ensureGetImageAvailable","processedColor","processColor","cacheKey","String","maybeCachedValue","get","undefined","imagePath","getImageForFontSync","value","uri","scale","PixelRatio","setValue","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_defaults","_getImageLibrary","getImageSourceSync","imageSourceCache","fontReference","glyph","size","DEFAULT_ICON_SIZE","color","DEFAULT_ICON_COLOR","NativeIconAPI","ensureGetImageAvailable","processedColor","processColor","cacheKey","String","maybeCachedValue","get","undefined","imagePath","getImageForFontSync","value","uri","scale","PixelRatio","setValue","exports","getImageSource","getImageForFont"],"sourceRoot":"../../src","sources":["get-image-source.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAGA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAEO,MAAMG,kBAAkB,GAAGA,CAChCC,gBAA0D,EAC1DC,aAAqB,EACrBC,KAAa,EACbC,IAAI,GAAGC,2BAAiB,EACxBC,KAAyB,GAAGC,4BAAkB,KAC3C;EACH,MAAMC,aAAa,GAAG,IAAAC,wCAAuB,EAAC,CAAC;EAE/C,MAAMC,cAAc,GAAG,IAAAC,yBAAY,EAACL,KAAK,CAAC;EAC1C,MAAMM,QAAQ,GAAG,GAAGT,KAAK,IAAIC,IAAI,IAAIS,MAAM,CAACH,cAAc,CAAC,EAAE;EAE7D,MAAMI,gBAAgB,GAAGb,gBAAgB,CAACc,GAAG,CAACH,QAAQ,CAAC;EACvD,IAAIE,gBAAgB,KAAKE,SAAS,EAAE;IAClC,OAAOF,gBAAgB;EACzB;EAEA,MAAMG,SAAS,GAAGT,a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ardRef, useEffect } from 'react';
|
|
5
5
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
6
6
|
import { Platform, Text } from 'react-native';
|
|
7
|
-
import createIconSourceCache from "./create-icon-source-cache.js";
|
|
7
|
+
import { createIconSourceCache } from "./create-icon-source-cache.js";
|
|
8
8
|
import { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from "./defaults.js";
|
|
9
9
|
import { dynamicLoader } from "./dynamicLoading/dynamic-font-loading.js";
|
|
10
10
|
import { isDynamicLoadingEnabled } from "./dynamicLoading/dynamic-loading-setting.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","forwardRef","useEffect","Platform","Text","createIconSourceCache","DEFAULT_ICON_COLOR","DEFAULT_ICON_SIZE","dynamicLoader","isDynamicLoadingEnabled","getImageSource","getImageSourceImpl","getImageSourceSync","getImageSourceSyncImpl","jsxs","_jsxs","jsx","_jsx","createIconSet","glyphMap","postScriptNameOrOptions","fontFileNameParam","fontStyleParam","postScriptName","fontFileName","fontStyle","fontBasename","replace","fontReference","select","windows","android","default","styleOverrides","fontFamily","fontWeight","resolveGlyph","name","glyph","String","fromCodePoint","Icon","size","color","style","children","allowFontScaling","innerRef","props","isFontLoaded","setIsFontLoaded","useState","isLoaded","isMounted","fontSource","loadFontAsync","finally","styleDefaults","fontSize","newProps","ref","selectable","WrappedIcon","displayName","imageSourceCache","IconNamespace","Object","assign"],"sourceRoot":"../../src","sources":["create-icon-set.tsx"],"mappings":";;AAAA;AACA,OAAOA,KAAK,IAAIC,UAAU,EAAYC,SAAS,QAAQ,OAAO;AAC9D;AACA,SAASC,QAAQ,EAAEC,IAAI,QAAwC,cAAc;AAE7E,
|
|
1
|
+
{"version":3,"names":["React","forwardRef","useEffect","Platform","Text","createIconSourceCache","DEFAULT_ICON_COLOR","DEFAULT_ICON_SIZE","dynamicLoader","isDynamicLoadingEnabled","getImageSource","getImageSourceImpl","getImageSourceSync","getImageSourceSyncImpl","jsxs","_jsxs","jsx","_jsx","createIconSet","glyphMap","postScriptNameOrOptions","fontFileNameParam","fontStyleParam","postScriptName","fontFileName","fontStyle","fontBasename","replace","fontReference","select","windows","android","default","styleOverrides","fontFamily","fontWeight","resolveGlyph","name","glyph","String","fromCodePoint","Icon","size","color","style","children","allowFontScaling","innerRef","props","isFontLoaded","setIsFontLoaded","useState","isLoaded","isMounted","fontSource","loadFontAsync","finally","styleDefaults","fontSize","newProps","ref","selectable","WrappedIcon","displayName","imageSourceCache","IconNamespace","Object","assign"],"sourceRoot":"../../src","sources":["create-icon-set.tsx"],"mappings":";;AAAA;AACA,OAAOA,KAAK,IAAIC,UAAU,EAAYC,SAAS,QAAQ,OAAO;AAC9D;AACA,SAASC,QAAQ,EAAEC,IAAI,QAAwC,cAAc;AAE7E,SAASC,qBAAqB,QAAQ,+BAA4B;AAClE,SAASC,kBAAkB,EAAEC,iBAAiB,QAAQ,eAAY;AAClE,SAASC,aAAa,QAAQ,0CAAuC;AACrE,SAASC,uBAAuB,QAAQ,6CAA0C;AAElF,SAASC,cAAc,IAAIC,kBAAkB,EAAEC,kBAAkB,IAAIC,sBAAsB,QAAQ,uBAAoB;AAAC,SAAAC,IAAA,IAAAC,KAAA,EAAAC,GAAA,IAAAC,IAAA;AA6CxH,OAAO,SAASC,aAAaA,CAC3BC,QAAY,EACZC,uBAAsD,EACtDC,iBAA0B,EAC1BC,cAAmC,EAChB;EACnB,MAAM;IAAEC,cAAc;IAAEC,YAAY;IAAEC;EAAU,CAAC,GAC/C,OAAOL,uBAAuB,KAAK,QAAQ,GACvC;IACEG,cAAc,EAAEH,uBAAuB;IACvCI,YAAY,EAAEH,iBAAiB;IAC/BI,SAAS,EAAEH;EACb,CAAC,GACDF,uBAAuB;EAE7B,MAAMM,YAAY,GAAGF,YAAY,GAAGA,YAAY,CAACG,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,GAAGJ,cAAc;EAE7F,MAAMK,aAAa,GAAGzB,QAAQ,CAAC0B,MAAM,CAAC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CAACyB,IAAI,EAAEK,IAAI,EAAEC,KAAK,KACjF9B,sBAAsB,CAACmD,gBAAgB,EAAEpC,aAAa,EAAEQ,YAAY,CAACC,IAAI,CAAC,EAAEK,IAAI,EAAEC,KAAK,CAAC;EAE1F,MAAMsB,aAAa,GAAGC,MAAM,CAACC,MAAM,CAACL,WAAW,EAAE;IAC/CpD,cAAc;IACdE;EACF,CAAC,CAAC;EAEF,OAAOqD,aAAa;AACtB","ignoreList":[]}
|
|
@@ -1,34 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const TYPE_ERROR = 'error';
|
|
5
|
-
export default function createIconSourceCache() {
|
|
3
|
+
export function createIconSourceCache() {
|
|
6
4
|
const cache = new Map();
|
|
7
|
-
const setValue = (key, value) => cache.set(key,
|
|
8
|
-
|
|
9
|
-
data: value
|
|
10
|
-
});
|
|
11
|
-
const setError = (key, error) => cache.set(key, {
|
|
12
|
-
type: TYPE_ERROR,
|
|
13
|
-
data: error
|
|
14
|
-
});
|
|
15
|
-
const get = key => {
|
|
16
|
-
const value = cache.get(key);
|
|
17
|
-
if (!value) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
const {
|
|
21
|
-
type,
|
|
22
|
-
data
|
|
23
|
-
} = value;
|
|
24
|
-
if (type === TYPE_ERROR) {
|
|
25
|
-
throw data;
|
|
26
|
-
}
|
|
27
|
-
return data;
|
|
28
|
-
};
|
|
5
|
+
const setValue = (key, value) => cache.set(key, value);
|
|
6
|
+
const get = key => cache.get(key);
|
|
29
7
|
return {
|
|
30
8
|
setValue,
|
|
31
|
-
setError,
|
|
32
9
|
get
|
|
33
10
|
};
|
|
34
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createIconSourceCache","cache","Map","setValue","key","value","set","get"],"sourceRoot":"../../src","sources":["create-icon-source-cache.ts"],"mappings":";;AAEA,OAAO,SAASA,qBAAqBA,CAAA,EAAG;EACtC,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAoB,CAAC;EAE1C,MAAMC,QAAQ,GAAGA,CAACC,GAAW,EAAEC,KAAgB,KAAKJ,KAAK,CAACK,GAAG,CAACF,GAAG,EAAEC,KAAK,CAAC;EAEzE,MAAME,GAAG,GAAIH,GAAW,IAAKH,KAAK,CAACM,GAAG,CAACH,GAAG,CAAC;EAE3C,OAAO;IAAED,QAAQ;IAAEI;EAAI,CAAC;AAC1B","ignoreList":[]}
|
|
@@ -4,6 +4,9 @@ import { Platform } from 'react-native';
|
|
|
4
4
|
|
|
5
5
|
// this is a file:// uri on native, or an object with uri and display on web
|
|
6
6
|
|
|
7
|
+
// RenderToImageResult needs to be usable as the `source` prop for image,
|
|
8
|
+
// so it must stay compatible with ImageURISource type
|
|
9
|
+
|
|
7
10
|
// biome-ignore lint/suspicious/noExplicitAny: this is used internally with globalThis
|
|
8
11
|
function getIsDynamicLoadingSupported(globalObj) {
|
|
9
12
|
return globalObj?.expo && (Platform.OS === 'web' || typeof globalObj.expo.modules?.ExpoAsset?.downloadAsync === 'function') && typeof globalObj.expo.modules?.ExpoFontLoader?.getLoadedFonts === 'function' && typeof globalObj.expo.modules?.ExpoFontLoader?.loadAsync === 'function';
|
|
@@ -18,10 +21,13 @@ export function assertExpoModulesPresent(globalObj) {
|
|
|
18
21
|
throw new Error('Dynamic font loading not supported. Upgrade to latest expo and expo-font.');
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
// Detection of Expo modules is deferred to first use so that import order
|
|
26
|
+
// doesn't matter. By the time a component renders, all imports (including Expo)
|
|
27
|
+
// have been evaluated and globalThis.expo is available.
|
|
28
|
+
|
|
29
|
+
let dynamicFontLoadingOverride = null;
|
|
30
|
+
export const isDynamicLoadingSupported = () => getIsDynamicLoadingSupported(globalThis);
|
|
25
31
|
|
|
26
32
|
/**
|
|
27
33
|
* Set whether dynamic loading of fonts is enabled.
|
|
@@ -32,21 +38,22 @@ export const isDynamicLoadingSupported = () => hasNecessaryExpoFeatures;
|
|
|
32
38
|
* @returns `true` if dynamic loading of fonts was successfully set. `false` otherwise.
|
|
33
39
|
* */
|
|
34
40
|
export const setDynamicLoadingEnabled = value => {
|
|
35
|
-
if (!
|
|
41
|
+
if (!getIsDynamicLoadingSupported(globalThis)) {
|
|
36
42
|
if (process.env.NODE_ENV !== 'production' && !!value) {
|
|
43
|
+
const hasNecessaryExpoModules = (Platform.OS === 'web' || !!globalThis.expo?.modules?.ExpoAsset) && !!globalThis.expo?.modules?.ExpoFontLoader;
|
|
37
44
|
const message = hasNecessaryExpoModules ? 'Expo is installed, but does not support dynamic font loading. Make sure to use Expo SDK 54 or newer.' : 'Necessary Expo modules not found. Dynamic font loading is not available when necessary Expo modules are not present.';
|
|
38
45
|
console.error(message); // eslint-disable-line no-console
|
|
39
46
|
}
|
|
40
47
|
return false;
|
|
41
48
|
}
|
|
42
|
-
|
|
49
|
+
dynamicFontLoadingOverride = !!value;
|
|
43
50
|
return true;
|
|
44
51
|
};
|
|
45
52
|
|
|
46
53
|
/**
|
|
47
54
|
* Whether dynamic loading of fonts is enabled.
|
|
48
55
|
* */
|
|
49
|
-
export const isDynamicLoadingEnabled = () =>
|
|
56
|
+
export const isDynamicLoadingEnabled = () => dynamicFontLoadingOverride ?? getIsDynamicLoadingSupported(globalThis);
|
|
50
57
|
let dynamicLoadingErrorCallback;
|
|
51
58
|
|
|
52
59
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","getIsDynamicLoadingSupported","globalObj","expo","OS","modules","ExpoAsset","downloadAsync","ExpoFontLoader","getLoadedFonts","loadAsync","getIsRenderToImageSupported","ExpoFontUtils","renderToImageAsync","assertExpoModulesPresent","Error","
|
|
1
|
+
{"version":3,"names":["Platform","getIsDynamicLoadingSupported","globalObj","expo","OS","modules","ExpoAsset","downloadAsync","ExpoFontLoader","getLoadedFonts","loadAsync","getIsRenderToImageSupported","ExpoFontUtils","renderToImageAsync","assertExpoModulesPresent","Error","dynamicFontLoadingOverride","isDynamicLoadingSupported","globalThis","setDynamicLoadingEnabled","value","process","env","NODE_ENV","hasNecessaryExpoModules","message","console","error","isDynamicLoadingEnabled","dynamicLoadingErrorCallback","setDynamicLoadingErrorCallback","callback","getErrorCallback"],"sourceRoot":"../../../src","sources":["dynamicLoading/dynamic-loading-setting.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;;AAUvC;;AAUA;AACA;;AAoDA;AACA,SAASC,4BAA4BA,CAACC,SAAc,EAElD;EACA,OACEA,SAAS,EAAEC,IAAI,KACdH,QAAQ,CAACI,EAAE,KAAK,KAAK,IAAI,OAAOF,SAAS,CAACC,IAAI,CAACE,OAAO,EAAEC,SAAS,EAAEC,aAAa,KAAK,UAAU,CAAC,IACjG,OAAOL,SAAS,CAACC,IAAI,CAACE,OAAO,EAAEG,cAAc,EAAEC,cAAc,KAAK,UAAU,IAC5E,OAAOP,SAAS,CAACC,IAAI,CAACE,OAAO,EAAEG,cAAc,EAAEE,SAAS,KAAK,UAAU;AAE3E;;AAEA;AACA,OAAO,SAASC,2BAA2BA,CAACT,SAAc,EAMxD;EACA,OAAOA,SAAS,EAAEC,IAAI,IAAI,OAAOD,SAAS,CAACC,IAAI,CAACE,OAAO,EAAEO,aAAa,EAAEC,kBAAkB,KAAK,UAAU;AAC3G;AAEA,OAAO,SAASC,wBAAwBA,CAACZ,SAAkB,EAAiD;EAC1G,IAAI,CAACD,4BAA4B,CAACC,SAAS,CAAC,EAAE;IAC5C,MAAM,IAAIa,KAAK,CAAC,2EAA2E,CAAC;EAC9F;AACF;;AAEA;AACA;AACA;;AAEA,IAAIC,0BAA0C,GAAG,IAAI;AAErD,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAMhB,4BAA4B,CAACiB,UAAU,CAAC;;AAEvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,GAAIC,KAAc,IAAc;EACnE,IAAI,CAACnB,4BAA4B,CAACiB,UAAU,CAAC,EAAE;IAC7C,IAAIG,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAACH,KAAK,EAAE;MACpD,MAAMI,uBAAuB,GAC3B,CAACxB,QAAQ,CAACI,EAAE,KAAK,KAAK,IAAI,CAAC,CAACc,UAAU,CAACf,IAAI,EAAEE,OAAO,EAAEC,SAAS,KAAK,CAAC,CAACY,UAAU,CAACf,IAAI,EAAEE,OAAO,EAAEG,cAAc;MAChH,MAAMiB,OAAO,GAAGD,uBAAuB,GACnC,sGAAsG,GACtG,sHAAsH;MAC1HE,OAAO,CAACC,KAAK,CAACF,OAAO,CAAC,CAAC,CAAC;IAC1B;IACA,OAAO,KAAK;EACd;EAEAT,0BAA0B,GAAG,CAAC,CAACI,KAAK;EAEpC,OAAO,IAAI;AACb,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMQ,uBAAuB,GAAGA,CAAA,KACrCZ,0BAA0B,IAAIf,4BAA4B,CAACiB,UAAU,CAAC;AAIxE,IAAIW,2BAAsD;;AAE1D;AACA;AACA;AACA,OAAO,MAAMC,8BAA8B,GAAIC,QAAuB,IAAK;EACzEF,2BAA2B,GAAGE,QAAQ;AACxC,CAAC;AAED,OAAO,MAAMC,gBAAgB,GAAGA,CAAA,KAAMH,2BAA2B","ignoreList":[]}
|
|
@@ -24,16 +24,19 @@ export const ensureGetImageAvailable = () => {
|
|
|
24
24
|
ExpoFontUtils
|
|
25
25
|
} = globalRef.expo.modules;
|
|
26
26
|
return {
|
|
27
|
-
getImageForFont: async (fontReference, glyph, size, color) =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
getImageForFont: async (fontReference, glyph, size, color) => {
|
|
28
|
+
const result = await ExpoFontUtils.renderToImageAsync(glyph, {
|
|
29
|
+
fontFamily: fontReference,
|
|
30
|
+
size,
|
|
31
|
+
color
|
|
32
|
+
});
|
|
33
|
+
return result.uri;
|
|
34
|
+
},
|
|
32
35
|
getImageForFontSync: () => {
|
|
33
36
|
throw new Error('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.');
|
|
34
37
|
}
|
|
35
38
|
};
|
|
36
39
|
}
|
|
37
|
-
throw new Error('Error in getImageSource / getImageSourceSync: You need to either (1) install `@react-native-vector-icons/get-image` or (2) use Expo SDK
|
|
40
|
+
throw new Error('Error in getImageSource / getImageSourceSync: You need to either (1) install `@react-native-vector-icons/get-image` or (2) use Expo SDK 54+ (Expo dev client or Expo Go). Check your setup and rebuild the app.');
|
|
38
41
|
};
|
|
39
42
|
//# sourceMappingURL=get-image-library.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getIsRenderToImageSupported","NativeIconAPI","require","globalRef","globalThis","hasExpoRenderToImage","ensureGetImageAvailable","ensureNativeModuleAvailable","ExpoFontUtils","expo","modules","getImageForFont","fontReference","glyph","size","color","renderToImageAsync","fontFamily","getImageForFontSync","Error"],"sourceRoot":"../../src","sources":["get-image-library.ts"],"mappings":";;AAAA,SAASA,2BAA2B,QAAQ,6CAA0C;;AAEtF;AACA,IAAIC,aAA2E,GAAG,IAAI;AAEtF,IAAI;EACF;EACAA,aAAa,GAAGC,OAAO,CAAC,sCAAsC,CAAC;AACjE,CAAC,CAAC,MAAM;EACN;EACA;EACA;AAAA;AAGF,MAAMC,SAAS,GAAGC,UAAU;AAC5B,MAAMC,oBAAoB,GAAGL,2BAA2B,CAACG,SAAS,CAAC;AAEnE,OAAO,MAAMG,uBAAuB,GAAGA,CAAA,KAAM;EAC3C,IAAIL,aAAa,EAAE;IACjBA,aAAa,CAACM,2BAA2B,CAAC,CAAC;IAC3C,OAAON,aAAa;EACtB;EACA,IAAII,oBAAoB,EAAE;IACxB,MAAM;MAAEG;IAAc,CAAC,GAAGL,SAAS,CAACM,IAAI,CAACC,OAAO;IAChD,OAAO;MACLC,eAAe,EAAE,MAAAA,CAAOC,aAAqB,EAAEC,KAAa,EAAEC,IAAY,EAAEC,KAAa,
|
|
1
|
+
{"version":3,"names":["getIsRenderToImageSupported","NativeIconAPI","require","globalRef","globalThis","hasExpoRenderToImage","ensureGetImageAvailable","ensureNativeModuleAvailable","ExpoFontUtils","expo","modules","getImageForFont","fontReference","glyph","size","color","result","renderToImageAsync","fontFamily","uri","getImageForFontSync","Error"],"sourceRoot":"../../src","sources":["get-image-library.ts"],"mappings":";;AAAA,SAASA,2BAA2B,QAAQ,6CAA0C;;AAEtF;AACA,IAAIC,aAA2E,GAAG,IAAI;AAEtF,IAAI;EACF;EACAA,aAAa,GAAGC,OAAO,CAAC,sCAAsC,CAAC;AACjE,CAAC,CAAC,MAAM;EACN;EACA;EACA;AAAA;AAGF,MAAMC,SAAS,GAAGC,UAAU;AAC5B,MAAMC,oBAAoB,GAAGL,2BAA2B,CAACG,SAAS,CAAC;AAEnE,OAAO,MAAMG,uBAAuB,GAAGA,CAAA,KAAM;EAC3C,IAAIL,aAAa,EAAE;IACjBA,aAAa,CAACM,2BAA2B,CAAC,CAAC;IAC3C,OAAON,aAAa;EACtB;EACA,IAAII,oBAAoB,EAAE;IACxB,MAAM;MAAEG;IAAc,CAAC,GAAGL,SAAS,CAACM,IAAI,CAACC,OAAO;IAChD,OAAO;MACLC,eAAe,EAAE,MAAAA,CAAOC,aAAqB,EAAEC,KAAa,EAAEC,IAAY,EAAEC,KAAa,KAAK;QAC5F,MAAMC,MAAM,GAAG,MAAMR,aAAa,CAACS,kBAAkB,CAACJ,KAAK,EAAE;UAC3DK,UAAU,EAAEN,aAAa;UACzBE,IAAI;UACJC;QACF,CAAC,CAAC;QACF,OAAOC,MAAM,CAACG,GAAG;MACnB,CAAC;MACDC,mBAAmB,EAAEA,CAAA,KAAM;QACzB,MAAM,IAAIC,KAAK,CACb,2OACF,CAAC;MACH;IACF,CAAC;EACH;EACA,MAAM,IAAIA,KAAK,CACb,iNACF,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -9,22 +9,16 @@ export const getImageSourceSync = (imageSourceCache, fontReference, glyph, size
|
|
|
9
9
|
const cacheKey = `${glyph}:${size}:${String(processedColor)}`;
|
|
10
10
|
const maybeCachedValue = imageSourceCache.get(cacheKey);
|
|
11
11
|
if (maybeCachedValue !== undefined) {
|
|
12
|
-
// FIXME: Should this check if it's an error and throw it again?
|
|
13
12
|
return maybeCachedValue;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return value;
|
|
24
|
-
} catch (error) {
|
|
25
|
-
imageSourceCache.setError(cacheKey, error);
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
14
|
+
const imagePath = NativeIconAPI.getImageForFontSync(fontReference, glyph, size, processedColor // FIXME what if a non existent colour was passed in?,
|
|
15
|
+
);
|
|
16
|
+
const value = {
|
|
17
|
+
uri: imagePath,
|
|
18
|
+
scale: PixelRatio.get()
|
|
19
|
+
};
|
|
20
|
+
imageSourceCache.setValue(cacheKey, value);
|
|
21
|
+
return value;
|
|
28
22
|
};
|
|
29
23
|
export const getImageSource = async (imageSourceCache, fontReference, glyph, size = DEFAULT_ICON_SIZE, color = DEFAULT_ICON_COLOR) => {
|
|
30
24
|
const NativeIconAPI = ensureGetImageAvailable();
|
|
@@ -32,21 +26,14 @@ export const getImageSource = async (imageSourceCache, fontReference, glyph, siz
|
|
|
32
26
|
const cacheKey = `${glyph}:${size}:${String(processedColor)}`;
|
|
33
27
|
const maybeCachedValue = imageSourceCache.get(cacheKey);
|
|
34
28
|
if (maybeCachedValue !== undefined) {
|
|
35
|
-
// FIXME: Should this check if it's an error and throw it again?
|
|
36
29
|
return maybeCachedValue;
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
imageSourceCache.setValue(cacheKey, value);
|
|
46
|
-
return value;
|
|
47
|
-
} catch (error) {
|
|
48
|
-
imageSourceCache.setError(cacheKey, error);
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
31
|
+
const imagePath = await NativeIconAPI.getImageForFont(fontReference, glyph, size, processedColor);
|
|
32
|
+
const value = {
|
|
33
|
+
uri: imagePath,
|
|
34
|
+
scale: PixelRatio.get()
|
|
35
|
+
};
|
|
36
|
+
imageSourceCache.setValue(cacheKey, value);
|
|
37
|
+
return value;
|
|
51
38
|
};
|
|
52
39
|
//# sourceMappingURL=get-image-source.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PixelRatio","processColor","DEFAULT_ICON_COLOR","DEFAULT_ICON_SIZE","ensureGetImageAvailable","getImageSourceSync","imageSourceCache","fontReference","glyph","size","color","NativeIconAPI","processedColor","cacheKey","String","maybeCachedValue","get","undefined","imagePath","getImageForFontSync","value","uri","scale","setValue","
|
|
1
|
+
{"version":3,"names":["PixelRatio","processColor","DEFAULT_ICON_COLOR","DEFAULT_ICON_SIZE","ensureGetImageAvailable","getImageSourceSync","imageSourceCache","fontReference","glyph","size","color","NativeIconAPI","processedColor","cacheKey","String","maybeCachedValue","get","undefined","imagePath","getImageForFontSync","value","uri","scale","setValue","getImageSource","getImageForFont"],"sourceRoot":"../../src","sources":["get-image-source.ts"],"mappings":";;AACA,SAASA,UAAU,EAAEC,YAAY,QAAQ,cAAc;AAGvD,SAASC,kBAAkB,EAAEC,iBAAiB,QAAQ,eAAY;AAClE,SAASC,uBAAuB,QAAQ,wBAAqB;AAE7D,OAAO,MAAMC,kBAAkB,GAAGA,CAChCC,gBAA0D,EAC1DC,aAAqB,EACrBC,KAAa,EACbC,IAAI,GAAGN,iBAAiB,EACxBO,KAAyB,GAAGR,kBAAkB,KAC3C;EACH,MAAM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C3G,MAAMQ,KAAK,GAAG;IAAEC,GAAG,EAAEH,SAAS;IAAEI,KAAK,EAAEtB,UAAU,CAACgB,GAAG,CAAC;EAAE,CAAC;EACzDV,gBAAgB,CAACiB,QAAQ,CAACV,QAAQ,EAAEO,KAAK,CAAC;EAC1C,OAAOA,KAAK;AACd,CAAC","ignoreList":[]}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
declare const TYPE_VALUE = "value";
|
|
2
|
-
declare const TYPE_ERROR = "error";
|
|
3
1
|
type ValueData = {
|
|
4
2
|
uri: string;
|
|
5
3
|
scale: number;
|
|
6
4
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
data: ValueData;
|
|
10
|
-
} | {
|
|
11
|
-
type: typeof TYPE_ERROR;
|
|
12
|
-
data: Error;
|
|
13
|
-
};
|
|
14
|
-
export default function createIconSourceCache(): {
|
|
15
|
-
setValue: (key: string, value: ValueData) => Map<string, Value>;
|
|
16
|
-
setError: (key: string, error: Error) => Map<string, Value>;
|
|
5
|
+
export declare function createIconSourceCache(): {
|
|
6
|
+
setValue: (key: string, value: ValueData) => Map<string, ValueData>;
|
|
17
7
|
get: (key: string) => ValueData | undefined;
|
|
18
8
|
};
|
|
19
9
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-icon-source-cache.d.ts","sourceRoot":"","sources":["../../../../src/create-icon-source-cache.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"create-icon-source-cache.d.ts","sourceRoot":"","sources":["../../../../src/create-icon-source-cache.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,wBAAgB,qBAAqB;oBAGZ,MAAM,SAAS,SAAS;eAE7B,MAAM;EAGzB"}
|
|
@@ -10,12 +10,30 @@ type ExpoFontLoaderModule = {
|
|
|
10
10
|
getLoadedFonts: () => string[];
|
|
11
11
|
loadAsync: (fontFamilyAlias: string, asset: LoadAsyncAsset) => Promise<void>;
|
|
12
12
|
};
|
|
13
|
+
type RenderToImageResult = {
|
|
14
|
+
/**
|
|
15
|
+
* The file uri to the image.
|
|
16
|
+
*/
|
|
17
|
+
uri: string;
|
|
18
|
+
/**
|
|
19
|
+
* Image width in dp.
|
|
20
|
+
*/
|
|
21
|
+
width: number;
|
|
22
|
+
/**
|
|
23
|
+
* Image height in dp.
|
|
24
|
+
*/
|
|
25
|
+
height: number;
|
|
26
|
+
/**
|
|
27
|
+
* Scale factor of the image. Multiply the dp dimensions by this value to get the dimensions in pixels.
|
|
28
|
+
* */
|
|
29
|
+
scale: number;
|
|
30
|
+
};
|
|
13
31
|
type ExpoFontUtilsModule = {
|
|
14
32
|
renderToImageAsync: (glyph: string, options: {
|
|
15
33
|
fontFamily?: string;
|
|
16
34
|
size?: number;
|
|
17
35
|
color?: number;
|
|
18
|
-
}) => Promise<
|
|
36
|
+
}) => Promise<RenderToImageResult>;
|
|
19
37
|
};
|
|
20
38
|
declare global {
|
|
21
39
|
interface ExpoGlobal {
|
|
@@ -1 +1 @@
|
|
|
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,CA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BAA8B,GAAI,UAAU,aAAa,SAErE,CAAC;AAEF,eAAO,MAAM,gBAAgB,iCAAoC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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;;
|
|
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;;CAkB9F,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TextStyle } from 'react-native';
|
|
2
|
-
import type createIconSourceCache from './create-icon-source-cache';
|
|
2
|
+
import type { createIconSourceCache } from './create-icon-source-cache';
|
|
3
3
|
export declare const getImageSourceSync: (imageSourceCache: ReturnType<typeof createIconSourceCache>, fontReference: string, glyph: string, size?: number, color?: TextStyle["color"]) => {
|
|
4
4
|
uri: string;
|
|
5
5
|
scale: number;
|
|
@@ -1 +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;
|
|
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,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAIxE,eAAO,MAAM,kBAAkB,GAC7B,kBAAkB,UAAU,CAAC,OAAO,qBAAqB,CAAC,EAC1D,eAAe,MAAM,EACrB,OAAO,MAAM,EACb,aAAwB,EACxB,QAAO,SAAS,CAAC,OAAO,CAAsB;;;CAqB/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;;;EAgB/C,CAAC"}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
declare const TYPE_VALUE = "value";
|
|
2
|
-
declare const TYPE_ERROR = "error";
|
|
3
1
|
type ValueData = {
|
|
4
2
|
uri: string;
|
|
5
3
|
scale: number;
|
|
6
4
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
data: ValueData;
|
|
10
|
-
} | {
|
|
11
|
-
type: typeof TYPE_ERROR;
|
|
12
|
-
data: Error;
|
|
13
|
-
};
|
|
14
|
-
export default function createIconSourceCache(): {
|
|
15
|
-
setValue: (key: string, value: ValueData) => Map<string, Value>;
|
|
16
|
-
setError: (key: string, error: Error) => Map<string, Value>;
|
|
5
|
+
export declare function createIconSourceCache(): {
|
|
6
|
+
setValue: (key: string, value: ValueData) => Map<string, ValueData>;
|
|
17
7
|
get: (key: string) => ValueData | undefined;
|
|
18
8
|
};
|
|
19
9
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-icon-source-cache.d.ts","sourceRoot":"","sources":["../../../../src/create-icon-source-cache.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"create-icon-source-cache.d.ts","sourceRoot":"","sources":["../../../../src/create-icon-source-cache.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhD,wBAAgB,qBAAqB;oBAGZ,MAAM,SAAS,SAAS;eAE7B,MAAM;EAGzB"}
|
|
@@ -10,12 +10,30 @@ type ExpoFontLoaderModule = {
|
|
|
10
10
|
getLoadedFonts: () => string[];
|
|
11
11
|
loadAsync: (fontFamilyAlias: string, asset: LoadAsyncAsset) => Promise<void>;
|
|
12
12
|
};
|
|
13
|
+
type RenderToImageResult = {
|
|
14
|
+
/**
|
|
15
|
+
* The file uri to the image.
|
|
16
|
+
*/
|
|
17
|
+
uri: string;
|
|
18
|
+
/**
|
|
19
|
+
* Image width in dp.
|
|
20
|
+
*/
|
|
21
|
+
width: number;
|
|
22
|
+
/**
|
|
23
|
+
* Image height in dp.
|
|
24
|
+
*/
|
|
25
|
+
height: number;
|
|
26
|
+
/**
|
|
27
|
+
* Scale factor of the image. Multiply the dp dimensions by this value to get the dimensions in pixels.
|
|
28
|
+
* */
|
|
29
|
+
scale: number;
|
|
30
|
+
};
|
|
13
31
|
type ExpoFontUtilsModule = {
|
|
14
32
|
renderToImageAsync: (glyph: string, options: {
|
|
15
33
|
fontFamily?: string;
|
|
16
34
|
size?: number;
|
|
17
35
|
color?: number;
|
|
18
|
-
}) => Promise<
|
|
36
|
+
}) => Promise<RenderToImageResult>;
|
|
19
37
|
};
|
|
20
38
|
declare global {
|
|
21
39
|
interface ExpoGlobal {
|
|
@@ -1 +1 @@
|
|
|
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,oBAA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AAK,IAAI,CAAC;AAIlG;;KAEK;AACL,eAAO,MAAM,8BAA8B,GAAI,UAAU,aAAa,SAErE,CAAC;AAEF,eAAO,MAAM,gBAAgB,iCAAoC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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;;
|
|
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;;CAkB9F,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TextStyle } from 'react-native';
|
|
2
|
-
import type createIconSourceCache from './create-icon-source-cache';
|
|
2
|
+
import type { createIconSourceCache } from './create-icon-source-cache';
|
|
3
3
|
export declare const getImageSourceSync: (imageSourceCache: ReturnType<typeof createIconSourceCache>, fontReference: string, glyph: string, size?: number, color?: TextStyle["color"]) => {
|
|
4
4
|
uri: string;
|
|
5
5
|
scale: number;
|
|
@@ -1 +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;
|
|
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,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAIxE,eAAO,MAAM,kBAAkB,GAC7B,kBAAkB,UAAU,CAAC,OAAO,qBAAqB,CAAC,EAC1D,eAAe,MAAM,EACrB,OAAO,MAAM,EACb,aAAwB,EACxB,QAAO,SAAS,CAAC,OAAO,CAAsB;;;CAqB/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;;;EAgB/C,CAAC"}
|
package/package.json
CHANGED
package/src/create-icon-set.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import React, { forwardRef, type Ref, useEffect } from 'react';
|
|
|
3
3
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
4
|
import { Platform, Text, type TextProps, type TextStyle } from 'react-native';
|
|
5
5
|
|
|
6
|
-
import createIconSourceCache from './create-icon-source-cache';
|
|
6
|
+
import { createIconSourceCache } from './create-icon-source-cache';
|
|
7
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';
|
|
@@ -1,29 +1,11 @@
|
|
|
1
|
-
const TYPE_VALUE = 'value';
|
|
2
|
-
const TYPE_ERROR = 'error';
|
|
3
|
-
|
|
4
1
|
type ValueData = { uri: string; scale: number };
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export default function createIconSourceCache() {
|
|
9
|
-
const cache = new Map<string, Value>();
|
|
10
|
-
|
|
11
|
-
const setValue = (key: string, value: ValueData) => cache.set(key, { type: TYPE_VALUE, data: value });
|
|
12
|
-
|
|
13
|
-
const setError = (key: string, error: Error) => cache.set(key, { type: TYPE_ERROR, data: error });
|
|
3
|
+
export function createIconSourceCache() {
|
|
4
|
+
const cache = new Map<string, ValueData>();
|
|
14
5
|
|
|
15
|
-
const
|
|
16
|
-
const value = cache.get(key);
|
|
17
|
-
if (!value) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
6
|
+
const setValue = (key: string, value: ValueData) => cache.set(key, value);
|
|
20
7
|
|
|
21
|
-
|
|
22
|
-
if (type === TYPE_ERROR) {
|
|
23
|
-
throw data;
|
|
24
|
-
}
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
8
|
+
const get = (key: string) => cache.get(key);
|
|
27
9
|
|
|
28
|
-
return { setValue,
|
|
10
|
+
return { setValue, get };
|
|
29
11
|
}
|
|
@@ -18,6 +18,28 @@ type ExpoFontLoaderModule = {
|
|
|
18
18
|
loadAsync: (fontFamilyAlias: string, asset: LoadAsyncAsset) => Promise<void>;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
// RenderToImageResult needs to be usable as the `source` prop for image,
|
|
22
|
+
// so it must stay compatible with ImageURISource type
|
|
23
|
+
type RenderToImageResult = {
|
|
24
|
+
/**
|
|
25
|
+
* The file uri to the image.
|
|
26
|
+
*/
|
|
27
|
+
uri: string;
|
|
28
|
+
/**
|
|
29
|
+
* Image width in dp.
|
|
30
|
+
*/
|
|
31
|
+
width: number;
|
|
32
|
+
/**
|
|
33
|
+
* Image height in dp.
|
|
34
|
+
*/
|
|
35
|
+
height: number;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Scale factor of the image. Multiply the dp dimensions by this value to get the dimensions in pixels.
|
|
39
|
+
* */
|
|
40
|
+
scale: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
21
43
|
type ExpoFontUtilsModule = {
|
|
22
44
|
renderToImageAsync: (
|
|
23
45
|
glyph: string,
|
|
@@ -26,7 +48,7 @@ type ExpoFontUtilsModule = {
|
|
|
26
48
|
size?: number;
|
|
27
49
|
color?: number;
|
|
28
50
|
},
|
|
29
|
-
) => Promise<
|
|
51
|
+
) => Promise<RenderToImageResult>;
|
|
30
52
|
};
|
|
31
53
|
|
|
32
54
|
declare global {
|
|
@@ -78,14 +100,13 @@ export function assertExpoModulesPresent(globalObj: unknown): asserts globalObj
|
|
|
78
100
|
}
|
|
79
101
|
}
|
|
80
102
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const hasNecessaryExpoFeatures = getIsDynamicLoadingSupported(globalThis);
|
|
103
|
+
// Detection of Expo modules is deferred to first use so that import order
|
|
104
|
+
// doesn't matter. By the time a component renders, all imports (including Expo)
|
|
105
|
+
// have been evaluated and globalThis.expo is available.
|
|
85
106
|
|
|
86
|
-
let
|
|
107
|
+
let dynamicFontLoadingOverride: boolean | null = null;
|
|
87
108
|
|
|
88
|
-
export const isDynamicLoadingSupported = () =>
|
|
109
|
+
export const isDynamicLoadingSupported = () => getIsDynamicLoadingSupported(globalThis);
|
|
89
110
|
|
|
90
111
|
/**
|
|
91
112
|
* Set whether dynamic loading of fonts is enabled.
|
|
@@ -96,8 +117,10 @@ export const isDynamicLoadingSupported = () => hasNecessaryExpoFeatures;
|
|
|
96
117
|
* @returns `true` if dynamic loading of fonts was successfully set. `false` otherwise.
|
|
97
118
|
* */
|
|
98
119
|
export const setDynamicLoadingEnabled = (value: boolean): boolean => {
|
|
99
|
-
if (!
|
|
120
|
+
if (!getIsDynamicLoadingSupported(globalThis)) {
|
|
100
121
|
if (process.env.NODE_ENV !== 'production' && !!value) {
|
|
122
|
+
const hasNecessaryExpoModules =
|
|
123
|
+
(Platform.OS === 'web' || !!globalThis.expo?.modules?.ExpoAsset) && !!globalThis.expo?.modules?.ExpoFontLoader;
|
|
101
124
|
const message = hasNecessaryExpoModules
|
|
102
125
|
? 'Expo is installed, but does not support dynamic font loading. Make sure to use Expo SDK 54 or newer.'
|
|
103
126
|
: 'Necessary Expo modules not found. Dynamic font loading is not available when necessary Expo modules are not present.';
|
|
@@ -106,7 +129,7 @@ export const setDynamicLoadingEnabled = (value: boolean): boolean => {
|
|
|
106
129
|
return false;
|
|
107
130
|
}
|
|
108
131
|
|
|
109
|
-
|
|
132
|
+
dynamicFontLoadingOverride = !!value;
|
|
110
133
|
|
|
111
134
|
return true;
|
|
112
135
|
};
|
|
@@ -114,7 +137,8 @@ export const setDynamicLoadingEnabled = (value: boolean): boolean => {
|
|
|
114
137
|
/**
|
|
115
138
|
* Whether dynamic loading of fonts is enabled.
|
|
116
139
|
* */
|
|
117
|
-
export const isDynamicLoadingEnabled = () =>
|
|
140
|
+
export const isDynamicLoadingEnabled = (): boolean =>
|
|
141
|
+
dynamicFontLoadingOverride ?? getIsDynamicLoadingSupported(globalThis);
|
|
118
142
|
|
|
119
143
|
type ErrorCallback = (args: { error: Error; fontFamily: string; fontSource: FontSource }) => void;
|
|
120
144
|
|
package/src/get-image-library.ts
CHANGED
|
@@ -23,12 +23,14 @@ export const ensureGetImageAvailable = () => {
|
|
|
23
23
|
if (hasExpoRenderToImage) {
|
|
24
24
|
const { ExpoFontUtils } = globalRef.expo.modules;
|
|
25
25
|
return {
|
|
26
|
-
getImageForFont: async (fontReference: string, glyph: string, size: number, color: number) =>
|
|
27
|
-
ExpoFontUtils.renderToImageAsync(glyph, {
|
|
26
|
+
getImageForFont: async (fontReference: string, glyph: string, size: number, color: number) => {
|
|
27
|
+
const result = await ExpoFontUtils.renderToImageAsync(glyph, {
|
|
28
28
|
fontFamily: fontReference,
|
|
29
29
|
size,
|
|
30
30
|
color,
|
|
31
|
-
})
|
|
31
|
+
});
|
|
32
|
+
return result.uri;
|
|
33
|
+
},
|
|
32
34
|
getImageForFontSync: () => {
|
|
33
35
|
throw new Error(
|
|
34
36
|
'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.',
|
|
@@ -37,6 +39,6 @@ export const ensureGetImageAvailable = () => {
|
|
|
37
39
|
};
|
|
38
40
|
}
|
|
39
41
|
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
|
|
42
|
+
'Error in getImageSource / getImageSourceSync: You need to either (1) install `@react-native-vector-icons/get-image` or (2) use Expo SDK 54+ (Expo dev client or Expo Go). Check your setup and rebuild the app.',
|
|
41
43
|
);
|
|
42
44
|
};
|
package/src/get-image-source.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TextStyle } from 'react-native';
|
|
2
2
|
import { PixelRatio, processColor } from 'react-native';
|
|
3
3
|
|
|
4
|
-
import type createIconSourceCache from './create-icon-source-cache';
|
|
4
|
+
import type { createIconSourceCache } from './create-icon-source-cache';
|
|
5
5
|
import { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from './defaults';
|
|
6
6
|
import { ensureGetImageAvailable } from './get-image-library';
|
|
7
7
|
|
|
@@ -19,24 +19,18 @@ export const getImageSourceSync = (
|
|
|
19
19
|
|
|
20
20
|
const maybeCachedValue = imageSourceCache.get(cacheKey);
|
|
21
21
|
if (maybeCachedValue !== undefined) {
|
|
22
|
-
// FIXME: Should this check if it's an error and throw it again?
|
|
23
22
|
return maybeCachedValue;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return value;
|
|
36
|
-
} catch (error) {
|
|
37
|
-
imageSourceCache.setError(cacheKey, error as Error);
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
25
|
+
const imagePath = NativeIconAPI.getImageForFontSync(
|
|
26
|
+
fontReference,
|
|
27
|
+
glyph,
|
|
28
|
+
size,
|
|
29
|
+
processedColor as number, // FIXME what if a non existent colour was passed in?,
|
|
30
|
+
);
|
|
31
|
+
const value = { uri: imagePath, scale: PixelRatio.get() };
|
|
32
|
+
imageSourceCache.setValue(cacheKey, value);
|
|
33
|
+
return value;
|
|
40
34
|
};
|
|
41
35
|
|
|
42
36
|
export const getImageSource = async (
|
|
@@ -53,22 +47,11 @@ export const getImageSource = async (
|
|
|
53
47
|
|
|
54
48
|
const maybeCachedValue = imageSourceCache.get(cacheKey);
|
|
55
49
|
if (maybeCachedValue !== undefined) {
|
|
56
|
-
// FIXME: Should this check if it's an error and throw it again?
|
|
57
50
|
return maybeCachedValue;
|
|
58
51
|
}
|
|
59
52
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|
|
53
|
+
const imagePath = await NativeIconAPI.getImageForFont(fontReference, glyph, size, processedColor as number);
|
|
54
|
+
const value = { uri: imagePath, scale: PixelRatio.get() };
|
|
55
|
+
imageSourceCache.setValue(cacheKey, value);
|
|
56
|
+
return value;
|
|
74
57
|
};
|