Skip to content

Commit

Permalink
simplify codes (#17801)
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo authored Nov 8, 2024
1 parent 8904950 commit e4bf2e1
Showing 1 changed file with 15 additions and 81 deletions.
96 changes: 15 additions & 81 deletions cocos/ui/scroll-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToBottom (timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(0, 0, false, true);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta, true);
}
this._doScroll(0, 0, false, true, timeInSecond, attenuated);
}

/**
Expand All @@ -527,14 +520,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToTop (timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(0, 1, false, true);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(0, 1, false, true, timeInSecond, attenuated);
}

/**
Expand All @@ -554,14 +540,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToLeft (timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(0, 0, true, false);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(0, 0, true, false, timeInSecond, attenuated);
}

/**
Expand All @@ -581,14 +560,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToRight (timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(1, 0, true, false);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(1, 0, true, false, timeInSecond, attenuated);
}

/**
Expand All @@ -608,14 +580,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToTopLeft (timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(0, 1, true, true);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(0, 1, true, true, timeInSecond, attenuated);
}

/**
Expand All @@ -635,14 +600,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToTopRight (timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(1, 1, true, true);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(1, 1, true, true, timeInSecond, attenuated);
}

/**
Expand All @@ -662,14 +620,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToBottomLeft (timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(0, 0, true, true);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(0, 0, true, true, timeInSecond, attenuated);
}

/**
Expand All @@ -689,14 +640,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToBottomRight (timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(1, 0, true, true);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(1, 0, true, true, timeInSecond, attenuated);
}

/**
Expand Down Expand Up @@ -796,14 +740,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToPercentHorizontal (percent: number, timeInSecond: number, attenuated: boolean): void {
assignMoveDeltaOption(percent, 0, true, false);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(percent, 0, true, false, timeInSecond, attenuated);
}

/**
Expand All @@ -829,14 +766,7 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollTo (anchor: Vec2, timeInSecond?: number, attenuated?: boolean): void {
assignMoveDeltaOption(anchor.x, anchor.y, true, true);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
this._startAutoScroll(moveDelta, timeInSecond, attenuated);
} else {
this._moveContent(moveDelta);
}
this._doScroll(anchor.x, anchor.y, true, true, timeInSecond, attenuated);
}

/**
Expand All @@ -857,7 +787,11 @@ export class ScrollView extends ViewGroup {
* ```
*/
public scrollToPercentVertical (percent: number, timeInSecond?: number, attenuated?: boolean): void {
assignMoveDeltaOption(0, percent, false, true);
this._doScroll(0, percent, false, true, timeInSecond, attenuated);
}

private _doScroll (x: number, y: number, applyToHorizontal: boolean, applyToVertical: boolean, timeInSecond?: number, attenuated = true): void {
assignMoveDeltaOption(x, y, applyToHorizontal, applyToVertical);
const moveDelta = this._calculateMovePercentDelta(_moveDeltaOptions);

if (timeInSecond) {
Expand Down

0 comments on commit e4bf2e1

Please sign in to comment.