-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d2e33b
commit 8c1c80d
Showing
7 changed files
with
138 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/debanshu777/compose_github/ui/base/components/tabHandler/TabHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.debanshu777.compose_github.ui.base.components.tabHandler | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.runtime.Composable | ||
import com.google.accompanist.pager.ExperimentalPagerApi | ||
import com.google.accompanist.pager.HorizontalPager | ||
import com.google.accompanist.pager.PagerState | ||
|
||
@ExperimentalPagerApi | ||
@Composable | ||
fun TabHandler(pagerState: PagerState,pageCount:Int,tabNames:List<String>) { | ||
Column( | ||
) { | ||
Tabs(pagerState = pagerState,tabNames) | ||
TabsContent(pagerState = pagerState,pageCount) | ||
} | ||
} | ||
|
||
@ExperimentalPagerApi | ||
@Composable | ||
fun TabsContent(pagerState: PagerState,pageCount:Int) { | ||
HorizontalPager(state = pagerState,count=pageCount) { page -> | ||
when(page) { | ||
0 -> TabLayout(data = "Make It Easy One") | ||
1 -> TabLayout(data = "Make It Easy Two") | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/debanshu777/compose_github/ui/base/components/tabHandler/TabLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.debanshu777.compose_github.ui.base.components.tabHandler | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
|
||
@Composable | ||
fun TabLayout(data: String) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
Text( | ||
text = data, | ||
) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/debanshu777/compose_github/ui/base/components/tabHandler/Tabs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.debanshu777.compose_github.ui.base.components.tabHandler | ||
|
||
import androidx.compose.material.Tab | ||
import androidx.compose.material.TabRow | ||
import androidx.compose.material.TabRowDefaults | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import com.google.accompanist.pager.ExperimentalPagerApi | ||
import com.google.accompanist.pager.PagerState | ||
import com.google.accompanist.pager.pagerTabIndicatorOffset | ||
import kotlinx.coroutines.launch | ||
|
||
|
||
@ExperimentalPagerApi | ||
@Composable | ||
fun Tabs(pagerState: PagerState,tabNames:List<String>) { | ||
val scope = rememberCoroutineScope() | ||
|
||
TabRow( | ||
selectedTabIndex = pagerState.currentPage, | ||
divider = { | ||
TabRowDefaults.Divider( | ||
thickness = 2.dp, | ||
) | ||
}, | ||
indicator = { tabPositions -> | ||
TabRowDefaults.Indicator( | ||
Modifier.pagerTabIndicatorOffset(pagerState, tabPositions), | ||
height = 2.dp, | ||
) | ||
} | ||
) { | ||
tabNames.forEachIndexed { index, _-> | ||
Tab( | ||
text = { | ||
Text( | ||
tabNames[index], | ||
color = if (pagerState.currentPage == index) Color.White else Color.LightGray | ||
) | ||
}, | ||
selected = pagerState.currentPage == index, | ||
onClick = { | ||
scope.launch { | ||
pagerState.animateScrollToPage(index) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 18 additions & 2 deletions
20
app/src/main/java/com/debanshu777/compose_github/ui/feature_trending/TrendingScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
package com.debanshu777.compose_github.ui.feature_trending | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import com.debanshu777.compose_github.ui.base.components.tabHandler.TabHandler | ||
import com.google.accompanist.pager.* | ||
import kotlinx.coroutines.launch | ||
|
||
@OptIn(ExperimentalPagerApi::class) | ||
@Composable | ||
fun TrendingScreen() { | ||
Text("Trending Screen") | ||
val pagerState = rememberPagerState(0) | ||
val pageCount=2 | ||
val tabList = listOf("Repository", "Developer") | ||
TabHandler(pagerState,pageCount,tabList) | ||
} |