Skip to content

Commit

Permalink
Release 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingermainbusiness committed Aug 31, 2022
1 parent 16adf4f commit 96e8556
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ repositories {

```groovy
dependencies {
implementation "com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.1"
implementation "com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.2"
}
```

Expand Down
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
apply plugin: 'kotlin-android'

android {
compileSdk 32
compileSdk 33

defaultConfig {
applicationId "com.germainkevin.collapsingtopbarcompose"
minSdk 21
targetSdk 32
targetSdk 33
versionCode 1
versionName libraryVersion

Expand Down Expand Up @@ -50,8 +51,8 @@ dependencies {
implementation project(path: ':collapsingtopbar')

implementation "androidx.core:core-ktx:$coreKtx"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0'
implementation 'androidx.activity:activity-compose:1.5.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.5.1'


// Compose dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.unit.dp
import com.germainkevin.collapsingtopbar.CollapsingTopBar
import com.germainkevin.collapsingtopbar.CollapsingTopBarDefaults
import com.germainkevin.collapsingtopbar.rememberCollapsingTopBarScrollBehavior
import com.germainkevin.collapsingtopbar.*
import com.germainkevin.collapsingtopbarcompose.ui.*
import com.germainkevin.collapsingtopbarcompose.ui.theme.CollapsingTopBarComposeTheme
import kotlinx.coroutines.launch
import timber.log.Timber

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -112,16 +111,24 @@ private fun HomeScreen(
)
},
) { contentPadding ->
val context = LocalContext.current
var topBarState = true
LazyColumn(
modifier = Modifier.background(MaterialTheme.colorScheme.background),
contentPadding = contentPadding,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
item {
Spacer(modifier = Modifier.height(6.dp))
Timber.d("CollapsingTopBarState currentTopBarHeight: ${scrollBehavior.currentTopBarHeight}")
Timber.d("CollapsingTopBarState: ${scrollBehavior.currentState.value}")
}
items(count = contactNames.size) {
ContactNameItem(LocalContext.current, contactNames[it])
ContactNameItem(contactNames[it]) { name ->
createToast(context, name)
if (topBarState) scrollBehavior.collapse() else scrollBehavior.expand()
topBarState = !topBarState
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ fun LeftDrawer(
}

@Composable
fun ContactNameItem(context: Context, contactName: String) {
fun ContactNameItem(contactName: String, onClick: (String) -> Unit) {
Row(
modifier = Modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.background)
.clickable { createToast(context, contactName) },
.clickable { onClick(contactName) },
verticalAlignment = Alignment.CenterVertically,
content = {
Text(
Expand Down
17 changes: 12 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
buildscript {
ext {
compose_version = '1.2.0'
compose_version = '1.2.1'
coreKtx = '1.8.0'
libraryVersion ='1.0.1'
material3Version ='1.0.0-alpha15'
libraryVersion ='1.0.3'
kotlin_version = '1.7.0'
material3Version ='1.0.0-beta01'
timberVersion ='5.0.1'
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}

Expand Down
6 changes: 5 additions & 1 deletion collapsingtopbar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
}
apply plugin: 'kotlin-android'

android {
publishing {
Expand Down Expand Up @@ -68,11 +69,14 @@ android {
dependencies {

implementation "androidx.core:core-ktx:$coreKtx"
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation "com.jakewharton.timber:timber:$timberVersion"

implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material3:material3:$material3Version"
}
repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ interface CollapsingTopBarScrollBehavior {
* */
var currentTopBarHeight: Dp

/**
* Notifies about the current [CollapsingTopBarState]
* */
val currentState: State<CollapsingTopBarState>

/**
* The offset that is added to the height of the [CollapsingTopBar] based on detected
* scroll events from the
Expand Down Expand Up @@ -132,10 +137,9 @@ class DefaultBehaviorOnScroll(
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {

if (!isAlwaysCollapsed && !isExpandedWhenFirstDisplayed && trackOffSetIsZero >= 3) {
// Just making sure trackOffSetIsZero doesn't store high numbers, koz it's unnecessary
if (trackOffSetIsZero > 6) {
trackOffSetIsZero = 3
}
// Just making sure trackOffSetIsZero doesn't store high numbers,
// koz it's unnecessary
if (trackOffSetIsZero > 6) trackOffSetIsZero = 3
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
} else if (isExpandedWhenFirstDisplayed && !isAlwaysCollapsed) {
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
Expand All @@ -155,6 +159,15 @@ class DefaultBehaviorOnScroll(
}
}

override val currentState: State<CollapsingTopBarState>
get() = mutableStateOf(
when (currentTopBarHeight) {
collapsedTopBarHeight -> CollapsingTopBarState.COLLAPSED
expandedTopBarMaxHeight -> CollapsingTopBarState.EXPANDED
else -> CollapsingTopBarState.IN_BETWEEN
}
)

override val expandedColumnAlphaValue: @Composable () -> State<Float> = {
getExpandedColumnAlpha()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.germainkevin.collapsingtopbar

enum class CollapsingTopBarState {
COLLAPSED, // When the CollapsingTopBar is collapsed
IN_BETWEEN, // When the CollapsingTopBar is neither collapsed neither expanded
EXPANDED // When the CollapsingTopBar is expanded
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,22 @@ internal fun CollapsingTopBarScrollBehavior.currentBackgroundColor(
colors.onBackgroundColorChange(colors.backgroundColorWhenCollapsingOrExpanding)
colors.backgroundColorWhenCollapsingOrExpanding
}
)
)

/**
* Collapses the [CollapsingTopBar]
* */
fun CollapsingTopBarScrollBehavior.collapse() {
if (currentTopBarHeight != collapsedTopBarHeight) {
currentTopBarHeight = collapsedTopBarHeight
}
}

/**
* Expands the [CollapsingTopBar]
* */
fun CollapsingTopBarScrollBehavior.expand() {
if (currentTopBarHeight != expandedTopBarMaxHeight) {
currentTopBarHeight = expandedTopBarMaxHeight
}
}
5 changes: 4 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.api.initialization.resolve.RepositoriesMode

pluginManagement {
repositories {
gradlePluginPortal()
Expand All @@ -6,10 +8,11 @@ pluginManagement {
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "CollapsingTopBarCompose"
Expand Down

0 comments on commit 96e8556

Please sign in to comment.