Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toast设置duration为0时,手动隐藏不好使 #745

Closed
weiq opened this issue Jan 19, 2017 · 7 comments
Closed

Toast设置duration为0时,手动隐藏不好使 #745

weiq opened this issue Jan 19, 2017 · 7 comments
Assignees

Comments

@weiq
Copy link

weiq commented Jan 19, 2017

Toast设置duration为0时,手动隐藏不好使。
如果只有一个Toast提示时可以隐藏,如果有两个的时候最先出来的Toast隐藏不了。

示例:
https://codepen.io/weiq/pen/NddyXw?editors=0010

@paranoidjk
Copy link
Contributor

内存里面只保留了对最新的Toast实例的引用,所以你调用 Toast.hide()只能隐藏最新的那个Toast

@weiq 对于你的需求,应该写成这样

Toast.hide();  // 请求结束的时候先隐藏加载中loading
Toast.fail("加载错误1!", 400); // 再显示加载错误的toast

@silentcloud 是不是可以考虑改下Api的设计,类似这样

const toast = Toast.loading('text');
toast.hide();

@silentcloud
Copy link
Contributor

silentcloud commented Jan 19, 2017

实际业务中用到的情况,一般页面中都只是有一个 toast 当前在显示中,应该很难看到两个 toast 同时显示吧,第二种方式在使用中还要保存引用实例,用起来略显麻烦;
结合之前业务使用经验,建议用第一种方式,这种方式也是跟容器保持同步的

@weiq
Copy link
Author

weiq commented Jan 19, 2017

@paranoidjk @silentcloud 很多时候会有同时发多个ajax时,在请求前loading提示的并发问题,不可能按顺序隐藏。
例如:

fetchData(url) {
  Toast.loading("请求中...");
  $.ajax({ url, success: function(){
    Toast.hide();
  }});
}

componentWillMount() {
  this.fetchData("url1");
  this.fetchData("url2");
}

下面这种方式可以满足要求

const toast = Toast.loading('text');
toast.hide();

@paranoidjk
Copy link
Contributor

从移动端的场景来看,实际上一个页面的确不太可能同时两个Toast

@silentcloud 另一种方案,或者把Toast做成单例?每次调用都销毁/覆盖之前的?

@silentcloud
Copy link
Contributor

@paranoidjk 恩,这个方案可行,也不会存在兼容性改动,我稍后改一下

@paranoidjk
Copy link
Contributor

@silentcloud 💯 忙的话也可以assign给我,你来review

@lock
Copy link

lock bot commented Jun 13, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants