@react-native-vector-icons/common
Version:
Customizable Icons for React Native with support for image source and full styling.
46 lines (45 loc) • 1.46 kB
JavaScript
;
import { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from "./defaults.js";
import { ensureGetImageAvailable } from "./get-image-library.js";
const resolveOptions = (imageSourceCache, fontReference, glyph, {
size = DEFAULT_ICON_SIZE,
color = DEFAULT_ICON_COLOR,
lineHeight
} = {}) => {
const cacheKey = `${glyph}:${size}:${String(color)}:${lineHeight ?? ''}`;
const cached = imageSourceCache.get(cacheKey);
const nativeOptions = {
fontFamily: fontReference,
size,
color: color,
lineHeight
};
return {
cacheKey,
cached,
nativeOptions
};
};
export const getImageSourceSync = (imageSourceCache, fontReference, glyph, options) => {
const {
cacheKey,
cached,
nativeOptions
} = resolveOptions(imageSourceCache, fontReference, glyph, options);
if (cached !== undefined) return cached;
const value = ensureGetImageAvailable().getImageForFontSync(glyph, nativeOptions);
imageSourceCache.setValue(cacheKey, value);
return value;
};
export const getImageSource = async (imageSourceCache, fontReference, glyph, options) => {
const {
cacheKey,
cached,
nativeOptions
} = resolveOptions(imageSourceCache, fontReference, glyph, options);
if (cached !== undefined) return cached;
const value = await ensureGetImageAvailable().getImageForFont(glyph, nativeOptions);
imageSourceCache.setValue(cacheKey, value);
return value;
};
//# sourceMappingURL=get-image-source.js.map