taro-ui 3.2.2 → 3.3.0

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.
package/dist/index.js CHANGED
@@ -1424,13 +1424,15 @@ function delay(delayTime) {
1424
1424
  function delayQuerySelector(selectorStr, delayTime) {
1425
1425
  if (delayTime === void 0) { delayTime = 500; }
1426
1426
  return new Promise(function (resolve) {
1427
- var selector = Taro__default["default"].createSelectorQuery();
1428
- delay(delayTime).then(function () {
1429
- selector
1430
- .select(selectorStr)
1431
- .boundingClientRect()
1432
- .exec(function (res) {
1433
- resolve(res);
1427
+ Taro__default["default"].nextTick(function () {
1428
+ var selector = Taro__default["default"].createSelectorQuery();
1429
+ delay(delayTime).then(function () {
1430
+ selector
1431
+ .select(selectorStr)
1432
+ .boundingClientRect()
1433
+ .exec(function (res) {
1434
+ resolve(res);
1435
+ });
1434
1436
  });
1435
1437
  });
1436
1438
  });
@@ -1573,13 +1575,7 @@ function handleTouchScroll(flag) {
1573
1575
  function pxTransform(size) {
1574
1576
  if (!size)
1575
1577
  return '';
1576
- var designWidth = 750;
1577
- var deviceRatio = {
1578
- 640: 2.34 / 2,
1579
- 750: 1,
1580
- 828: 1.81 / 2
1581
- };
1582
- return "".concat(size / deviceRatio[designWidth], "rpx");
1578
+ return Taro__default["default"].pxTransform(size);
1583
1579
  }
1584
1580
  function objectToString$2(style) {
1585
1581
  if (style && typeof style === 'object') {
@@ -1609,18 +1605,6 @@ function mergeStyle(style1, style2) {
1609
1605
  return Object.assign({}, style1, style2);
1610
1606
  }
1611
1607
  return objectToString$2(style1) + objectToString$2(style2);
1612
- }
1613
- /**
1614
- * 自定义验证器,用于验证参数是否是 JSX.Element
1615
- * @param {any} props
1616
- * @param {string} propName
1617
- * @param {string} componentName
1618
- * @returns
1619
- */
1620
- function isJSXElement(props, propName, componentName) {
1621
- if (!React__default["default"].isValidElement(props[propName])) {
1622
- return new Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". It must be a valid JSX element."));
1623
- }
1624
1608
  }
1625
1609
 
1626
1610
  var AtLoading = /** @class */ (function (_super) {
@@ -2131,16 +2115,16 @@ AtListItem.defaultProps = {
2131
2115
  iconInfo: { value: '' }
2132
2116
  };
2133
2117
  AtListItem.propTypes = {
2134
- note: isJSXElement,
2118
+ note: propTypes.oneOfType([propTypes.string, propTypes.element]),
2135
2119
  disabled: propTypes.bool,
2136
- title: isJSXElement,
2120
+ title: propTypes.oneOfType([propTypes.string, propTypes.element]),
2137
2121
  thumb: propTypes.string,
2138
2122
  onClick: propTypes.func,
2139
2123
  isSwitch: propTypes.bool,
2140
2124
  hasBorder: propTypes.bool,
2141
2125
  switchColor: propTypes.string,
2142
2126
  switchIsCheck: propTypes.bool,
2143
- extraText: isJSXElement,
2127
+ extraText: propTypes.oneOfType([propTypes.string, propTypes.element]),
2144
2128
  extraThumb: propTypes.string,
2145
2129
  onSwitchChange: propTypes.func,
2146
2130
  arrow: propTypes.oneOf(['up', 'down', 'right']),
@@ -4518,8 +4502,7 @@ var AtTabs = /** @class */ (function (_super) {
4518
4502
  transformStyle = "translate3d(-".concat(current * 100, "%, 0px, 0px)");
4519
4503
  }
4520
4504
  Object.assign(bodyStyle, {
4521
- transform: transformStyle,
4522
- '-webkit-transform': transformStyle
4505
+ transform: transformStyle
4523
4506
  });
4524
4507
  if (!animated) {
4525
4508
  bodyStyle.transition = 'unset';
@@ -5171,22 +5154,7 @@ var AtSwipeAction = /** @class */ (function (_super) {
5171
5154
  };
5172
5155
  _this.onTouchEnd = function (e) {
5173
5156
  var maxOffsetSize = _this.state.maxOffsetSize;
5174
- if (_this.moveX === -maxOffsetSize) {
5175
- _this._reset(true);
5176
- _this.handleOpened(e);
5177
- return;
5178
- }
5179
- if (_this.moveX === 0) {
5180
- _this._reset(false);
5181
- _this.handleClosed(e);
5182
- return;
5183
- }
5184
- if (_this.state._isOpened && _this.moveX < 0) {
5185
- _this._reset(false);
5186
- _this.handleClosed(e);
5187
- return;
5188
- }
5189
- if (Math.abs(_this.moveX) < maxOffsetSize * _this.moveRatio) {
5157
+ if (Math.abs(_this.moveX) < maxOffsetSize / 2) {
5190
5158
  _this._reset(false);
5191
5159
  _this.handleClosed(e);
5192
5160
  }
@@ -5198,7 +5166,7 @@ var AtSwipeAction = /** @class */ (function (_super) {
5198
5166
  _this.onChange = function (e) {
5199
5167
  _this.moveX = e.detail.x;
5200
5168
  };
5201
- var isOpened = props.isOpened, moveRatio = props.moveRatio;
5169
+ var isOpened = props.isOpened;
5202
5170
  _this.state = {
5203
5171
  componentId: uuid(),
5204
5172
  // eslint-disable-next-line no-extra-boolean-cast
@@ -5209,7 +5177,6 @@ var AtSwipeAction = /** @class */ (function (_super) {
5209
5177
  maxOffsetSize: 0
5210
5178
  };
5211
5179
  _this.moveX = _this.state.offsetSize;
5212
- _this.moveRatio = moveRatio || 0.5;
5213
5180
  return _this;
5214
5181
  }
5215
5182
  AtSwipeAction.prototype.componentDidMount = function () {
@@ -6210,7 +6177,8 @@ var AtIndexes = /** @class */ (function (_super) {
6210
6177
  _scrollTop: 0,
6211
6178
  _tipText: '',
6212
6179
  _isShowToast: false,
6213
- isWEB: Taro__default["default"].getEnv() === Taro__default["default"].ENV_TYPE.WEB
6180
+ isWEB: Taro__default["default"].getEnv() === Taro__default["default"].ENV_TYPE.WEB,
6181
+ currentIndex: -1
6214
6182
  };
6215
6183
  // 右侧导航高度
6216
6184
  _this.menuHeight = 0;
@@ -6221,6 +6189,7 @@ var AtIndexes = /** @class */ (function (_super) {
6221
6189
  // 当前索引
6222
6190
  _this.currentIndex = -1;
6223
6191
  _this.listId = isTest() ? 'indexes-list-AOTU2018' : "list-".concat(uuid());
6192
+ _this.indexMap = [];
6224
6193
  return _this;
6225
6194
  }
6226
6195
  AtIndexes.prototype.jumpTarget = function (_scrollIntoView, idx) {
@@ -6278,21 +6247,69 @@ var AtIndexes = /** @class */ (function (_super) {
6278
6247
  }
6279
6248
  };
6280
6249
  AtIndexes.prototype.initData = function () {
6281
- var _this = this;
6282
- delayQuerySelector('.at-indexes__menu').then(function (rect) {
6283
- var len = _this.props.list.length;
6284
- _this.menuHeight = rect[0].height;
6285
- _this.startTop = rect[0].top;
6286
- _this.itemHeight = Math.floor(_this.menuHeight / (len + 1));
6250
+ var _a, _b, _c, _d;
6251
+ return __awaiter(this, void 0, void 0, function () {
6252
+ var headerHeight, itemHeight, titleHeight;
6253
+ var _this = this;
6254
+ return __generator(this, function (_e) {
6255
+ switch (_e.label) {
6256
+ case 0:
6257
+ delayQuerySelector('.at-indexes__menu').then(function (rect) {
6258
+ var len = _this.props.list.length;
6259
+ _this.menuHeight = rect[0].height;
6260
+ _this.startTop = rect[0].top;
6261
+ _this.itemHeight = Math.floor(_this.menuHeight / (len + 1));
6262
+ });
6263
+ return [4 /*yield*/, delayQuerySelector('#at-indexes__top')];
6264
+ case 1:
6265
+ headerHeight = ((_b = (_a = (_e.sent())) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.height) || 0;
6266
+ return [4 /*yield*/, delayQuerySelector('.at-list__item')];
6267
+ case 2:
6268
+ itemHeight = ((_c = (_e.sent())) === null || _c === void 0 ? void 0 : _c[0].height) || 0;
6269
+ return [4 /*yield*/, delayQuerySelector('.at-indexes__list-title')];
6270
+ case 3:
6271
+ titleHeight = ((_d = (_e.sent())) === null || _d === void 0 ? void 0 : _d[0].height) || 0;
6272
+ this.indexMap = [];
6273
+ this.props.list.forEach(function (dataList, i) {
6274
+ if (i === 0) {
6275
+ _this.indexMap.push({
6276
+ key: dataList.key,
6277
+ startHeight: headerHeight,
6278
+ endHeight: dataList.items.length * itemHeight + headerHeight + titleHeight
6279
+ });
6280
+ }
6281
+ else {
6282
+ var prev = _this.indexMap[i - 1];
6283
+ _this.indexMap.push({
6284
+ key: dataList.key,
6285
+ startHeight: prev.endHeight,
6286
+ endHeight: prev.endHeight + dataList.items.length * itemHeight + titleHeight
6287
+ });
6288
+ }
6289
+ });
6290
+ return [2 /*return*/];
6291
+ }
6292
+ });
6287
6293
  });
6288
6294
  };
6289
6295
  AtIndexes.prototype.handleScroll = function (e) {
6290
6296
  if (e && e.detail) {
6297
+ var scrollTop = e.detail.scrollTop;
6291
6298
  this.setState({
6292
- _scrollTop: e.detail.scrollTop
6299
+ _scrollTop: scrollTop
6293
6300
  });
6301
+ this.getAnchorIndex(scrollTop);
6294
6302
  }
6295
6303
  };
6304
+ // 根据滚动高度,判断当前应该显示的索引值
6305
+ AtIndexes.prototype.getAnchorIndex = function (scrollTop) {
6306
+ var index = this.indexMap.findIndex(function (item) {
6307
+ return scrollTop >= item.startHeight && scrollTop < item.endHeight;
6308
+ });
6309
+ this.setState({
6310
+ currentIndex: index
6311
+ });
6312
+ };
6296
6313
  AtIndexes.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
6297
6314
  if (nextProps.list.length !== this.props.list.length) {
6298
6315
  this.initData();
@@ -6311,13 +6328,15 @@ var AtIndexes = /** @class */ (function (_super) {
6311
6328
  AtIndexes.prototype.render = function () {
6312
6329
  var _this = this;
6313
6330
  var _a = this.props, className = _a.className, customStyle = _a.customStyle, animation = _a.animation, topKey = _a.topKey, list = _a.list;
6314
- var _b = this.state, _scrollTop = _b._scrollTop, _scrollIntoView = _b._scrollIntoView, _tipText = _b._tipText, _isShowToast = _b._isShowToast, isWEB = _b.isWEB;
6331
+ var _b = this.state, _scrollTop = _b._scrollTop, _scrollIntoView = _b._scrollIntoView, _tipText = _b._tipText, _isShowToast = _b._isShowToast, isWEB = _b.isWEB, currentIndex = _b.currentIndex;
6315
6332
  var toastStyle = { minWidth: pxTransform(100) };
6316
6333
  var rootCls = classnames('at-indexes', className);
6317
6334
  var menuList = list.map(function (dataList, i) {
6318
6335
  var key = dataList.key;
6319
6336
  var targetView = "at-indexes__list-".concat(key);
6320
- return (React__default["default"].createElement(components.View, { className: 'at-indexes__menu-item', key: key, onClick: _this.jumpTarget.bind(_this, targetView, i + 1) }, key));
6337
+ return (React__default["default"].createElement(components.View, { className: classnames('at-indexes__menu-item', {
6338
+ 'at-indexes__menu-item--active': currentIndex === i
6339
+ }), key: key, onClick: _this.jumpTarget.bind(_this, targetView, i + 1) }, key));
6321
6340
  });
6322
6341
  var indexesList = list.map(function (dataList) { return (React__default["default"].createElement(components.View, { id: "at-indexes__list-".concat(dataList.key), className: 'at-indexes__list', key: dataList.key },
6323
6342
  React__default["default"].createElement(components.View, { className: 'at-indexes__list-title' }, dataList.title),