Commit 5bc1cc39 authored by hewenhao's avatar hewenhao

feat: 优化滚动

parent df42b9cb
...@@ -59,15 +59,19 @@ const MainPage = () => { ...@@ -59,15 +59,19 @@ const MainPage = () => {
const tabbar = getTabBar<TabbarRef>(page) const tabbar = getTabBar<TabbarRef>(page)
tabbar?.setSelected(0) tabbar?.setSelected(0)
fetchStage().then((list) => { fetchStage().then(([list, preList]) => {
setTimeout(() => { setTimeout(() => {
nextTick(() => { nextTick(() => {
if (!list.find(c => c.status === StageStatus.CURRENT)) { const currentItem = list.find(c => c.status === StageStatus.CURRENT)
if (!currentItem) {
updateReady(true) updateReady(true)
} else { } else {
scrollToCurrent(() => { const lastItem = preList.find(c => c.status === StageStatus.CURRENT)
updateReady(true) if (currentItem?.id !== lastItem?.id) {
}) scrollToCurrent(() => {
updateReady(true)
})
}
setTimeout(() => { setTimeout(() => {
updateReady(true) updateReady(true)
}, 300) }, 300)
......
...@@ -20,7 +20,7 @@ export interface MainModel { ...@@ -20,7 +20,7 @@ export interface MainModel {
player: InnerAudioContext; player: InnerAudioContext;
updateReady: Action<MainModel, boolean>; updateReady: Action<MainModel, boolean>;
updateStageList: Action<MainModel, Stage[]>; updateStageList: Action<MainModel, Stage[]>;
fetchStage: Thunk<MainModel, void, void, AppStoreModel, Promise<Stage[]>>; fetchStage: Thunk<MainModel, void, void, AppStoreModel, Promise<[Stage[], Stage[]]>>;
} }
const mainModel: MainModel = { const mainModel: MainModel = {
...@@ -33,7 +33,8 @@ const mainModel: MainModel = { ...@@ -33,7 +33,8 @@ const mainModel: MainModel = {
updateStageList: action((state, stageList) => { updateStageList: action((state, stageList) => {
state.stageList = stageList state.stageList = stageList
}), }),
fetchStage: thunk(async (actions, _) => { fetchStage: thunk(async (actions, _, helpers) => {
const { stageList: preStageList } = helpers.getState()
let ret: Stage[] = [] let ret: Stage[] = []
try { try {
const { data: stageList } = await getStageList() const { data: stageList } = await getStageList()
...@@ -42,7 +43,7 @@ const mainModel: MainModel = { ...@@ -42,7 +43,7 @@ const mainModel: MainModel = {
ret = [] ret = []
} }
actions.updateStageList(ret) actions.updateStageList(ret)
return ret return [ret, preStageList] as [Stage[], Stage[]]
}), }),
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment