I experience some jank in the UI when changing pages in the horizontal pager. Do you know what might be causing this issue? I’ve tried all the different ways for skipping recompositions, but none seem to help. Is there something wrong with the performance of the library itself (since it’s still experimental)?
MarketAssetsView(
modifier = Modifier
.height(screenHeight - 60.dp),
horizontalTabModifier = Modifier
.nestedScroll( remember {
object : NestedScrollConnection {
override fun onPreScroll(
available: Offset,
source: NestedScrollSource
): Offset {
return if (available.y > 0) Offset.Zero else Offset(
x = 0f,
y = -scrollState.dispatchRawDelta(-available.y)
)
}
}
}),
loginStatus = isUserLoggedIn,
assets = assets,
favoriteAssets = favoriteAssets,
getAssets = viewModel::getAssets,
getFavoriteAssets = bookmarksViewModel::getBookmarks,
stopRefreshingAssets = viewModel::cancelDataUpdates,
stopRefreshingFavoriteAssets = bookmarksViewModel::cancelDataUpdates,
refreshAssetsPeriodically = viewModel::refreshDataPeriodically,
refreshFavoriteAssetsPeriodically = bookmarksViewModel::refreshDataPeriodically,
selectedCategoryIndex = homeConfig.selectedCategoryIndex,
saveLatestSelectedCategory = screenConfigViewModel::saveLatestChosenCategory
)
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MarketAssetsView(
modifier: Modifier = Modifier,
horizontalTabModifier: Modifier,
loginStatus: UserStatus,
assets: Resource<List<Asset>>,
favoriteAssets: Resource<List<Asset>>,
selectedCategoryIndex: Int,
getAssets: (String) -> Unit = {},
getFavoriteAssets: () -> Unit = {},
refreshAssetsPeriodically: (String) -> Unit = {},
refreshFavoriteAssetsPeriodically: () -> Unit = {},
stopRefreshingAssets: () -> Unit = {},
stopRefreshingFavoriteAssets: () -> Unit = {},
onTabChanged: (String) -> Unit = {},
saveLatestSelectedCategory: (Int) -> Unit = {}
) {
HorizontalPager(
state = pagerState,
modifier = horizontalTabModifier
.fillMaxHeight()
) { page: Int ->
// if the page is the current screen, show the current resource
when(page) {
0 -> {
MarketAssets(
assetsResource = if(loginStatus == UserStatus.LoggedIn) favoriteAssets else assets,
modifier = Modifier.fillMaxSize(),
onTryAgainClicked = {
if(loginStatus == UserStatus.LoggedIn) {
getFavoriteAssets()
refreshFavoriteAssetsPeriodically()
} else {
val targetCategories = if(loginStatus==UserStatus.LoggedIn) categories[1].name
else categories[0].name
getAssets(targetCategories)
refreshAssetsPeriodically(targetCategories)
}
}
)
}
else -> {
MarketAssets(
assetsResource = assets,
modifier = Modifier.fillMaxSize(),
onTryAgainClicked = {
val targetCategories = if(loginStatus==UserStatus.LoggedIn) categories[1].name
else categories[0].name
getAssets(targetCategories)
refreshAssetsPeriodically(targetCategories)
}
)
}
}
}
}