teaset icon indicating copy to clipboard operation
teaset copied to clipboard

SegmentedBar autoScroll=true时 x位置计算存在问题

Open heartsoul opened this issue 6 years ago • 6 comments

此函数计算 滚动条位置不正确,相见以下代码 updateIndicator() { if (!this._indicatorX || !this._indicatorWidth) return;

...

if (this.props.autoScroll && this.refs.scrollView) {
  let contextWidth = 0;
  this._buttonsLayout.map(item => contextWidth += item.width);
  let x = indicatorXValue + indicatorWidthValue / 2 - this._scrollViewWidth / 2;
  if (x < 0) {
    x = 0;
  } else if (x > contextWidth - this._scrollViewWidth) {
    x = contextWidth - this._scrollViewWidth;
  }

line 162: /* 这里x会存下小于0的情形(contextWidth < this._scrollViewWidth) 在 x 小于0时,滚动条会将内容整体滚动到右侧,用户视觉体验较差。 增加下面的x的判断代码后,就可以正常了:) / /
if (x < 0) { x = 0; } // console.log('\n>>>>>>this.refs.scrollView.scrollTo:\n'+JSON.stringify({contextWidth:contextWidth,scrollViewWidth:this._scrollViewWidth,x: x, y: 0, animated: this.props.animated})); */ this.refs.scrollView.scrollTo({x: x, y: 0, animated: this.props.animated}); } }

heartsoul avatar Sep 30 '18 01:09 heartsoul

if (x < 0) { x = 0; } 我看的源码这个已经存在,但晒ios 还是存在滚动调滚动到右侧问题

zsswlr avatar Nov 08 '18 07:11 zsswlr

非常感谢,原来是再添加这一行,完美解决~ 非常感谢。。

zsswlr avatar Nov 08 '18 08:11 zsswlr

:) 希望代码能更新一下,解决这个问题

heartsoul avatar Nov 15 '18 09:11 heartsoul

:) 希望代码能更新一下,解决这个问题

你发一个代码合并不就好了,等作者合并

orzhtml avatar Dec 19 '18 03:12 orzhtml

image 我们这边遇到的问题是. 数据加载后,x先在0的位置, 后又位移一定数值, 主要原因还是 componentDidUpdate不断调用

我这边粗暴处理了

SegmentedBar.js中添加

image

image

组件使用: image

tianNanYiHao avatar Oct 25 '22 08:10 tianNanYiHao

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

zsswlr avatar Oct 25 '22 08:10 zsswlr