pull/63/merge
Vedant Bhamare 3 years ago committed by GitHub
commit 78947df641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,3 +21,10 @@ plugins {
id("dagger.hilt.android.plugin")
id("nowinandroid.spotless")
}
dependencies {
//compose pagers
implementation(libs.accompanist.pager)
implementation(libs.accompanist.pager.indicators)
}

@ -17,6 +17,7 @@
package com.google.samples.apps.nowinandroid.feature.interests
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
@ -31,15 +32,20 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.rememberPagerState
import com.google.samples.apps.nowinandroid.core.ui.LoadingWheel
import com.google.samples.apps.nowinandroid.core.ui.component.NiaTab
import com.google.samples.apps.nowinandroid.core.ui.component.NiaTabRow
import com.google.samples.apps.nowinandroid.core.ui.component.NiaTopAppBar
import kotlinx.coroutines.launch
@Composable
fun InterestsRoute(
@ -118,6 +124,7 @@ fun InterestsScreen(
}
}
@OptIn(ExperimentalPagerApi::class)
@Composable
private fun InterestsContent(
tabState: InterestsTabState,
@ -130,26 +137,38 @@ private fun InterestsContent(
modifier: Modifier = Modifier
) {
Column(modifier) {
NiaTabRow(selectedTabIndex = tabState.currentIndex) {
val pagerState = rememberPagerState()
val scope = rememberCoroutineScope()
NiaTabRow(
selectedTabIndex = pagerState.currentPage
) {
tabState.titles.forEachIndexed { index, titleId ->
NiaTab(
selected = index == tabState.currentIndex,
onClick = { switchTab(index) },
selected = pagerState.currentPage == index,
onClick = {
switchTab(index)
scope.launch {
pagerState.scrollToPage(index)
}
},
text = { Text(text = stringResource(id = titleId)) }
)
}
}
when (tabState.currentIndex) {
0 -> {
TopicsTabContent(
HorizontalPager(
state = pagerState,
count = tabState.titles.size,
verticalAlignment = Alignment.Top,
contentPadding = PaddingValues(top = 12.dp),
) { index ->
when (index) {
0 -> TopicsTabContent(
topics = uiState.topics,
onTopicClick = navigateToTopic,
onFollowButtonClick = followTopic,
modifier = Modifier.padding(top = 8.dp)
)
}
1 -> {
AuthorsTabContent(
1 -> AuthorsTabContent(
authors = uiState.authors,
onAuthorClick = navigateToAuthor,
onFollowButtonClick = followAuthor,

@ -1,5 +1,5 @@
[versions]
accompanist = "0.24.8-beta"
accompanist = "0.24.9-beta"
androidDesugarJdkLibs = "1.1.5"
androidGradlePlugin = "7.2.1"
androidxActivity = "1.4.0"
@ -46,6 +46,8 @@ turbine = "0.8.0"
[libraries]
accompanist-flowlayout = { group = "com.google.accompanist", name = "accompanist-flowlayout", version.ref = "accompanist" }
accompanist-pager = { group = "com.google.accompanist", name = "accompanist-pager", version.ref = "accompanist" }
accompanist-pager-indicators = { group = "com.google.accompanist", name = "accompanist-pager-indicators", version.ref = "accompanist" }
android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" }
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivity" }

Loading…
Cancel
Save