zarm icon indicating copy to clipboard operation
zarm copied to clipboard

picker-view组件无法滚动的问题

Open busy-dog opened this issue 4 years ago • 2 comments

Description

偶现: 二次封装picker-view组件后, 发现有时候wheel部分无法滚动

Steps to Reproduce

  1. 将picker-view所需级联数据异步多次加载

Error Trace (if possible)

better-scroll需要在页面渲染完成后创建 否则在数据加载完成前创建会导致高度计算错误

Solution

  1. 修改wheel组件
componentDidMount() {
    setTimeout(() => { this.createBScroll() })
}

createBScroll = () => {
    const value = getValue(this.props);
    const { dataSource } = this.props;
    const initIndex = this.getSelectedIndex(value, dataSource);
    const wheel = { selectedIndex: initIndex, wheelWrapperClass: `wheel-content`, wheelItemClass: `wheel__item` }
    this.BScroll = new BScroll(this.wrapper, { wheel, probeType: 3 });
    this.props.disabled && this.BScroll.disable();
    this.BScroll.on("scrollEnd", () => { this.handleScrollEnd() });
}

Environment

  • zarm version: v2.9.2
  • react/react-native version: 16.13.1
  • system version: macos 11.2
  • browser version: chrome 91.0.4472.114(正式版本) (x86_64)

You can get this information from package.json and your device.

busy-dog avatar Jun 27 '21 07:06 busy-dog

将picker-view所需级联数据异步多次加载

请问下可以简单用代码描述下这个操作嘛?

edison-hm avatar Jun 28 '21 08:06 edison-hm

将picker-view需要级联数据异步多个加载

好像下可以简单用代码描述下这个操作嘛?

for (let $i = 0; $i < cascade; $i++) {
    const { value: previous } = this.state
    const parent = previous[$i - 1] || undefined
    const current: DATASOURCE = await requestOptions(name, parent, previous)
    const options = this.state.options.map((e, i) => i === $i ? current : e)
    const value = previous?.map((e, i) => (!e && i === $i) ? current[0]?.value : e)
    await this.asyncSetState({ options, value })
}

busy-dog avatar Jun 28 '21 10:06 busy-dog