cancelling previous page jobs when switch gallery pages

This commit is contained in:
Adam Brown 2022-11-02 16:08:29 +00:00
parent 2b9142b6c4
commit ec56e74c98
2 changed files with 11 additions and 0 deletions

View File

@ -38,3 +38,8 @@ sealed interface PageAction : Action {
data class PageContainer<P>( data class PageContainer<P>(
val page: SpiderPage<out P> val page: SpiderPage<out P>
) )
fun PageContainer<*>.isDifferentPage(page: SpiderPage<*>): Boolean {
return page::class != this.page::class
}

View File

@ -56,4 +56,10 @@ private fun SharedStateScope<Combined2<PageContainer<ImageGalleryPage>, Unit>>.c
dispatch(PageAction.UpdatePage(page.state.copy(content = Lce.Content(media)))) dispatch(PageAction.UpdatePage(page.state.copy(content = Lce.Content(media))))
}) })
}, },
sideEffect(PageAction.GoTo::class) { action, _ ->
if (getSharedState().state1.isDifferentPage(action.page)) {
jobBag.cancel("page")
}
}
) )