@td-design/react-native
Version:
react-native UI组件库
54 lines • 1.36 kB
JavaScript
import { useRef } from 'react';
import React from 'react';
import { useMemoizedFn } from '@td-design/rn-hooks';
import { addNewRef, getRef, removeOldRef } from '../utils/ref-util';
import { LONG, SHORT } from './constant';
import NotifyRoot from './NotifyRoot';
let refs = [];
export default function Notify() {
const notifyRef = useRef(null);
const setRef = useMemoizedFn(ref => {
if (ref) {
notifyRef.current = ref;
addNewRef(refs, ref);
} else {
removeOldRef(refs, notifyRef.current);
}
});
return /*#__PURE__*/React.createElement(NotifyRoot, {
ref: setRef
});
}
Notify.displayName = 'Notify';
Notify.SHORT = SHORT;
Notify.LONG = LONG;
const defaultProps = {
content: '',
duration: SHORT,
autoClose: true
};
Notify.success = props => {
var _getRef;
(_getRef = getRef(refs)) === null || _getRef === void 0 ? void 0 : _getRef.show({
...defaultProps,
...props,
type: 'success'
});
};
Notify.fail = props => {
var _getRef2;
(_getRef2 = getRef(refs)) === null || _getRef2 === void 0 ? void 0 : _getRef2.show({
...defaultProps,
...props,
type: 'fail'
});
};
Notify.info = props => {
var _getRef3;
(_getRef3 = getRef(refs)) === null || _getRef3 === void 0 ? void 0 : _getRef3.show({
...defaultProps,
...props,
type: 'info'
});
};
//# sourceMappingURL=index.js.map