Skip to content

Commit

Permalink
Revert "Revert "修复AbsoluteList、Scroll 组件bug"" (#1481)
Browse files Browse the repository at this point in the history
This reverts commit a5afa35.

Co-authored-by: leo <[email protected]>
  • Loading branch information
leehaoChen and leehaoChen committed Jan 28, 2022
1 parent c13ddc3 commit ab2a74f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AnimationList/AbsoluteList.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export default function(List) {
}

componentDidUpdate(prevProps) {
if (shallowEqual(prevProps.value, this.props.value)) return
if (!this.props.focus) this.ajustdoc = false
if (shallowEqual(prevProps.value, this.props.value)) return
setTimeout(() => {
this.forceUpdate()
})
Expand Down
15 changes: 15 additions & 0 deletions src/Scroll/Scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Scroll extends PureComponent {
this.handleTouchStart = this.handleTouchStart.bind(this)
this.handleTouchMove = this.handleTouchMove.bind(this)
this.setStartPoint = this.setStartPoint.bind(this)
this.handleInnerScroll = this.handleInnerScroll.bind(this)
}

componentDidMount() {
Expand All @@ -48,6 +49,7 @@ class Scroll extends PureComponent {
this.wheelElement.addEventListener('wheel', this.handleWheel, { passive: false })
this.wheelElement.addEventListener('touchstart', this.handleTouchStart, { passive: true })
this.wheelElement.addEventListener('touchmove', this.handleTouchMove, { passive: false })
this.inner.addEventListener('scroll', this.handleInnerScroll)
}

componentDidUpdate(prevProps) {
Expand All @@ -61,6 +63,7 @@ class Scroll extends PureComponent {
this.wheelElement.removeEventListener('wheel', this.handleWheel)
this.wheelElement.removeEventListener('touchstart', this.handleTouchStart)
this.wheelElement.removeEventListener('touchmove', this.handleTouchMove)
this.inner.removeEventListener('scroll', this.handleInnerScroll)
}

getWheelRect() {
Expand Down Expand Up @@ -215,6 +218,18 @@ class Scroll extends PureComponent {
this.boundleScroll()
}

// inner scroll
handleInnerScroll(e) {
const { target } = e
const { left, scrollWidth } = this.props
const { width } = this.getWheelRect()
if (target.scrollLeft) {
this.handleScroll(left + target.scrollLeft / (scrollWidth - width), this.props.top, undefined, 0)
target.scrollLeft = 0
target.scrollTop = 0
}
}

render() {
const { children, scrollWidth, scrollHeight, left, top, scrollX, scrollY, style } = this.props
const { width, height } = this.getWheelRect()
Expand Down

0 comments on commit ab2a74f

Please sign in to comment.