UNPKG

@td-design/react-native

Version:

react-native UI组件库

86 lines 2.14 kB
import React, { useRef } from 'react'; import { useMemoizedFn } from '@td-design/rn-hooks'; import { addNewRef, getRef, removeOldRef } from '../utils/ref-util'; import { INFINITY, LONG, SHORT } from './constant'; import ToastRoot from './ToastRoot'; let refs = []; export default function Toast() { const toastRef = useRef(null); const setRef = useMemoizedFn(ref => { if (ref) { toastRef.current = ref; addNewRef(refs, ref); } else { removeOldRef(refs, toastRef.current); } }); return /*#__PURE__*/React.createElement(ToastRoot, { ref: setRef }); } Toast.displayName = 'Toast'; Toast.hide = () => { var _getRef; (_getRef = getRef(refs)) === null || _getRef === void 0 ? void 0 : _getRef.hide(); }; Toast.top = _ref => { var _getRef2; let { duration = SHORT, content } = _ref; (_getRef2 = getRef(refs)) === null || _getRef2 === void 0 ? void 0 : _getRef2.show({ content, duration, position: 'top' }); }; Toast.middle = _ref2 => { var _getRef3; let { duration = SHORT, content } = _ref2; (_getRef3 = getRef(refs)) === null || _getRef3 === void 0 ? void 0 : _getRef3.show({ content, duration, position: 'middle' }); }; Toast.bottom = _ref3 => { var _getRef4; let { duration = SHORT, content } = _ref3; (_getRef4 = getRef(refs)) === null || _getRef4 === void 0 ? void 0 : _getRef4.show({ content, duration, position: 'bottom' }); }; Toast.process = function () { var _getRef5; let content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '加载中...'; (_getRef5 = getRef(refs)) === null || _getRef5 === void 0 ? void 0 : _getRef5.show({ content, duration: INFINITY, position: 'middle', mask: true, indicator: true }); }; Toast.custom = props => { var _getRef6; (_getRef6 = getRef(refs)) === null || _getRef6 === void 0 ? void 0 : _getRef6.show({ duration: INFINITY, position: 'middle', mask: true, ...props, indicator: false }); }; Toast.SHORT = SHORT; Toast.LONG = LONG; Toast.INFINITY = INFINITY; //# sourceMappingURL=index.js.map