Skip to content

Commit

Permalink
fix: 蜡烛图切换销毁scrollbar时移除对应事件
Browse files Browse the repository at this point in the history
  • Loading branch information
兵人 committed Jan 4, 2024
1 parent 3b5335d commit 954d885
Show file tree
Hide file tree
Showing 3 changed files with 2,339 additions and 12 deletions.
41 changes: 29 additions & 12 deletions packages/f2/src/components/zoom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export default (View) => {

loop: number;

bindedEvents = {}


constructor(props: P) {
const defaultProps = {
onPanStart: () => {},
Expand Down Expand Up @@ -219,7 +222,12 @@ export default (View) => {
}

didUnmount(): void {
const { chart } = this.props;
this._cancelAnimationFrame();
Object.entries(this.bindedEvents).forEach((item) => {
const [key, fn] = item || [];
key && chart.off(key, fn as any)
})
}

_requestAnimationFrame(calllback: Function) {
Expand Down Expand Up @@ -253,36 +261,45 @@ export default (View) => {

// 统一绑定事件
if (pan !== false) {
chart.on('panstart', () => {
this.bindedEvents['panstart'] = () => {
this.onStart();
onPanStart({ scale });
});
chart.on('pan', (ev) => {
}
this.bindedEvents['pan'] = (ev) => {
this.onPan(ev);
onPan(ev);
});
chart.on('panend', () => {
}
this.bindedEvents['panend'] = () => {
this.onEnd();
onPanEnd({ scale });
});
}

chart.on('panstart', this.bindedEvents['panstart']);
chart.on('pan', this.bindedEvents['pan']);
chart.on('panend', this.bindedEvents['panend']);
}

if (pinch !== false) {
chart.on('pinchstart', () => {
this.bindedEvents['pinchstart'] = () => {
this.onStart();
onPinchStart();
});
chart.on('pinch', (ev) => {
}
this.bindedEvents['pinch'] = (ev) => {
this.onPinch(ev);
onPinch(ev);
});
chart.on('pinchend', () => {
}
this.bindedEvents['pinchend'] = () => {
this.onEnd();
onPinchEnd({ scale });
});
}

chart.on('pinch', this.bindedEvents['pinch']);
chart.on('pinchstart', this.bindedEvents['pinchstart']);
chart.on('pinchend',this.bindedEvents['pinchend']);
}

if (swipe !== false) {
this.bindedEvents['swipe'] = this.onSwipe
chart.on('swipe', this.onSwipe);
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 954d885

Please sign in to comment.