UNPKG

@applicaster/zapp-react-native-ui-components

Version:

Applicaster Zapp React Native ui components for the Quick Brick App

40 lines (35 loc) 955 B
import FastImage, { Source } from "@applicaster/react-native-fast-image"; import { useMemo } from "react"; import { ImageRequireSource } from "react-native"; function getSourceCache(cache: Source["cache"]) { return cache || FastImage.cacheControl.web; } export const useImageSource = (source?: Source | ImageRequireSource) => { return useMemo(() => { if (source) { if (typeof source === "number") { return source; } return { uri: source.uri, headers: source.headers, priority: source.priority, cache: getSourceCache(source?.cache), maxWidth: source.maxWidth, maxHeight: source.maxHeight, }; } return undefined; }, [ ...(typeof source === "object" ? [ source?.uri, source?.priority, source?.cache, source?.headers, source?.maxWidth, source?.maxHeight, ] : []), ]); };