Skip to content

Commit 48a9bf5

Browse files
committed
feat: update scrollProgress on move
1 parent acd6013 commit 48a9bf5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/state-api/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const flickingStateApiAdapter: ReactiveSetupAdapter<FlickingStateApi, FlickingRe
7272
reactiveObj.isReachEnd = getIsReachEnd(flicking);
7373
reactiveObj.currentPanelIndex = getCurrentPanelIndex(flicking);
7474
reactiveObj.indexProgress = getProgressByPanelIndex(flicking);
75-
reactiveObj.scrollProgress = getProgressByScrollPos(flicking);
7675
};
7776

7877
const onPanelChange = () => {
@@ -82,6 +81,12 @@ const flickingStateApiAdapter: ReactiveSetupAdapter<FlickingStateApi, FlickingRe
8281
reactiveObj.totalPanelCount = getTotalPanelCount(flicking);
8382
};
8483

84+
const onMove = () => {
85+
if (flicking === null) return;
86+
87+
reactiveObj.scrollProgress = getProgressByScrollPos(flicking);
88+
};
89+
8590
onInit((inst, data) => {
8691
flicking = data.flicking;
8792
if (flicking === null) return;
@@ -96,11 +101,13 @@ const flickingStateApiAdapter: ReactiveSetupAdapter<FlickingStateApi, FlickingRe
96101

97102
flicking?.on("changed", onChanged);
98103
flicking?.on("panelChange", onPanelChange);
104+
flicking?.on("move", onMove);
99105
});
100106

101107
onDestroy(() => {
102108
flicking?.off("changed", onChanged);
103109
flicking?.off("panelChange", onPanelChange);
110+
flicking?.off("move", onMove);
104111
});
105112

106113
return reactiveObj;

test/unit/state-api/state-api.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe("State API", () => {
2626
expect(stateApi.isReachEnd).to.be.false;
2727
expect(stateApi.totalPanelCount).to.equal(3);
2828
expect(stateApi.currentPanelIndex).to.equal(0);
29-
expect(stateApi.progress).to.equal(0);
29+
expect(stateApi.indexProgress).to.equal(0);
30+
expect(stateApi.scrollProgress).to.equal(0);
3031
});
3132
});
3233

@@ -39,7 +40,8 @@ describe("State API", () => {
3940
expect(stateApi.isReachStart).to.be.false;
4041
expect(stateApi.isReachEnd).to.be.false;
4142
expect(stateApi.currentPanelIndex).to.equal(1);
42-
expect(stateApi.progress).to.equal(50);
43+
expect(stateApi.indexProgress).to.equal(50);
44+
expect(stateApi.scrollProgress).to.equal(50);
4345
});
4446

4547
it("should update state when moving to last panel", async () => {
@@ -50,7 +52,7 @@ describe("State API", () => {
5052
expect(stateApi.isReachStart).to.be.false;
5153
expect(stateApi.isReachEnd).to.be.true;
5254
expect(stateApi.currentPanelIndex).to.equal(2);
53-
expect(stateApi.progress).to.equal(100);
55+
expect(stateApi.indexProgress).to.equal(100);
5456
});
5557

5658
it("should update state when adding panels", async () => {
@@ -75,7 +77,7 @@ describe("State API", () => {
7577
await promise;
7678

7779
expect(stateApi.currentPanelIndex).to.equal(1);
78-
expect(stateApi.progress).to.equal(50);
80+
expect(stateApi.indexProgress).to.equal(50);
7981
});
8082
});
8183
});

0 commit comments

Comments
 (0)