Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shamimcse1 committed Jan 14, 2023
0 parents commit 46e10eb
Show file tree
Hide file tree
Showing 54 changed files with 1,296 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions StarTabView/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
77 changes: 77 additions & 0 deletions StarTabView/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
}

ext {
compose_version = '1.3.2'
version_hilt_navigation = "1.0.0-rc01"
coroutines_version = "1.5.1"

}
android {
namespace 'com.codercamp.startabview'
compileSdk 33

defaultConfig {
minSdk 21
targetSdk 33
versionCode = 1
versionName = "1.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}

}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
}

dependencies {

implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.compose.material:material:1.3.1'

androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
implementation("io.coil-kt:coil-compose:2.2.2")
implementation("io.coil-kt:coil-svg:2.2.2")
implementation "androidx.navigation:navigation-compose:2.6.0-alpha04"
implementation("androidx.compose.material:material:1.3.1")
def accompanist_version = "0.28.0"
implementation "com.google.accompanist:accompanist-pager:$accompanist_version" // Pager
implementation "com.google.accompanist:accompanist-pager-indicators:$accompanist_version" // Pager Indicator

}
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = 'com.github.shamimcse1'
artifactId = 'star-tab-view-compose'
version = '1.0.0'
}
}
}
}
Empty file added StarTabView/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions StarTabView/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.codercamp.startabview

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.codercamp.startabview.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions StarTabView/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.codercamp.startabview

import androidx.compose.runtime.Composable
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.PagerState


@OptIn(ExperimentalPagerApi::class)
@Composable
fun StarTabsContent(tabList: List<StarTabItem>, pagerState: PagerState) {
HorizontalPager(
count = tabList.size,state = pagerState) { page ->
tabList[page].screen()
}
}
10 changes: 10 additions & 0 deletions StarTabView/src/main/java/com/codercamp/startabview/StarTabItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.codercamp.startabview

import androidx.compose.runtime.Composable

typealias ComposableFun = @Composable () -> Unit

data class StarTabItem(
var title: String,
var screen: ComposableFun
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.codercamp.startabview

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color

import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.rememberPagerState


@OptIn(ExperimentalPagerApi::class)
@Composable
fun StarTabLayout(
modifier: Modifier = Modifier,
tabList: List<StarTabItem>,
tabColor: Color = Color.White,
tabIndicatorColor: Color = Color.Blue,
) {

val pagerState = rememberPagerState(initialPage = 0)

Column(
modifier = modifier.background(tabColor)
) {
StarTabs(pagerState = pagerState, tabList = tabList, indicatorColor = tabIndicatorColor)
StarTabsContent(
pagerState = pagerState,
tabList = tabList
)
}

}
63 changes: 63 additions & 0 deletions StarTabView/src/main/java/com/codercamp/startabview/StarTabs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.codercamp.startabview

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.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.PagerState
import com.google.accompanist.pager.pagerTabIndicatorOffset
import kotlinx.coroutines.launch


@OptIn(ExperimentalPagerApi::class)
@ExperimentalPagerApi
@Composable
fun StarTabs(
pagerState: PagerState,
tabList: List<StarTabItem>,
indicatorColor: Color = Color.Black,
) {

val scope = rememberCoroutineScope()

TabRow(
selectedTabIndex = pagerState.currentPage,
backgroundColor = Color.White,
contentColor = Color.White,
indicator = { tabPositions ->
TabRowDefaults.Indicator(
Modifier.pagerTabIndicatorOffset(pagerState, tabPositions),
height = 2.dp,
color = indicatorColor
)
}
) {

tabList.forEachIndexed { index, _ ->
Tab(
text = {
Text(
tabList[index].title,
color = if (pagerState.currentPage == index) Color.Black else Color.Black,
style = TextStyle(fontSize = 14.sp, fontWeight = FontWeight.Bold)
)
},
selected = pagerState.currentPage == index,
onClick = {
scope.launch {
pagerState.animateScrollToPage(index)
}
}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.codercamp.startabview

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit 46e10eb

Please sign in to comment.