index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { PopupDefaultProps } from './props';
  2. import { compareVersion } from '../_util/compareVersion';
  3. import '../_util/assert-component2';
  4. var SDKVersion = my.SDKVersion;
  5. var isOldVersion = compareVersion(SDKVersion, '2.0.0') < 0;
  6. var component2 = my.canIUse('component2');
  7. Component({
  8. props: PopupDefaultProps,
  9. data: {
  10. closing: false,
  11. isOldVersion: isOldVersion,
  12. },
  13. didUpdate: function (prevProps) {
  14. if (component2) {
  15. return;
  16. }
  17. var _a = this.props, visible = _a.visible, duration = _a.duration, animation = _a.animation;
  18. if (prevProps.visible && !visible) {
  19. if (animation && duration > 0) {
  20. this.setData({ closing: true });
  21. }
  22. }
  23. },
  24. deriveDataFromProps: function (nextProps) {
  25. var visible = nextProps.visible, duration = nextProps.duration, animation = nextProps.animation;
  26. if (this.props.visible && !visible) {
  27. if (animation && duration > 0) {
  28. this.setData({ closing: true });
  29. }
  30. }
  31. },
  32. methods: {
  33. onTapMask: function () {
  34. var closing = this.data.closing;
  35. if (closing) {
  36. return;
  37. }
  38. var onClose = this.props.onClose;
  39. if (onClose) {
  40. onClose();
  41. }
  42. },
  43. onAnimationEnd: function () {
  44. var closing = this.data.closing;
  45. if (closing) {
  46. this.setData({ closing: false });
  47. }
  48. },
  49. },
  50. });