Toast.js 672 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { Toast, Portal } from '@ant-design/react-native'
  2. const myToast = (now) => ({
  3. tKey: '',
  4. loading() {
  5. const { tKey } = now()
  6. if (!tKey) {
  7. const newKey = Toast.loading('Loading...', 0)
  8. now({
  9. tKey: newKey,
  10. })
  11. }
  12. },
  13. success(title) {
  14. const { clearLoading } = now()
  15. clearLoading()
  16. Toast.success(title, 2)
  17. },
  18. warnning(title) {
  19. const { clearLoading } = now()
  20. clearLoading()
  21. Toast.info(title, 2)
  22. },
  23. clearLoading() {
  24. const { tKey } = now()
  25. if (tKey) {
  26. Portal.remove(tKey)
  27. now({
  28. tKey: '',
  29. })
  30. }
  31. },
  32. })
  33. export default myToast