transition.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.transition = void 0;
  4. // @ts-nocheck
  5. var utils_1 = require("../common/utils");
  6. var validator_1 = require("../common/validator");
  7. var getClassNames = function (name) { return ({
  8. enter: "van-".concat(name, "-enter van-").concat(name, "-enter-active enter-class enter-active-class"),
  9. 'enter-to': "van-".concat(name, "-enter-to van-").concat(name, "-enter-active enter-to-class enter-active-class"),
  10. leave: "van-".concat(name, "-leave van-").concat(name, "-leave-active leave-class leave-active-class"),
  11. 'leave-to': "van-".concat(name, "-leave-to van-").concat(name, "-leave-active leave-to-class leave-active-class"),
  12. }); };
  13. function transition(showDefaultValue) {
  14. return Behavior({
  15. properties: {
  16. customStyle: String,
  17. // @ts-ignore
  18. show: {
  19. type: Boolean,
  20. value: showDefaultValue,
  21. observer: 'observeShow',
  22. },
  23. // @ts-ignore
  24. duration: {
  25. type: null,
  26. value: 300,
  27. observer: 'observeDuration',
  28. },
  29. name: {
  30. type: String,
  31. value: 'fade',
  32. },
  33. },
  34. data: {
  35. type: '',
  36. inited: false,
  37. display: false,
  38. },
  39. ready: function () {
  40. if (this.data.show === true) {
  41. this.observeShow(true, false);
  42. }
  43. },
  44. methods: {
  45. observeShow: function (value, old) {
  46. if (value === old) {
  47. return;
  48. }
  49. value ? this.enter() : this.leave();
  50. },
  51. enter: function () {
  52. var _this = this;
  53. var _a = this.data, duration = _a.duration, name = _a.name;
  54. var classNames = getClassNames(name);
  55. var currentDuration = (0, validator_1.isObj)(duration) ? duration.enter : duration;
  56. if (this.status === 'enter') {
  57. return;
  58. }
  59. this.status = 'enter';
  60. this.$emit('before-enter');
  61. (0, utils_1.requestAnimationFrame)(function () {
  62. if (_this.status !== 'enter') {
  63. return;
  64. }
  65. _this.$emit('enter');
  66. _this.setData({
  67. inited: true,
  68. display: true,
  69. classes: classNames.enter,
  70. currentDuration: currentDuration,
  71. });
  72. (0, utils_1.requestAnimationFrame)(function () {
  73. if (_this.status !== 'enter') {
  74. return;
  75. }
  76. _this.transitionEnded = false;
  77. _this.setData({ classes: classNames['enter-to'] });
  78. });
  79. });
  80. },
  81. leave: function () {
  82. var _this = this;
  83. if (!this.data.display) {
  84. return;
  85. }
  86. var _a = this.data, duration = _a.duration, name = _a.name;
  87. var classNames = getClassNames(name);
  88. var currentDuration = (0, validator_1.isObj)(duration) ? duration.leave : duration;
  89. this.status = 'leave';
  90. this.$emit('before-leave');
  91. (0, utils_1.requestAnimationFrame)(function () {
  92. if (_this.status !== 'leave') {
  93. return;
  94. }
  95. _this.$emit('leave');
  96. _this.setData({
  97. classes: classNames.leave,
  98. currentDuration: currentDuration,
  99. });
  100. (0, utils_1.requestAnimationFrame)(function () {
  101. if (_this.status !== 'leave') {
  102. return;
  103. }
  104. _this.transitionEnded = false;
  105. setTimeout(function () { return _this.onTransitionEnd(); }, currentDuration);
  106. _this.setData({ classes: classNames['leave-to'] });
  107. });
  108. });
  109. },
  110. onTransitionEnd: function () {
  111. if (this.transitionEnded) {
  112. return;
  113. }
  114. this.transitionEnded = true;
  115. this.$emit("after-".concat(this.status));
  116. var _a = this.data, show = _a.show, display = _a.display;
  117. if (!show && display) {
  118. this.setData({ display: false });
  119. }
  120. },
  121. },
  122. });
  123. }
  124. exports.transition = transition;