@eslam-elmeniawy/react-native-common-components
Version:
Common `ReactNative` components packed in library for usage in projects.
49 lines (45 loc) • 1.7 kB
JavaScript
;
// External imports.
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
// Types imports.
// Internal imports.
import styles from "./ImagePlaceholder.styles.js";
import { jsx as _jsx } from "react/jsx-runtime";
let Progress = null;
try {
Progress = require('react-native-progress');
try {
require('react-native-svg');
} catch (_error) {
// ignore svg load errors in non-native envs
}
} catch (error) {
console.warn('Error loading `react-native-progress`:', error);
Progress = null;
}
// Create ProgressPie component ONCE at module level, not per-render
const ProgressPie = Progress?.Pie ? Progress.Pie : pieProps => /*#__PURE__*/React.createElement('Pie', pieProps);
const Loading = /*#__PURE__*/React.memo(props => {
const {
loadingProps,
theme,
setProgressSizeState,
progress,
progressSize
} = props;
return /*#__PURE__*/_jsx(View, {
style: StyleSheet.flatten([styles.image, styles.loadingContainer, {
backgroundColor: loadingProps?.backgroundColor == null || loadingProps?.backgroundColor === undefined ? theme.colors.backdrop : loadingProps?.backgroundColor
}]),
onLayout: event => setProgressSizeState?.((event.nativeEvent.layout.width > event.nativeEvent.layout.height ? event.nativeEvent.layout.height : event.nativeEvent.layout.width) / 2),
children: /*#__PURE__*/_jsx(ProgressPie, {
indeterminate: (progress ?? 0) <= 0,
size: progressSize,
progress: progress,
color: loadingProps?.color == null || loadingProps?.color === undefined ? theme.colors.surface : loadingProps?.color
})
});
});
export default Loading;
//# sourceMappingURL=Loading.js.map