transition.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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) {
  8. return {
  9. enter:
  10. 'van-' +
  11. name +
  12. '-enter van-' +
  13. name +
  14. '-enter-active enter-class enter-active-class',
  15. 'enter-to':
  16. 'van-' +
  17. name +
  18. '-enter-to van-' +
  19. name +
  20. '-enter-active enter-to-class enter-active-class',
  21. leave:
  22. 'van-' +
  23. name +
  24. '-leave van-' +
  25. name +
  26. '-leave-active leave-class leave-active-class',
  27. 'leave-to':
  28. 'van-' +
  29. name +
  30. '-leave-to van-' +
  31. name +
  32. '-leave-active leave-to-class leave-active-class',
  33. };
  34. };
  35. function transition(showDefaultValue) {
  36. return Behavior({
  37. properties: {
  38. customStyle: String,
  39. // @ts-ignore
  40. show: {
  41. type: Boolean,
  42. value: showDefaultValue,
  43. observer: 'observeShow',
  44. },
  45. // @ts-ignore
  46. duration: {
  47. type: null,
  48. value: 300,
  49. observer: 'observeDuration',
  50. },
  51. name: {
  52. type: String,
  53. value: 'fade',
  54. },
  55. },
  56. data: {
  57. type: '',
  58. inited: false,
  59. display: false,
  60. },
  61. ready: function () {
  62. if (this.data.show === true) {
  63. this.observeShow(true, false);
  64. }
  65. },
  66. methods: {
  67. observeShow: function (value, old) {
  68. if (value === old) {
  69. return;
  70. }
  71. value ? this.enter() : this.leave();
  72. },
  73. enter: function () {
  74. var _this = this;
  75. var _a = this.data,
  76. duration = _a.duration,
  77. name = _a.name;
  78. var classNames = getClassNames(name);
  79. var currentDuration = validator_1.isObj(duration)
  80. ? duration.enter
  81. : duration;
  82. this.status = 'enter';
  83. this.$emit('before-enter');
  84. utils_1.requestAnimationFrame(function () {
  85. if (_this.status !== 'enter') {
  86. return;
  87. }
  88. _this.$emit('enter');
  89. _this.setData({
  90. inited: true,
  91. display: true,
  92. classes: classNames.enter,
  93. currentDuration: currentDuration,
  94. });
  95. utils_1.requestAnimationFrame(function () {
  96. if (_this.status !== 'enter') {
  97. return;
  98. }
  99. _this.transitionEnded = false;
  100. _this.setData({ classes: classNames['enter-to'] });
  101. });
  102. });
  103. },
  104. leave: function () {
  105. var _this = this;
  106. if (!this.data.display) {
  107. return;
  108. }
  109. var _a = this.data,
  110. duration = _a.duration,
  111. name = _a.name;
  112. var classNames = getClassNames(name);
  113. var currentDuration = validator_1.isObj(duration)
  114. ? duration.leave
  115. : duration;
  116. this.status = 'leave';
  117. this.$emit('before-leave');
  118. utils_1.requestAnimationFrame(function () {
  119. if (_this.status !== 'leave') {
  120. return;
  121. }
  122. _this.$emit('leave');
  123. _this.setData({
  124. classes: classNames.leave,
  125. currentDuration: currentDuration,
  126. });
  127. utils_1.requestAnimationFrame(function () {
  128. if (_this.status !== 'leave') {
  129. return;
  130. }
  131. _this.transitionEnded = false;
  132. setTimeout(function () {
  133. return _this.onTransitionEnd();
  134. }, currentDuration);
  135. _this.setData({ classes: classNames['leave-to'] });
  136. });
  137. });
  138. },
  139. onTransitionEnd: function () {
  140. if (this.transitionEnded) {
  141. return;
  142. }
  143. this.transitionEnded = true;
  144. this.$emit('after-' + this.status);
  145. var _a = this.data,
  146. show = _a.show,
  147. display = _a.display;
  148. if (!show && display) {
  149. this.setData({ display: false });
  150. }
  151. },
  152. },
  153. });
  154. }
  155. exports.transition = transition;