Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualList滚动后子组件的onClick不执行 #7137

Closed
peica opened this issue Jul 22, 2020 · 2 comments
Closed

VirtualList滚动后子组件的onClick不执行 #7137

peica opened this issue Jul 22, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@peica
Copy link

peica commented Jul 22, 2020

这个特性解决了什么问题?

const onClick = () => { console.log("onClick");}
const Row = React.memo(({ index, style, data }) => {
return (
<View className={index % 2 ? 'ListItemOdd' : 'ListItemEven'} style={style} onClick={onClick}>
Row {index}

);
})

function buildData (offset = 0) {
return Array(100).fill(0).map((_, i) => i offset);
}

export default class Index extends Component {
state = {
data: buildData(0),
}

loading = false

listReachBottom() {
Taro.showLoading()
// 如果 loading 与视图相关,那它就应该放在 this.state
// 我们这里使用的是一个同步的 API 调用 loading,所以不需要
this.loading = true
setTimeout(() => {
const { data } = this.state
this.setState({
data: data.concat(buildData(data.length))
}, () => {
this.loading = false;
Taro.hideLoading()
})
}, 1000)
}

render() {
const { data } = this.state
const dataLen = data.length
const itemSize = 100
return (
<VirtualList
className='List'
height={500}
itemData={data}
itemCount={dataLen}
itemSize={itemSize}
width='100%'
onScroll={({ scrollDirection, scrollOffset }) => {
if (
// 避免重复加载数据
!this.loading &&
// 只有往前滚动我们才触发
scrollDirection === 'forward' &&
// 5 = (列表高度 / 单项列表高度)
// 100 = 滚动提前加载量,可根据样式情况调整
scrollOffset > ((dataLen - 5) * itemSize 100)
) {
this.listReachBottom()
}
}}
>
{Row}

);
}
}

这个 API 长什么样?

期望滚动后,onClick还是能执行。

@taro-bot2 taro-bot2 bot added the enhancement New feature or request label Jul 22, 2020
@peica
Copy link
Author

peica commented Jul 22, 2020

在每次生成的css中,多了一个pointer-events: none;

@peica
Copy link
Author

peica commented Jul 22, 2020

#7140

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant