taro-ui 3.2.2 → 3.3.1

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.
@@ -17,14 +17,16 @@ function delayQuerySelector(
17
17
  delayTime = 500
18
18
  ): Promise<any[]> {
19
19
  return new Promise(resolve => {
20
- const selector: SelectorQuery = Taro.createSelectorQuery()
21
- delay(delayTime).then(() => {
22
- selector
23
- .select(selectorStr)
24
- .boundingClientRect()
25
- .exec((res: any[]) => {
26
- resolve(res)
27
- })
20
+ Taro.nextTick(() => {
21
+ const selector: SelectorQuery = Taro.createSelectorQuery()
22
+ delay(delayTime).then(() => {
23
+ selector
24
+ .select(selectorStr)
25
+ .boundingClientRect()
26
+ .exec((res: any[]) => {
27
+ resolve(res)
28
+ })
29
+ })
28
30
  })
29
31
  })
30
32
  }
@@ -212,13 +214,8 @@ function handleTouchScroll(flag: any): void {
212
214
 
213
215
  function pxTransform(size: number): string {
214
216
  if (!size) return ''
215
- const designWidth = 750
216
- const deviceRatio = {
217
- 640: 2.34 / 2,
218
- 750: 1,
219
- 828: 1.81 / 2
220
- }
221
- return `${size / deviceRatio[designWidth]}rpx`
217
+
218
+ return Taro.pxTransform(size)
222
219
  }
223
220
 
224
221
  function objectToString(style: object | string): string {
@@ -31,6 +31,7 @@ export default class AtIndexes extends React.Component<
31
31
  private listId: string
32
32
  private timeoutTimer: NodeJS.Timeout | number | undefined
33
33
  private listRef: any
34
+ private indexMap: { key: string; startHeight: number; endHeight: number }[]
34
35
 
35
36
  public constructor(props: AtIndexesProps) {
36
37
  super(props)
@@ -39,7 +40,8 @@ export default class AtIndexes extends React.Component<
39
40
  _scrollTop: 0,
40
41
  _tipText: '',
41
42
  _isShowToast: false,
42
- isWEB: Taro.getEnv() === Taro.ENV_TYPE.WEB
43
+ isWEB: Taro.getEnv() === Taro.ENV_TYPE.WEB,
44
+ currentIndex: -1
43
45
  }
44
46
  // 右侧导航高度
45
47
  this.menuHeight = 0
@@ -50,6 +52,7 @@ export default class AtIndexes extends React.Component<
50
52
  // 当前索引
51
53
  this.currentIndex = -1
52
54
  this.listId = isTest() ? 'indexes-list-AOTU2018' : `list-${uuid()}`
55
+ this.indexMap = []
53
56
  }
54
57
 
55
58
  private handleClick = (item: Item): void => {
@@ -136,23 +139,65 @@ export default class AtIndexes extends React.Component<
136
139
  }
137
140
  }
138
141
 
139
- private initData(): void {
142
+ private async initData(): Promise<void> {
140
143
  delayQuerySelector('.at-indexes__menu').then(rect => {
141
144
  const len = this.props.list.length
142
145
  this.menuHeight = rect[0].height
143
146
  this.startTop = rect[0].top
144
147
  this.itemHeight = Math.floor(this.menuHeight / (len + 1))
145
148
  })
149
+
150
+ const headerHeight =
151
+ (await delayQuerySelector('#at-indexes__top'))?.[0]?.height || 0
152
+ const itemHeight =
153
+ (await delayQuerySelector('.at-list__item'))?.[0].height || 0
154
+ const titleHeight =
155
+ (await delayQuerySelector('.at-indexes__list-title'))?.[0].height || 0
156
+
157
+ this.indexMap = []
158
+ this.props.list.forEach((dataList, i) => {
159
+ if (i === 0) {
160
+ this.indexMap.push({
161
+ key: dataList.key,
162
+ startHeight: headerHeight,
163
+ endHeight:
164
+ dataList.items.length * itemHeight + headerHeight + titleHeight
165
+ })
166
+ } else {
167
+ const prev = this.indexMap[i - 1]
168
+ this.indexMap.push({
169
+ key: dataList.key,
170
+ startHeight: prev.endHeight,
171
+ endHeight:
172
+ prev.endHeight + dataList.items.length * itemHeight + titleHeight
173
+ })
174
+ }
175
+ })
146
176
  }
147
177
 
148
178
  private handleScroll(e: CommonEvent): void {
149
179
  if (e && e.detail) {
180
+ const scrollTop = e.detail.scrollTop
181
+
150
182
  this.setState({
151
- _scrollTop: e.detail.scrollTop
183
+ _scrollTop: scrollTop
152
184
  })
185
+
186
+ this.getAnchorIndex(scrollTop)
153
187
  }
154
188
  }
155
189
 
190
+ // 根据滚动高度,判断当前应该显示的索引值
191
+ private getAnchorIndex(scrollTop: number) {
192
+ const index = this.indexMap.findIndex(item => {
193
+ return scrollTop >= item.startHeight && scrollTop < item.endHeight
194
+ })
195
+
196
+ this.setState({
197
+ currentIndex: index
198
+ })
199
+ }
200
+
156
201
  public UNSAFE_componentWillReceiveProps(nextProps: AtIndexesProps): void {
157
202
  if (nextProps.list.length !== this.props.list.length) {
158
203
  this.initData()
@@ -178,7 +223,8 @@ export default class AtIndexes extends React.Component<
178
223
  _scrollIntoView,
179
224
  _tipText,
180
225
  _isShowToast,
181
- isWEB
226
+ isWEB,
227
+ currentIndex
182
228
  } = this.state
183
229
 
184
230
  const toastStyle = { minWidth: pxTransform(100) }
@@ -189,7 +235,9 @@ export default class AtIndexes extends React.Component<
189
235
  const targetView = `at-indexes__list-${key}`
190
236
  return (
191
237
  <View
192
- className='at-indexes__menu-item'
238
+ className={classNames('at-indexes__menu-item', {
239
+ 'at-indexes__menu-item--active': currentIndex === i
240
+ })}
193
241
  key={key}
194
242
  onClick={this.jumpTarget.bind(this, targetView, i + 1)}
195
243
  >
@@ -198,16 +198,16 @@ AtListItem.defaultProps = {
198
198
  }
199
199
 
200
200
  AtListItem.propTypes = {
201
- note: PropTypes.string,
201
+ note: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
202
202
  disabled: PropTypes.bool,
203
- title: PropTypes.string,
203
+ title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
204
204
  thumb: PropTypes.string,
205
205
  onClick: PropTypes.func,
206
206
  isSwitch: PropTypes.bool,
207
207
  hasBorder: PropTypes.bool,
208
208
  switchColor: PropTypes.string,
209
209
  switchIsCheck: PropTypes.bool,
210
- extraText: PropTypes.string,
210
+ extraText: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
211
211
  extraThumb: PropTypes.string,
212
212
  onSwitchChange: PropTypes.func,
213
213
  arrow: PropTypes.oneOf(['up', 'down', 'right']),
@@ -21,11 +21,10 @@ export default class AtSwipeAction extends React.Component<
21
21
  private maxOffsetSize: number
22
22
  private moveX: number
23
23
  private eleWidth: number
24
- private moveRatio: number
25
24
 
26
25
  public constructor(props: AtSwipeActionProps) {
27
26
  super(props)
28
- const { isOpened, maxDistance, areaWidth, moveRatio } = props
27
+ const { isOpened, maxDistance, areaWidth } = props
29
28
  this.maxOffsetSize = maxDistance
30
29
  this.state = {
31
30
  componentId: uuid(),
@@ -36,7 +35,6 @@ export default class AtSwipeAction extends React.Component<
36
35
  }
37
36
  this.moveX = this.state.offsetSize
38
37
  this.eleWidth = areaWidth
39
- this.moveRatio = moveRatio || 0.5
40
38
  }
41
39
 
42
40
  public UNSAFE_componentWillReceiveProps(nextProps: AtSwipeActionProps): void {
@@ -108,22 +106,8 @@ export default class AtSwipeAction extends React.Component<
108
106
  }
109
107
 
110
108
  onTouchEnd = e => {
111
- if (this.moveX === -this.maxOffsetSize) {
112
- this._reset(true)
113
- this.handleOpened(e)
114
- return
115
- }
116
- if (this.moveX === 0) {
117
- this._reset(false)
118
- this.handleClosed(e)
119
- return
120
- }
121
- if (this.state._isOpened && this.moveX < 0) {
122
- this._reset(false)
123
- this.handleClosed(e)
124
- return
125
- }
126
- if (Math.abs(this.moveX) < this.maxOffsetSize * this.moveRatio) {
109
+ const { maxOffsetSize } = this.state
110
+ if (Math.abs(this.moveX) < maxOffsetSize / 2) {
127
111
  this._reset(false)
128
112
  this.handleClosed(e)
129
113
  } else {
package/types/button.d.ts CHANGED
@@ -1,13 +1,27 @@
1
- import { MouseEvent, ComponentClass } from 'react'
1
+ import { ComponentClass } from 'react'
2
2
  import { CommonEventFunction } from '@tarojs/components/types/common'
3
3
  import { ButtonProps } from '@tarojs/components/types/Button'
4
4
 
5
5
  import AtComponent from './base'
6
6
 
7
- type TaroButtonProps = Pick<ButtonProps, 'formType' | 'openType' |
8
- 'lang' | 'sessionFrom' | 'sendMessageTitle' | 'sendMessagePath' |
9
- 'sendMessageImg' | 'showMessageCard' | 'appParameter' | 'onContact' |
10
- 'onGetUserInfo' | 'onGetPhoneNumber' | 'onOpenSetting' | 'onError'>
7
+ type TaroButtonProps = Pick<
8
+ ButtonProps,
9
+ | 'formType'
10
+ | 'openType'
11
+ | 'lang'
12
+ | 'sessionFrom'
13
+ | 'sendMessageTitle'
14
+ | 'sendMessagePath'
15
+ | 'sendMessageImg'
16
+ | 'showMessageCard'
17
+ | 'appParameter'
18
+ | 'onContact'
19
+ | 'onGetUserInfo'
20
+ | 'onGetPhoneNumber'
21
+ | 'onOpenSetting'
22
+ | 'onError'
23
+ | 'onChooseAvatar'
24
+ >
11
25
 
12
26
  export interface AtButtonProps extends AtComponent, TaroButtonProps {
13
27
  /**
@@ -68,6 +68,7 @@ export interface AtIndexesState {
68
68
  _tipText: string
69
69
  _isShowToast: boolean
70
70
  isWEB: boolean
71
+ currentIndex: number
71
72
  }
72
73
 
73
74
  declare const AtIndexes: ComponentClass<AtIndexesProps>
package/types/list.d.ts CHANGED
@@ -24,11 +24,11 @@ export interface AtListItemProps extends AtComponent {
24
24
  /**
25
25
  * 元素的描述信息
26
26
  */
27
- note?: string
27
+ note?: JSX.Element | string
28
28
  /**
29
29
  * 元素的标题
30
30
  */
31
- title?: string
31
+ title?: JSX.Element | string
32
32
  /**
33
33
  * 元素的主要缩略图
34
34
  */
@@ -40,7 +40,7 @@ export interface AtListItemProps extends AtComponent {
40
40
  /**
41
41
  * 额外信息的文本
42
42
  */
43
- extraText?: string
43
+ extraText?: JSX.Element | string
44
44
  /**
45
45
  * 额外信息的缩略图
46
46
  */
@@ -65,11 +65,6 @@ export interface AtSwipeActionProps extends AtComponent {
65
65
  * @deprecated 已废弃,无需设置 areaWidth
66
66
  */
67
67
  areaWidth?: number
68
-
69
- /**
70
- * 判断是否需要打开的比例阈值,即 滑块滑动距离 / 滑块最大滑动距离, 默认为 0.5
71
- */
72
- moveRatio?: number
73
68
  }
74
69
 
75
70
  export interface AtSwipeActionState {
@@ -24,17 +24,17 @@ export interface TabItem {
24
24
  /**
25
25
  * icon className 前缀,用于第三方字体图标库,
26
26
  * 比如想使用'fa fa-clock' 的图标,则传入 iconPrefixClass='fa' iconType='clock',
27
- * 参考[拓展图标库详细](https://taro-ui.taro.zone/#/docs/icon)
27
+ * 参考[拓展图标库详细](https://jd-opensource.github.io/taro-ui/#/docs/icon)
28
28
  */
29
29
  iconPrefixClass?: string
30
30
  /**
31
31
  * 未选中时展示的 icon 类型,可扩展第三方字体图标库,
32
- * 参考[拓展图标库详细](https://taro-ui.taro.zone/#/docs/icon)
32
+ * 参考[拓展图标库详细](https://jd-opensource.github.io/taro-ui/#/docs/icon)
33
33
  */
34
34
  iconType?: string
35
35
  /**
36
36
  * 选中时展示的 icon 类型,可扩展第三方字体图标库,
37
- * 参考[拓展图标库详细](https://taro-ui.taro.zone/#/docs/icon)
37
+ * 参考[拓展图标库详细](https://jd-opensource.github.io/taro-ui/#/docs/icon)
38
38
  */
39
39
  selectedIconType?: string
40
40
  /**
package/README.md DELETED
@@ -1,85 +0,0 @@
1
- # Taro UI
2
-
3
- [![NPM][npm-version-image]][npm-version-url] [![NPM Downloads][npm-downloads-image]][npm-downloads-url] [![david-dm][david-dm-image]][david-dm-url] [![License][license-image]][license-url]
4
-
5
- 一款基于 `Taro` 框架开发的多端 UI 组件库
6
-
7
- ## 特性
8
-
9
- - 基于 `Taro` 开发 UI 组件
10
- - 一套组件可以在 `微信小程序`,`支付宝小程序`,`百度小程序`,`H5`,`ReactNative` 多端适配运行
11
- - 提供友好的 API,可灵活的使用组件
12
-
13
- ## 关于 Taro
14
-
15
- Taro 是由 [凹凸实验室](https://aotu.io) 倾力打造的多端开发解决方案。现如今市面上端的形态多种多样,Web、ReactNative、微信小程序等各种端大行其道,当业务要求同时在不同的端都要求有所表现的时候,针对不同的端去编写多套代码的成本显然非常高,这时候只编写一套代码就能够适配到多端的能力就显得极为需要。
16
-
17
- 使用 Taro,我们可以只书写一套代码,再通过 Taro 的编译工具,将源代码分别编译出可以在不同端(微信小程序、H5、RN等)运行的代码。
18
-
19
- ## 体验
20
-
21
- 请使用微信扫一扫以下体验码
22
-
23
- ![QRCode](https://user-images.githubusercontent.com/1240899/46650700-25a4e600-cbd0-11e8-90ff-905edb39c340.jpg)
24
-
25
- ## 相关链接
26
-
27
- - [Taro UI 使用文档](https://taro-ui.taro.zone)
28
- - [Taro UI 官方示例](https://github.com/NervJS/taro-ui-demo)
29
- - [Taro](https://taro.jd.com/)
30
- - [Taro 物料市场](https://taro-ext.jd.com)
31
- - [Taro 论坛 Taro-UI 板块](https://taro-club.jd.com/category/11/taro-ui)
32
-
33
- ## 安装
34
-
35
- ### 2.x
36
- 当 Taro 版本 < 3 时,使用 2.x 版本
37
-
38
- ```bash
39
- $ npm install taro-ui@2.3.4
40
- ```
41
-
42
- ### 3.x
43
- 当 Taro 版本 ≥ 3 时,使用 3.x 版本
44
-
45
- ```bash
46
- $ npm install taro-ui@latest
47
- ```
48
-
49
- ## 使用
50
-
51
- 在代码中 `import` 需要的组件并按照文档说明使用
52
-
53
- ```js
54
- import { AtButton } from 'taro-ui'
55
- ```
56
-
57
- ## 开发交流
58
-
59
- [官方微信交流群](https://github.com/NervJS/taro-ui/issues/16)
60
-
61
- ## 开发计划
62
-
63
- [开发计划](./PLANS.md)
64
-
65
- ## 路线图
66
-
67
- ![Roadmap][roadmap-image]
68
-
69
- ## 贡献
70
-
71
- 如果你在使用 `Taro UI` 时遇到问题,或者有好的建议,欢迎给我们提 `Issue` 或 `Pull Request`。在开始之前,请阅读 [贡献指南](https://github.com/NervJS/taro-ui/blob/master/.github/CONTRIBUTING.md)
72
-
73
- ## License
74
-
75
- MIT
76
-
77
- [npm-version-image]: https://img.shields.io/npm/v/taro-ui.svg?style=flat-square
78
- [npm-version-url]: https://www.npmjs.com/package/taro-ui
79
- [npm-downloads-image]: https://img.shields.io/npm/dm/taro-ui?style=flat-square
80
- [npm-downloads-url]: https://www.npmjs.com/package/taro-ui
81
- [david-dm-image]: https://david-dm.org/NervJS/taro-ui.svg?style=flat-square
82
- [david-dm-url]: https://david-dm.org/NervJS/taro-ui
83
- [license-image]: https://img.shields.io/github/license/NervJS/taro-ui?style=flat-square
84
- [license-url]: https://github.com/NervJS/taro-ui/blob/master/LICENSE
85
- [roadmap-image]: ./docs/assets/taro-ui-roadmap.svg