UNPKG

@eslam-elmeniawy/react-native-common-components

Version:

Common `ReactNative` components packed in library for usage in projects.

113 lines (110 loc) 3.12 kB
"use strict"; // External imports. import * as React from 'react'; // Types imports. // Internal imports. import styles from "./ImagePlaceholder.styles.js"; import Placeholder from "./Placeholder.js"; import Loading from "./Loading.js"; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; const Image = /*#__PURE__*/React.memo(props => { try { const FastImage = require('@d11/react-native-fast-image').default; require('react-native-svg'); const { source, placeholder, vectorPlaceholder, resizeMode, priority, cache, loadingProps, theme, isLoading, isError, progress, progressSize, setLoadingState, setErrorState, setProgressState, setProgressSizeState } = props; let _resizeMode; switch (resizeMode) { case 'contain': _resizeMode = FastImage.resizeMode.contain; break; case 'stretch': _resizeMode = FastImage.resizeMode.stretch; break; case 'center': _resizeMode = FastImage.resizeMode.center; break; default: _resizeMode = FastImage.resizeMode.cover; break; } let _priority; switch (priority) { case 'low': _priority = FastImage.priority.low; break; case 'high': _priority = FastImage.priority.high; break; default: _priority = FastImage.priority.normal; break; } let _cache; switch (cache) { case 'web': _cache = FastImage.cacheControl.web; break; case 'cacheOnly': _cache = FastImage.cacheControl.cacheOnly; break; default: _cache = FastImage.cacheControl.immutable; break; } let _shouldDisplayLoading = isLoading; if (loadingProps?.showLoading === false) { _shouldDisplayLoading = false; } return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(Placeholder, { source: source, placeholder: placeholder, vectorPlaceholder: vectorPlaceholder, resizeMode: resizeMode, isLoading: isLoading, isError: isError, progress: progress, progressSize: progressSize }), Boolean(source) && !isError && /*#__PURE__*/_jsx(FastImage, { style: styles.image, source: { uri: source, priority: _priority, cache: _cache }, resizeMode: _resizeMode, onLoadStart: () => setLoadingState(true), onLoadEnd: () => setLoadingState(false), onError: () => setErrorState(true), onProgress: e => setProgressState(e.nativeEvent.total > 0 ? e.nativeEvent.loaded / e.nativeEvent.total : 0) }), _shouldDisplayLoading && /*#__PURE__*/_jsx(Loading, { loadingProps: loadingProps, theme: theme, setProgressSizeState: setProgressSizeState, progress: progress, progressSize: progressSize })] }); } catch (error) { return null; } }); export default Image; //# sourceMappingURL=Image.js.map