UNPKG

@fruits-chain/react-native-xiaoshu

Version:
67 lines (65 loc) 2.04 kB
"use strict"; import isNil from 'lodash/isNil'; import React, { isValidElement, memo } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import { getDefaultValue } from "../helpers/index.js"; import Theme from "../theme/index.js"; import Circular from "./loading-circular.js"; import Spinner from "./loading-spinner.js"; import { varCreator } from "./style.js"; /** * Loading 加载 * 加载图标,用于表示加载中的过渡状态。 */ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const Loading = ({ children, style, theme, textStyle, size, color, textSize, vertical = false, type = 'circular', loadingIcon, ...restProps }) => { const [CV] = Theme.useStyle({ varCreator, theme }); const ICON_COLOR = getDefaultValue(color, CV.loading_icon_color); const ICON_SIZE = getDefaultValue(size, CV.loading_icon_size); const textJSX = !isNil(children) ? /*#__PURE__*/isValidElement(children) ? children : /*#__PURE__*/_jsx(Text, { style: StyleSheet.flatten([{ fontSize: textSize || CV.loading_text_font_size, color: color || CV.loading_text_color, marginLeft: vertical ? 0 : CV.loading_gap, marginTop: vertical ? CV.loading_gap : 0 }, textStyle]), children: children }) : null; return /*#__PURE__*/_jsxs(View, { ...restProps, style: StyleSheet.flatten([STYLES.loading, vertical ? STYLES.loading_vertical : null, style]), children: [/*#__PURE__*/isValidElement(loadingIcon) ? loadingIcon : typeof loadingIcon === 'function' ? loadingIcon(ICON_SIZE, ICON_COLOR) : type === 'circular' ? /*#__PURE__*/_jsx(Circular, { size: ICON_SIZE, color: ICON_COLOR }) : /*#__PURE__*/_jsx(Spinner, { size: ICON_SIZE, color: ICON_COLOR }), textJSX] }); }; const STYLES = StyleSheet.create({ loading: { flexDirection: 'row', alignItems: 'center' }, loading_vertical: { flexDirection: 'column' } }); export default /*#__PURE__*/memo(Loading); //# sourceMappingURL=loading.js.map