zt
06/24/2022, 8:47 PMnavController.navigate(destination.direction) {
popUpTo(navController.navGraph.startRoute) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
Joseph Hawkes-Cates
06/24/2022, 9:21 PMzt
06/24/2022, 9:36 PMrememberSaveable
though I may be wrongJoseph Hawkes-Cates
06/24/2022, 9:42 PMJoseph Hawkes-Cates
06/24/2022, 9:42 PMIan Lake
06/24/2022, 10:11 PMrememberSaveable
also works across being put on the back stack and coming backIan Lake
06/24/2022, 10:14 PMnavigate()
call then going back to that first screen. If that works, then there's something wrong with your bottom nav codezt
06/24/2022, 10:15 PMzt
06/24/2022, 10:15 PMIan Lake
06/24/2022, 10:17 PMnavController.graph.startRoute
is not going to work if you have nested graphs - that's specifically why the documentation uses navController.graph.findStartDestination().id
to go down as many levels as you have to actually find the first composable destination: https://developer.android.com/jetpack/compose/navigation#bottom-navzt
06/24/2022, 10:18 PMIan Lake
06/24/2022, 10:22 PMzt
06/25/2022, 2:28 AMzt
06/26/2022, 1:06 AMitem {
LazyRow(
modifier = Modifier.fillParentMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
item {
var selected by remember { mutableStateOf(false) }
FilterChip(
selected = selected,
leadingIcon = {
Icon(
imageVector = Icons.Default.Explore,
contentDescription = stringResource(R.string.explore)
)
},
selectedIcon = {
Icon(
imageVector = Icons.Default.Explore,
contentDescription = stringResource(R.string.explore)
)
},
label = { Text(stringResource(R.string.explore)) },
onClick = { selected = !selected }
)
}
}
}
Ian Lake
06/26/2022, 1:08 AMIan Lake
06/26/2022, 1:12 AMzt
06/26/2022, 1:13 AMitem { }
zt
06/26/2022, 1:16 AMclass HomeViewModel(
private val repository: InnerTubeRepository
) : ViewModel() {
val videos = Pager(PagingConfig(10)) {
object : PagingSource<String, DomainVideoPartial>() {
override suspend fun load(params: LoadParams<String>): LoadResult<String, DomainVideoPartial> {
return try {
val trendingVideosResponse = repository.getTrendingVideos(params.key)
LoadResult.Page(
data = trendingVideosResponse.videos,
prevKey = null,
nextKey = trendingVideosResponse.continuation
)
} catch (e: Exception) {
e.printStackTrace()
LoadResult.Error(e)
}
}
override fun getRefreshKey(state: PagingState<String, DomainVideoPartial>): String? = null
}
}.flow.cachedIn(viewModelScope)
}
This is what the viewmodel is right now