index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _utils = require("../utils");
  7. var _relation = require("../mixins/relation");
  8. var _createNamespace = (0, _utils.createNamespace)('swipe-item'),
  9. createComponent = _createNamespace[0],
  10. bem = _createNamespace[1];
  11. var _default = createComponent({
  12. mixins: [(0, _relation.ChildrenMixin)('vanSwipe')],
  13. data: function data() {
  14. return {
  15. offset: 0,
  16. inited: false,
  17. mounted: false
  18. };
  19. },
  20. mounted: function mounted() {
  21. var _this = this;
  22. this.$nextTick(function () {
  23. _this.mounted = true;
  24. });
  25. },
  26. computed: {
  27. style: function style() {
  28. var style = {};
  29. var _this$parent = this.parent,
  30. size = _this$parent.size,
  31. vertical = _this$parent.vertical;
  32. if (size) {
  33. style[vertical ? 'height' : 'width'] = size + "px";
  34. }
  35. if (this.offset) {
  36. style.transform = "translate" + (vertical ? 'Y' : 'X') + "(" + this.offset + "px)";
  37. }
  38. return style;
  39. },
  40. shouldRender: function shouldRender() {
  41. var index = this.index,
  42. inited = this.inited,
  43. parent = this.parent,
  44. mounted = this.mounted;
  45. if (!parent.lazyRender || inited) {
  46. return true;
  47. } // wait for all item to mount, so we can get the exact count
  48. if (!mounted) {
  49. return false;
  50. }
  51. var active = parent.activeIndicator;
  52. var maxActive = parent.count - 1;
  53. var prevActive = active === 0 && parent.loop ? maxActive : active - 1;
  54. var nextActive = active === maxActive && parent.loop ? 0 : active + 1;
  55. var shouldRender = index === active || index === prevActive || index === nextActive;
  56. if (shouldRender) {
  57. this.inited = true;
  58. }
  59. return shouldRender;
  60. }
  61. },
  62. render: function render() {
  63. var h = arguments[0];
  64. return h("div", {
  65. "class": bem(),
  66. "style": this.style,
  67. "on": (0, _extends2.default)({}, this.$listeners)
  68. }, [this.shouldRender && this.slots()]);
  69. }
  70. });
  71. exports.default = _default;