@tarojs/components-react 4.0.0-beta.0 → 4.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +14 -0
  2. package/dist/components/button/index.js +84 -0
  3. package/dist/components/button/index.js.map +1 -0
  4. package/dist/components/button/style/index.scss.js +4 -0
  5. package/dist/components/button/style/index.scss.js.map +1 -0
  6. package/dist/components/icon/index.js +28 -0
  7. package/dist/components/icon/index.js.map +1 -0
  8. package/dist/components/icon/style/index.scss.js +4 -0
  9. package/dist/components/icon/style/index.scss.js.map +1 -0
  10. package/dist/components/image/index.js +76 -100
  11. package/dist/components/image/index.js.map +1 -1
  12. package/dist/components/image/style/index.css.js +4 -0
  13. package/dist/components/image/style/index.css.js.map +1 -0
  14. package/dist/components/input/index.js +228 -0
  15. package/dist/components/input/index.js.map +1 -0
  16. package/dist/components/input/style/index.scss.js +4 -0
  17. package/dist/components/input/style/index.scss.js.map +1 -0
  18. package/dist/components/pull-down-refresh/index.js +184 -211
  19. package/dist/components/pull-down-refresh/index.js.map +1 -1
  20. package/dist/components/pull-down-refresh/style/index.css.js +4 -0
  21. package/dist/components/pull-down-refresh/style/index.css.js.map +1 -0
  22. package/dist/components/scroll-view/index.js +128 -157
  23. package/dist/components/scroll-view/index.js.map +1 -1
  24. package/dist/components/scroll-view/style/index.css.js +4 -0
  25. package/dist/components/scroll-view/style/index.css.js.map +1 -0
  26. package/dist/components/swiper/index.js +232 -271
  27. package/dist/components/swiper/index.js.map +1 -1
  28. package/dist/components/swiper/style/index.css.js +4 -0
  29. package/dist/components/swiper/style/index.css.js.map +1 -0
  30. package/dist/components/text/index.js +17 -31
  31. package/dist/components/text/index.js.map +1 -1
  32. package/dist/components/text/style/index.css.js +4 -0
  33. package/dist/components/text/style/index.css.js.map +1 -0
  34. package/dist/components/view/index.js +74 -96
  35. package/dist/components/view/index.js.map +1 -1
  36. package/dist/components/view/style/index.css.js +4 -0
  37. package/dist/components/view/style/index.css.js.map +1 -0
  38. package/dist/index.css +1 -0
  39. package/dist/index.js +4 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/utils/index.js +20 -12
  42. package/dist/utils/index.js.map +1 -1
  43. package/package.json +17 -12
  44. package/dist/components/image/style/index.js +0 -8
  45. package/dist/components/image/style/index.js.map +0 -1
  46. package/dist/components/pull-down-refresh/style/index.js +0 -8
  47. package/dist/components/pull-down-refresh/style/index.js.map +0 -1
  48. package/dist/components/scroll-view/style/index.js +0 -8
  49. package/dist/components/scroll-view/style/index.js.map +0 -1
  50. package/dist/components/swiper/style/index.js +0 -8
  51. package/dist/components/swiper/style/index.js.map +0 -1
  52. package/dist/components/text/style/index.js +0 -8
  53. package/dist/components/text/style/index.js.map +0 -1
  54. package/dist/components/view/style/index.js +0 -8
  55. package/dist/components/view/style/index.js.map +0 -1
  56. package/dist/node_modules/.pnpm/registry.npmjs.org_style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js +0 -27
  57. package/dist/node_modules/.pnpm/registry.npmjs.org_style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js.map +0 -1
  58. package/dist/node_modules/.pnpm/registry.npmjs.org_tslib@2.5.0/node_modules/tslib/tslib.es6.js +0 -446
  59. package/dist/node_modules/.pnpm/registry.npmjs.org_tslib@2.5.0/node_modules/tslib/tslib.es6.js.map +0 -1
@@ -1,20 +1,14 @@
1
- import _typeof from '@babel/runtime/helpers/typeof';
2
- import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
3
- import _createClass from '@babel/runtime/helpers/createClass';
4
- import _inherits from '@babel/runtime/helpers/inherits';
5
- import _createSuper from '@babel/runtime/helpers/createSuper';
6
- import { __rest } from '../../node_modules/.pnpm/registry.npmjs.org_tslib@2.5.0/node_modules/tslib/tslib.es6.js';
1
+ import { __rest } from 'tslib';
7
2
  import 'swiper/swiper-bundle.min.css';
8
- import 'weui';
9
- import './style/index.js';
3
+ import './style/index.css.js';
10
4
  import classNames from 'classnames';
11
5
  import React from 'react';
12
6
  import Swipers from 'swiper/swiper-bundle.esm.js';
13
7
  import { debounce } from '../../utils/index.js';
14
8
 
15
- var INSTANCE_ID = 0;
16
- var createEvent = function createEvent(type) {
17
- var e;
9
+ let INSTANCE_ID = 0;
10
+ const createEvent = type => {
11
+ let e;
18
12
  try {
19
13
  e = new TouchEvent(type);
20
14
  } catch (err) {
@@ -23,297 +17,264 @@ var createEvent = function createEvent(type) {
23
17
  }
24
18
  return e;
25
19
  };
26
- var SwiperItem = /*#__PURE__*/function (_React$Component) {
27
- _inherits(SwiperItem, _React$Component);
28
- var _super = _createSuper(SwiperItem);
29
- function SwiperItem() {
30
- _classCallCheck(this, SwiperItem);
31
- return _super.apply(this, arguments);
20
+ class SwiperItem extends React.Component {
21
+ render() {
22
+ const _a = this.props,
23
+ {
24
+ className,
25
+ style,
26
+ itemId,
27
+ children
28
+ } = _a,
29
+ restProps = __rest(_a, ["className", "style", "itemId", "children"]);
30
+ const cls = classNames('swiper-slide', className);
31
+ return React.createElement("div", Object.assign({
32
+ className: cls,
33
+ style: style,
34
+ "item-id": itemId
35
+ }, restProps), children);
32
36
  }
33
- _createClass(SwiperItem, [{
34
- key: "render",
35
- value: function render() {
36
- var _a = this.props,
37
- className = _a.className,
38
- style = _a.style,
39
- itemId = _a.itemId,
40
- children = _a.children,
41
- restProps = __rest(_a, ["className", "style", "itemId", "children"]);
42
- var cls = classNames('swiper-slide', className);
43
- return React.createElement("div", Object.assign({
44
- className: cls,
45
- style: style,
46
- "item-id": itemId
47
- }, restProps), children);
48
- }
49
- }]);
50
- return SwiperItem;
51
- }(React.Component);
52
- var Swiper = /*#__PURE__*/function (_React$Component2) {
53
- _inherits(Swiper, _React$Component2);
54
- var _super2 = _createSuper(Swiper);
55
- function Swiper() {
56
- var _this;
57
- _classCallCheck(this, Swiper);
58
- _this = _super2.apply(this, arguments);
59
- _this._id = 1 + INSTANCE_ID++;
60
- _this._$current = 0;
61
- _this._$width = 0;
62
- _this._$height = 0;
63
- _this.handleSwiperLoopListen = function () {
37
+ }
38
+ class Swiper extends React.Component {
39
+ constructor() {
40
+ super(...arguments);
41
+ this._id = 1 + INSTANCE_ID++;
42
+ this._$current = 0;
43
+ this._$width = 0;
44
+ this._$height = 0;
45
+ this.handleSwiperLoopListen = () => {
64
46
  var _a, _b, _c, _d;
65
- (_b = (_a = _this.observerFirst) === null || _a === void 0 ? void 0 : _a.disconnect) === null || _b === void 0 ? void 0 : _b.call(_a);
66
- (_d = (_c = _this.observerLast) === null || _c === void 0 ? void 0 : _c.disconnect) === null || _d === void 0 ? void 0 : _d.call(_c);
67
- _this.observerFirst = new MutationObserver(_this.handleSwiperLoop);
68
- _this.observerLast = new MutationObserver(_this.handleSwiperLoop);
69
- var wrapper = _this.mySwiper.$wrapperEl[0];
70
- var list = wrapper.querySelectorAll('taro-swiper-item-core:not(.swiper-slide-duplicate)');
47
+ (_b = (_a = this.observerFirst) === null || _a === void 0 ? void 0 : _a.disconnect) === null || _b === void 0 ? void 0 : _b.call(_a);
48
+ (_d = (_c = this.observerLast) === null || _c === void 0 ? void 0 : _c.disconnect) === null || _d === void 0 ? void 0 : _d.call(_c);
49
+ this.observerFirst = new MutationObserver(this.handleSwiperLoop);
50
+ this.observerLast = new MutationObserver(this.handleSwiperLoop);
51
+ const wrapper = this.mySwiper.$wrapperEl[0];
52
+ const list = wrapper.querySelectorAll('taro-swiper-item-core:not(.swiper-slide-duplicate)');
71
53
  if (list.length >= 1) {
72
- _this.observerFirst.observe(list[0], {
54
+ this.observerFirst.observe(list[0], {
73
55
  characterData: true
74
56
  });
75
57
  } else if (list.length >= 2) {
76
- _this.observerLast.observe(list[list.length - 1], {
58
+ this.observerLast.observe(list[list.length - 1], {
77
59
  characterData: true
78
60
  });
79
61
  }
80
62
  };
81
- _this.handleSwiperLoop = debounce(function () {
82
- if (_this.mySwiper && _this.mySwiper.$wrapperEl && _this.props.circular) {
63
+ this.handleSwiperLoop = debounce(() => {
64
+ if (this.mySwiper && this.mySwiper.$wrapperEl && this.props.circular) {
83
65
  // @ts-ignore
84
- _this.mySwiper.loopDestroy();
66
+ this.mySwiper.loopDestroy();
85
67
  // @ts-ignore
86
- _this.mySwiper.loopCreate();
68
+ this.mySwiper.loopCreate();
87
69
  }
88
70
  }, 500);
89
- return _this;
90
71
  }
91
- _createClass(Swiper, [{
92
- key: "componentDidMount",
93
- value: function componentDidMount() {
94
- var _this2 = this;
95
- var _this$props = this.props,
96
- _this$props$autoplay = _this$props.autoplay,
97
- autoplay = _this$props$autoplay === void 0 ? false : _this$props$autoplay,
98
- _this$props$circular = _this$props.circular,
99
- circular = _this$props$circular === void 0 ? true : _this$props$circular,
100
- _this$props$current = _this$props.current,
101
- current = _this$props$current === void 0 ? 0 : _this$props$current,
102
- _this$props$displayMu = _this$props.displayMultipleItems,
103
- displayMultipleItems = _this$props$displayMu === void 0 ? 1 : _this$props$displayMu,
104
- _this$props$duration = _this$props.duration,
105
- duration = _this$props$duration === void 0 ? 500 : _this$props$duration,
106
- _this$props$interval = _this$props.interval,
107
- interval = _this$props$interval === void 0 ? 5000 : _this$props$interval,
108
- spaceBetween = _this$props.spaceBetween,
109
- vertical = _this$props.vertical;
110
- // eslint-disable-next-line @typescript-eslint/no-this-alias
111
- var that = this;
112
- var opt = {
113
- // 指示器
114
- pagination: {
115
- el: ".taro-swiper-".concat(this._id, " > .swiper-container > .swiper-pagination")
72
+ componentDidMount() {
73
+ const {
74
+ autoplay = false,
75
+ circular = true,
76
+ current = 0,
77
+ displayMultipleItems = 1,
78
+ duration = 500,
79
+ interval = 5000,
80
+ spaceBetween,
81
+ vertical
82
+ } = this.props;
83
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
84
+ const that = this;
85
+ const opt = {
86
+ // 指示器
87
+ pagination: {
88
+ el: `.taro-swiper-${this._id} > .swiper-container > .swiper-pagination`
89
+ },
90
+ direction: vertical ? 'vertical' : 'horizontal',
91
+ loop: circular,
92
+ slidesPerView: parseFloat(String(displayMultipleItems)),
93
+ initialSlide: parseInt(String(current), 10),
94
+ speed: parseInt(String(duration), 10),
95
+ observer: true,
96
+ observeParents: true,
97
+ on: {
98
+ slideChange() {
99
+ const e = createEvent('touchend');
100
+ try {
101
+ Object.defineProperty(e, 'detail', {
102
+ enumerable: true,
103
+ value: {
104
+ current: this.realIndex
105
+ }
106
+ });
107
+ } catch (err) {} // eslint-disable-line no-empty
108
+ that._$current = this.realIndex;
109
+ that.handleOnChange(e);
116
110
  },
117
- direction: vertical ? 'vertical' : 'horizontal',
118
- loop: circular,
119
- slidesPerView: parseFloat(String(displayMultipleItems)),
120
- initialSlide: parseInt(String(current), 10),
121
- speed: parseInt(String(duration), 10),
122
- observer: true,
123
- observeParents: true,
124
- on: {
125
- slideChange: function slideChange() {
126
- var e = createEvent('touchend');
127
- try {
128
- Object.defineProperty(e, 'detail', {
129
- enumerable: true,
130
- value: {
131
- current: this.realIndex
132
- }
133
- });
134
- } catch (err) {} // eslint-disable-line no-empty
135
- that._$current = this.realIndex;
136
- that.handleOnChange(e);
137
- },
138
- transitionEnd: function transitionEnd() {
139
- var e = createEvent('touchend');
140
- try {
141
- Object.defineProperty(e, 'detail', {
142
- enumerable: true,
143
- value: {
144
- current: this.mySwiper.realIndex
145
- }
146
- });
147
- if (this.mySwiper.isBeginning) {
148
- this.mySwiper.slideToLoop(this.props.children.length - 1, 0);
149
- } else if (this.mySwiper.isEnd) {
150
- this.mySwiper.slideToLoop(0, 0);
111
+ transitionEnd() {
112
+ const e = createEvent('touchend');
113
+ try {
114
+ Object.defineProperty(e, 'detail', {
115
+ enumerable: true,
116
+ value: {
117
+ current: this.mySwiper.realIndex
151
118
  }
152
- } catch (err) {} // eslint-disable-line no-empty
153
- that.handleOnAnimationFinish(e);
154
- },
155
- observerUpdate: function observerUpdate(_swiper, e) {
156
- var target = e.target;
157
- var className = target && typeof target.className === 'string' ? target.className : '';
158
- if (className.includes('taro_page') && target.style.display !== 'none') {
159
- if (that.props.autoplay && target.contains(_swiper.$el[0])) {
160
- if (that.props.circular) {
161
- _swiper.slideToLoop(this.realIndex, 0); // 更新下标
162
- } else {
163
- _swiper.slideTo(this.realIndex);
164
- }
119
+ });
120
+ if (this.mySwiper.isBeginning) {
121
+ this.mySwiper.slideToLoop(this.props.children.length - 1, 0);
122
+ } else if (this.mySwiper.isEnd) {
123
+ this.mySwiper.slideToLoop(0, 0);
124
+ }
125
+ } catch (err) {} // eslint-disable-line no-empty
126
+ that.handleOnAnimationFinish(e);
127
+ },
128
+ observerUpdate(_swiper, e) {
129
+ const target = e.target;
130
+ const className = target && typeof target.className === 'string' ? target.className : '';
131
+ if (className.includes('taro_page') && target.style.display !== 'none') {
132
+ if (that.props.autoplay && target.contains(_swiper.$el[0])) {
133
+ if (that.props.circular) {
134
+ _swiper.slideToLoop(this.realIndex, 0); // 更新下标
135
+ } else {
136
+ _swiper.slideTo(this.realIndex);
165
137
  }
166
138
  }
167
139
  }
168
140
  }
169
- };
170
- // 自动播放
171
- if (autoplay) {
172
- opt.autoplay = {
173
- delay: parseInt(String(interval), 10),
174
- disableOnInteraction: false
175
- };
176
- }
177
- // 两端距离
178
- if (spaceBetween) {
179
- opt.spaceBetween = spaceBetween;
180
141
  }
181
- this.mySwiper = new Swipers(this.$el, opt);
182
- setTimeout(function () {
183
- _this2.mySwiper.update();
184
- }, 500);
185
- if (!this.mySwiper || !this.props.circular) return;
186
- var wrapper = this.mySwiper.$wrapperEl[0];
187
- this.observer = new MutationObserver(this.handleSwiperLoopListen);
188
- this.observer.observe(wrapper, {
189
- childList: true
190
- });
142
+ };
143
+ // 自动播放
144
+ if (autoplay) {
145
+ opt.autoplay = {
146
+ delay: parseInt(String(interval), 10),
147
+ disableOnInteraction: false
148
+ };
191
149
  }
192
- }, {
193
- key: "UNSAFE_componentWillReceiveProps",
194
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
195
- if (this.mySwiper) {
196
- var nextCurrent = typeof nextProps.current === 'number' ? nextProps.current : this._$current || 0;
197
- this.handleSwiperLoop();
198
- // 是否衔接滚动模式
199
- if (nextProps.circular) {
200
- if (!this.mySwiper.isBeginning && !this.mySwiper.isEnd) {
201
- this.mySwiper.slideToLoop(parseInt(nextCurrent, 10)); // 更新下标
202
- }
203
- } else {
204
- this.mySwiper.slideTo(parseInt(nextCurrent, 10) + 1); // 更新下标
150
+ // 两端距离
151
+ if (spaceBetween) {
152
+ opt.spaceBetween = spaceBetween;
153
+ }
154
+ this.mySwiper = new Swipers(this.$el, opt);
155
+ setTimeout(() => {
156
+ this.mySwiper.update();
157
+ }, 500);
158
+ if (!this.mySwiper || !this.props.circular) return;
159
+ const wrapper = this.mySwiper.$wrapperEl[0];
160
+ this.observer = new MutationObserver(this.handleSwiperLoopListen);
161
+ this.observer.observe(wrapper, {
162
+ childList: true
163
+ });
164
+ }
165
+ UNSAFE_componentWillReceiveProps(nextProps) {
166
+ if (this.mySwiper) {
167
+ const nextCurrent = typeof nextProps.current === 'number' ? nextProps.current : this._$current || 0;
168
+ this.handleSwiperLoop();
169
+ // 是否衔接滚动模式
170
+ if (nextProps.circular) {
171
+ if (!this.mySwiper.isBeginning && !this.mySwiper.isEnd) {
172
+ this.mySwiper.slideToLoop(parseInt(nextCurrent, 10)); // 更新下标
205
173
  }
174
+ } else {
175
+ this.mySwiper.slideTo(parseInt(nextCurrent, 10) + 1); // 更新下标
176
+ }
206
177
 
207
- var autoplay = this.mySwiper.autoplay;
208
- // 判断是否需要停止或开始自动轮播
209
- if (autoplay.running !== nextProps.autoplay) {
210
- if (nextProps.autoplay) {
211
- if (_typeof(this.mySwiper.params.autoplay) === 'object') {
212
- this.mySwiper.params.autoplay.disableOnInteraction = false;
213
- this.mySwiper.params.autoplay.delay = parseInt(String(this.props.interval) || '3000', 10);
214
- }
215
- autoplay.start();
216
- } else {
217
- autoplay.stop();
178
+ const autoplay = this.mySwiper.autoplay;
179
+ // 判断是否需要停止或开始自动轮播
180
+ if (autoplay.running !== nextProps.autoplay) {
181
+ if (nextProps.autoplay) {
182
+ if (typeof this.mySwiper.params.autoplay === 'object') {
183
+ this.mySwiper.params.autoplay.disableOnInteraction = false;
184
+ this.mySwiper.params.autoplay.delay = parseInt(String(this.props.interval) || '3000', 10);
218
185
  }
219
- }
220
- this.mySwiper.update(); // 更新子元素
221
- }
222
- }
223
- }, {
224
- key: "componentDidUpdate",
225
- value: function componentDidUpdate(preProps) {
226
- if (preProps.children.length === 0 && this.props.children.length > 0) {
227
- this.mySwiper.loopDestroy();
228
- this.mySwiper.loopCreate();
229
- }
230
- if (!this.mySwiper) return;
231
- if (this.props.autoplay) {
232
- if (this._$width !== this.mySwiper.width || this._$height !== this.mySwiper.height) {
233
- this.mySwiper.autoplay.start();
186
+ autoplay.start();
187
+ } else {
188
+ autoplay.stop();
234
189
  }
235
190
  }
236
- this._$width = this.mySwiper.width;
237
- this._$height = this.mySwiper.height;
238
- }
239
- }, {
240
- key: "componentWillUnmount",
241
- value: function componentWillUnmount() {
242
- var _a, _b, _c, _d, _e, _f;
243
- this.$el = null;
244
- if (this.mySwiper) this.mySwiper.destroy();
245
- (_b = (_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect) === null || _b === void 0 ? void 0 : _b.call(_a);
246
- (_d = (_c = this.observerFirst) === null || _c === void 0 ? void 0 : _c.disconnect) === null || _d === void 0 ? void 0 : _d.call(_c);
247
- (_f = (_e = this.observerLast) === null || _e === void 0 ? void 0 : _e.disconnect) === null || _f === void 0 ? void 0 : _f.call(_e);
248
- }
249
- }, {
250
- key: "handleOnChange",
251
- value: function handleOnChange(e) {
252
- var func = this.props.onChange;
253
- typeof func === 'function' && func(e);
191
+ this.mySwiper.update(); // 更新子元素
254
192
  }
255
- }, {
256
- key: "handleOnAnimationFinish",
257
- value: function handleOnAnimationFinish(e) {
258
- var func = this.props.onAnimationFinish;
259
- typeof func === 'function' && func(e);
260
- }
261
- }, {
262
- key: "parsePX",
263
- value: function parsePX() {
264
- var s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0px';
265
- return parseFloat(s.replace(/r*px/i, ''));
193
+ }
194
+
195
+ componentDidUpdate(preProps) {
196
+ if (preProps.children.length === 0 && this.props.children.length > 0) {
197
+ this.mySwiper.loopDestroy();
198
+ this.mySwiper.loopCreate();
266
199
  }
267
- }, {
268
- key: "render",
269
- value: function render() {
270
- var _this3 = this;
271
- var _this$props2 = this.props,
272
- className = _this$props2.className,
273
- style = _this$props2.style,
274
- vertical = _this$props2.vertical,
275
- previousMargin = _this$props2.previousMargin,
276
- nextMargin = _this$props2.nextMargin,
277
- indicatorColor = _this$props2.indicatorColor,
278
- indicatorActiveColor = _this$props2.indicatorActiveColor;
279
- var defaultIndicatorColor = indicatorColor || 'rgba(0, 0, 0, .3)';
280
- var defaultIndicatorActiveColor = indicatorActiveColor || '#000';
281
- var cls = classNames("taro-swiper-".concat(this._id), className);
282
- var sty = Object.assign({
283
- paddingTop: vertical ? this.parsePX(previousMargin) : 0,
284
- paddingRight: vertical ? 0 : this.parsePX(nextMargin),
285
- paddingBottom: vertical ? this.parsePX(nextMargin) : 0,
286
- paddingLeft: vertical ? 0 : this.parsePX(previousMargin),
287
- overflow: 'hidden'
288
- }, style);
289
- var paginationCls = classNames('swiper-pagination', {
290
- 'swiper-pagination-hidden': !this.props.indicatorDots,
291
- 'swiper-pagination-bullets': this.props.indicatorDots
292
- });
293
- return React.createElement("div", {
294
- className: "swiper-container-wrapper ".concat(cls),
295
- style: sty
296
- }, React.createElement("div", {
297
- className: 'swiper-container',
298
- style: {
299
- overflow: 'visible'
300
- },
301
- ref: function ref(el) {
302
- _this3.$el = el;
303
- }
304
- }, React.createElement("div", {
305
- dangerouslySetInnerHTML: {
306
- __html: "<style type='text/css'>\n .taro-swiper-".concat(this._id, " > .swiper-container > .swiper-pagination > .swiper-pagination-bullet { background: ").concat(defaultIndicatorColor, " }\n .taro-swiper-").concat(this._id, " > .swiper-container > .swiper-pagination > .swiper-pagination-bullet-active { background: ").concat(defaultIndicatorActiveColor, " }\n </style>")
307
- }
308
- }), React.createElement("div", {
309
- className: 'swiper-wrapper'
310
- }, this.props.children), React.createElement("div", {
311
- className: paginationCls
312
- })));
200
+ if (!this.mySwiper) return;
201
+ if (this.props.autoplay) {
202
+ if (this._$width !== this.mySwiper.width || this._$height !== this.mySwiper.height) {
203
+ this.mySwiper.autoplay.start();
204
+ }
313
205
  }
314
- }]);
315
- return Swiper;
316
- }(React.Component);
206
+ this._$width = this.mySwiper.width;
207
+ this._$height = this.mySwiper.height;
208
+ }
209
+ componentWillUnmount() {
210
+ var _a, _b, _c, _d, _e, _f;
211
+ this.$el = null;
212
+ if (this.mySwiper) this.mySwiper.destroy();
213
+ (_b = (_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect) === null || _b === void 0 ? void 0 : _b.call(_a);
214
+ (_d = (_c = this.observerFirst) === null || _c === void 0 ? void 0 : _c.disconnect) === null || _d === void 0 ? void 0 : _d.call(_c);
215
+ (_f = (_e = this.observerLast) === null || _e === void 0 ? void 0 : _e.disconnect) === null || _f === void 0 ? void 0 : _f.call(_e);
216
+ }
217
+ handleOnChange(e) {
218
+ const func = this.props.onChange;
219
+ typeof func === 'function' && func(e);
220
+ }
221
+ handleOnAnimationFinish(e) {
222
+ const func = this.props.onAnimationFinish;
223
+ typeof func === 'function' && func(e);
224
+ }
225
+ parsePX() {
226
+ let s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0px';
227
+ return parseFloat(s.replace(/r*px/i, ''));
228
+ }
229
+ render() {
230
+ const {
231
+ className,
232
+ style,
233
+ vertical,
234
+ previousMargin,
235
+ nextMargin,
236
+ indicatorColor,
237
+ indicatorActiveColor
238
+ } = this.props;
239
+ const defaultIndicatorColor = indicatorColor || 'rgba(0, 0, 0, .3)';
240
+ const defaultIndicatorActiveColor = indicatorActiveColor || '#000';
241
+ const cls = classNames(`taro-swiper-${this._id}`, className);
242
+ const sty = Object.assign({
243
+ paddingTop: vertical ? this.parsePX(previousMargin) : 0,
244
+ paddingRight: vertical ? 0 : this.parsePX(nextMargin),
245
+ paddingBottom: vertical ? this.parsePX(nextMargin) : 0,
246
+ paddingLeft: vertical ? 0 : this.parsePX(previousMargin),
247
+ overflow: 'hidden'
248
+ }, style);
249
+ const paginationCls = classNames('swiper-pagination', {
250
+ 'swiper-pagination-hidden': !this.props.indicatorDots,
251
+ 'swiper-pagination-bullets': this.props.indicatorDots
252
+ });
253
+ return React.createElement("div", {
254
+ className: `swiper-container-wrapper ${cls}`,
255
+ style: sty
256
+ }, React.createElement("div", {
257
+ className: 'swiper-container',
258
+ style: {
259
+ overflow: 'visible'
260
+ },
261
+ ref: el => {
262
+ this.$el = el;
263
+ }
264
+ }, React.createElement("div", {
265
+ dangerouslySetInnerHTML: {
266
+ __html: `<style type='text/css'>
267
+ .taro-swiper-${this._id} > .swiper-container > .swiper-pagination > .swiper-pagination-bullet { background: ${defaultIndicatorColor} }
268
+ .taro-swiper-${this._id} > .swiper-container > .swiper-pagination > .swiper-pagination-bullet-active { background: ${defaultIndicatorActiveColor} }
269
+ </style>`
270
+ }
271
+ }), React.createElement("div", {
272
+ className: 'swiper-wrapper'
273
+ }, this.props.children), React.createElement("div", {
274
+ className: paginationCls
275
+ })));
276
+ }
277
+ }
317
278
 
318
279
  export { Swiper, SwiperItem };
319
280
  //# sourceMappingURL=index.js.map