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?
- 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)
- 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:
- Created 3 years ago
- Comments:12 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
这个你建议加一个
Toast.config
的话我想你知道怎么做了。 哈哈 做成可配置的就谁也不会受伤害顺便催一下 v4 …