question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Toast is not convenient

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

  1. No more Portal for Toast removing(Toast 自带 show / hide 方法,不再引入 Portal 去 remove
import { Portal, Toast } from '@ant-design/react-native'
const key = Toast.loading('messsage')
Portal.remove(key)
  1. Real Optional Parameters(Toast 参数应该选填,同时做到 API 向后兼容,现在如果想要 mask = false,需要把前面的参数都传入进去
Toast.info('Toast without mask !!!', 1, undefined, false);

What does the proposed API look like?

Toast.success({ content: 'hi', mask: true });
Toast.success('hi');

目前我直接加了一层进行适配

import { Toast as AntdToast } from '@ant-design/react-native';

interface IProps {
  content: string;
  duration?: number;
  onClose?: () => void;
  mask?: boolean;
}

// Order is important!
const defaultProps = new Map<keyof IProps, any>();
defaultProps.set('content', '');
defaultProps.set('duration', 2);
defaultProps.set('onClose', () => {});
defaultProps.set('mask', false);

const getAntdProps = (props: IProps | string) => {
  let _props = props as IProps;
  if (typeof _props === 'string') {
    _props = {
      content: _props,
    };
  }

  const propsMap = new Map(defaultProps);

  const antdProps: [
    string?,
    (number | undefined)?,
    ((() => void) | undefined)?,
    (boolean | undefined)?,
  ] = [];

  Array.from(propsMap.keys()).forEach(key => {
    antdProps.push(_props[key] || propsMap.get(key));
  });

  return antdProps as [
    string,
    (number | undefined)?,
    ((() => void) | undefined)?,
    (boolean | undefined)?,
  ];
};

const Toast = {
  success(props: IProps | string) {
    AntdToast.success.apply(null, getAntdProps(props));
  },
  fail(props: IProps | string) {
    AntdToast.fail.apply(null, getAntdProps(props));
  },
  info(props: IProps | string) {
    AntdToast.info.apply(null, getAntdProps(props));
  },
  loading(props: IProps | string) {
    AntdToast.loading.apply(null, getAntdProps(props));
  },
  offline(props: IProps | string) {
    AntdToast.offline.apply(null, getAntdProps(props));
  },
};

export { Toast };
export default Toast;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
BANG88commented, May 30, 2020

这个你建议加一个 Toast.config 的话我想你知道怎么做了。 哈哈 做成可配置的就谁也不会受伤害

1reaction
helsonxiaocommented, May 28, 2020

顺便催一下 v4 …

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap toast does not show up - Stack Overflow
I am developing a website in HTML using bootstrap and javascript. I am trying to add a toast using the following ...
Read more >
How to Give an Awesome Toast - Science of People
When in doubt, ask permission: If you are worried a joke is too embarrassing or inappropriate, then ask a friend or ask the...
Read more >
What Is a Toast Message, and How Do You Use It? - MagicBell
Toast messages ensure that the use of the application is not interrupted while providing necessary information for the user. They have no ...
Read more >
Toasts · Bootstrap v5.0
Toasts are lightweight notifications designed to mimic the push notifications that have been popularized by mobile and desktop operating systems.
Read more >
Android Custom Toast. Toast has more features other than…
Toast is an easy and convenient way to display a short message to user. ... For example, unlike DialogFragment , Toast does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found