@gm-mobile/react 1.1.6 → 1.1.7-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-mobile/react",
3
- "version": "1.1.6",
3
+ "version": "1.1.7-beta.3",
4
4
  "description": "",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-mobile#readme",
@@ -27,8 +27,8 @@
27
27
  "dependencies": {
28
28
  "@gm-common/number": "^2.2.9",
29
29
  "@gm-common/tool": "^2.2.9",
30
- "@gm-mobile/locales": "^1.1.6",
30
+ "@gm-mobile/locales": "^1.1.7-beta.3",
31
31
  "classnames": "^2.2.6"
32
32
  },
33
- "gitHead": "986c6402ca51357b144807b533a6575371602783"
33
+ "gitHead": "c01b6364ab1229c2e7e139423930ab01859f5924"
34
34
  }
@@ -51,10 +51,10 @@ const Picker = ({
51
51
  onChange={handleChange}
52
52
  />
53
53
  ))}
54
- <div
54
+ {/* <div
55
55
  className='m-picker-highlight m-border-1px-top-before m-border-1px-bottom-after'
56
56
  style={highlightStyle}
57
- />
57
+ /> */}
58
58
  </div>
59
59
  </div>
60
60
  )
@@ -12,21 +12,22 @@ class PickerColumn extends React.Component {
12
12
  startScrollerTranslate: 0,
13
13
  ...this.computeTranslate(props),
14
14
  }
15
+ this.divRef = React.createRef()
15
16
  }
16
17
 
17
- componentDidMount() {
18
- ReactDOM.findDOMNode(this.refScroll).addEventListener(
19
- 'touchmove',
20
- this.handleTouchMove
21
- )
22
- }
18
+ // componentDidMount() {
19
+ // ReactDOM.findDOMNode(this.refScroll).addEventListener(
20
+ // 'touchmove',
21
+ // this.handleTouchMove
22
+ // )
23
+ // }
23
24
 
24
- componentWillUnmount() {
25
- ReactDOM.findDOMNode(this.refScroll).removeEventListener(
26
- 'touchmove',
27
- this.handleTouchMove
28
- )
29
- }
25
+ // componentWillUnmount() {
26
+ // ReactDOM.findDOMNode(this.refScroll).removeEventListener(
27
+ // 'touchmove',
28
+ // this.handleTouchMove
29
+ // )
30
+ // }
30
31
 
31
32
  componentWillReceiveProps(nextProps) {
32
33
  if (this.state.isMoving) {
@@ -36,7 +37,7 @@ class PickerColumn extends React.Component {
36
37
  }
37
38
 
38
39
  computeTranslate = (props) => {
39
- const { options, value, itemHeight, columnHeight } = props
40
+ const { options, value, columnHeight } = props
40
41
  let selectedIndex = _.findIndex(options, (option) => option.value === value)
41
42
  if (selectedIndex < 0) {
42
43
  // throw new ReferenceError();
@@ -50,10 +51,16 @@ class PickerColumn extends React.Component {
50
51
  this.handleOptionSelected(options[0])
51
52
  selectedIndex = 0
52
53
  }
53
-
54
+ // 获取到当前元素的高度
55
+ const itemHeight =
56
+ this.divRef?.current?.childNodes?.[selectedIndex]?.clientHeight ?? 40
57
+ let addHeight = 40
58
+ // 计算translate3d要移动的距离
59
+ for (let i = 0; i < selectedIndex; i++) {
60
+ addHeight += this.divRef?.current?.childNodes?.[i]?.clientHeight ?? 40
61
+ }
54
62
  return {
55
- scrollerTranslate:
56
- columnHeight / 2 - itemHeight / 2 - selectedIndex * itemHeight,
63
+ scrollerTranslate: columnHeight / 2 - itemHeight / 2 - addHeight,
57
64
  minTranslate:
58
65
  columnHeight / 2 - itemHeight * options.length + itemHeight / 2,
59
66
  maxTranslate: columnHeight / 2 - itemHeight / 2,
@@ -153,11 +160,17 @@ class PickerColumn extends React.Component {
153
160
  const { options, renderOption, itemHeight, value } = this.props
154
161
  return options.map((option, index) => {
155
162
  const style = {
156
- height: itemHeight + 'px',
157
- lineHeight: itemHeight + 'px',
163
+ minHeight: itemHeight + 'px',
164
+ // height: itemHeight + 'px',
165
+ // lineHeight: itemHeight + 'px',
166
+ display: 'flex',
167
+ justifyContent: 'center',
168
+ alignItems: 'center',
158
169
  }
159
170
  const className = `m-picker-item${
160
- option.value === value ? ' m-picker-item-selected' : ''
171
+ option.value === value
172
+ ? ' m-picker-highlight m-picker-item-selected m-border-1px-top-before m-border-1px-bottom-after'
173
+ : ''
161
174
  }`
162
175
  return (
163
176
  <div
@@ -187,7 +200,8 @@ class PickerColumn extends React.Component {
187
200
  return (
188
201
  <div className='m-picker-column'>
189
202
  <div
190
- ref={(ref) => (this.refScroll = ref)}
203
+ // ref={(ref) => (this.refScroll = ref)}
204
+ ref={this.divRef}
191
205
  className='m-picker-scroll'
192
206
  style={style}
193
207
  onTouchStart={this.handleTouchStart}
@@ -50,10 +50,10 @@
50
50
  .m-picker-item {
51
51
  position: relative;
52
52
  padding: 0 4px;
53
- white-space: nowrap;
53
+ // white-space: nowrap;
54
54
  color: var(--m-color-desc);
55
- overflow: hidden;
56
- text-overflow: ellipsis;
55
+ // overflow: hidden;
56
+ // text-overflow: ellipsis;
57
57
  cursor: pointer;
58
58
 
59
59
  &.m-picker-item-selected {