Skip to content

Commit

Permalink
fix: swipe bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sanqi-med committed Jan 19, 2024
1 parent 03db543 commit 463a41d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/quark-react/src/type/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export interface baseInterface
HTMLElement
> {
name?: string;
className?: string;
key?: string | number;
}
export type componentBaseInterface = Omit<
baseInterface,
Expand Down
22 changes: 13 additions & 9 deletions packages/quarkd/src/swipe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export interface CustomEvent {
@customElement({ tag: "quark-swipe-item", style: swipeItemStyle })
class QuarkSwipeItem extends QuarkElement {
componentDidMount() {
const parentNode = this.parentNode as QuarkSwipe;
if (parentNode && parentNode.moveWidth) {
this.style.width = `${parentNode.moveWidth}px`;
}
requestAnimationFrame(() => {
const parentNode = this.parentNode as QuarkSwipe;
if (parentNode && parentNode.moveWidth) {
this.style.width = `${parentNode.moveWidth}px`;
}
});
}

render() {
Expand Down Expand Up @@ -91,11 +93,13 @@ class QuarkSwipe extends QuarkElement {
timer: any = null;

componentDidMount() {
const { offsetWidth } = this;
this.currentIndex = this.defaultindex;
this.moveWidth = offsetWidth;
const offset = this.getOffset();
this.swipeChild(offset, false);
requestAnimationFrame(() => {
const { offsetWidth } = this;
this.currentIndex = this.defaultindex;
this.moveWidth = offsetWidth;
const offset = this.getOffset();
this.swipeChild(offset, false);
});
}

componentWillUnmount() {
Expand Down

0 comments on commit 463a41d

Please sign in to comment.