ant-design / ant-design-mobile-rn

Ant Design for React Native
https://rn.mobile.ant.design/
MIT License
3.04k stars 612 forks source link

feat:Toast 新增 remove、removeAll 回调 #1196

Closed HuXin957 closed 2 years ago

HuXin957 commented 2 years ago

First of all, thank you for your contribution! :-)

Please makes sure that these checkboxes are checked before submitting your PR, thank you!

Extra checklist:

if isBugFix :

elif isNewFeature :

1uokun commented 2 years ago

针对 issue https://github.com/ant-design/ant-design-mobile-rn/issues/1195 提出的

// 在调用Toast.removeAll()时能正常输出 “hello”
Toast.loading('xx',0,()=>console.log('hello'))
Toast.removeAll()

在本次的mr中并没有实现哦

HuXin957 commented 2 years ago

针对 issue #1195 提出的

// 在调用Toast.removeAll()时能正常输出 “hello”
Toast.loading('xx',0,()=>console.log('hello'))
Toast.removeAll()

在本次的mr中并没有实现哦

这只是个设想。如果将回调放到打开loading的方法中,那只能固定时间后执行,在异步中是不符合需求的。所以只能将回调放到关闭loding的方法中。所以最终是我给removeAll、remove加了一个回调

1uokun commented 2 years ago

那和

Toast.removeAll();
callback();

没什么区别呢

erichua23 commented 2 years ago

针对 issue #1195 提出的

// 在调用Toast.removeAll()时能正常输出 “hello”
Toast.loading('xx',0,()=>console.log('hello'))
Toast.removeAll()

在本次的mr中并没有实现哦

如果只是实现这个功能,componentWillUnmount里面处理一下就行了。有动画的onClose依赖于动画结束的回调,duration为0的就直接单独根据 WillUnmount 来判断。 image

或者更精简的,可以把

    this.anim.start(() => {
      if (duration > 0) {
        this.anim = null
        if (onClose) {
          onClose()
        }
        if (onAnimationEnd) {
          onAnimationEnd()
        }
      }
    })

这里面的onClose回调都不要了,都走componentWillUnmount来触发就好了,效果是一样的,代码流程简单很多。 @1uokun 看看,这个思路没问题的话,我提个PR。