import isNil from 'lodash/isNil'; import React, { isValidElement, memo } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import { getDefaultValue } from '../helpers'; import Theme from '../theme'; import type { LoadingProps } from './interface'; import Circular from './loading-circular'; import Spinner from './loading-spinner'; import { varCreator } from './style'; /** * Loading 加载 * 加载图标,用于表示加载中的过渡状态。 */ const Loading: React.FC = ({ children, style, textStyle, size, color, textSize, vertical = false, type = 'circular', ...restProps }) => { const TOKENS = Theme.useThemeTokens(); const CV = Theme.createVar(TOKENS, varCreator); const ICON_COLOR = getDefaultValue(color, CV.loading_icon_color); const ICON_SIZE = getDefaultValue(size, CV.loading_icon_size); const textJSX = !isNil(children) ? ( isValidElement(children) ? ( children ) : ( {children} ) ) : null; return ( {type === 'circular' ? ( ) : ( )} {textJSX} ); }; const STYLES = StyleSheet.create({ loading: { flexDirection: 'row', alignItems: 'center', }, loading_vertical: { flexDirection: 'column', }, }); export default memo(Loading);