Skip to content

Commit

Permalink
Updated to 1.0.0-rc04 version
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingermainbusiness committed Jul 4, 2022
1 parent 00c7212 commit 2b0a8ce
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repositories {

```groovy
dependencies {
implementation "com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.0-rc03"
implementation "com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.0-rc04"
}
```

Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0.0-rc03"
versionName "1.0.0-rc04"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -36,7 +36,7 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerExtensionVersion '1.2.0'
}
packagingOptions {
resources {
Expand All @@ -50,8 +50,8 @@ dependencies {
implementation project(path: ':collapsingtopbar')

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


// Compose dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.germainkevin.collapsingtopbarcompose

import android.os.Bundle
import android.view.Window
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
Expand All @@ -17,11 +18,13 @@ import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
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.collapsingtopbarcompose.ui.*
import com.germainkevin.collapsingtopbarcompose.ui.theme.CollapsingTopBarComposeTheme
Expand Down Expand Up @@ -55,7 +58,8 @@ class MainActivity : ComponentActivity() {
contactNames = stringArrayResource(id = R.array.contactNames),
scaffoldState = scaffoldState,
openLeftDrawer = openLeftDrawer,
closeLeftDrawer = closeLeftDrawer
closeLeftDrawer = closeLeftDrawer,
window = this@MainActivity.window
)
}
}
Expand All @@ -68,7 +72,8 @@ private fun HomeScreen(
contactNames: Array<String>,
scaffoldState: ScaffoldState,
openLeftDrawer: () -> Unit,
closeLeftDrawer: () -> Unit
closeLeftDrawer: () -> Unit,
window: Window
) {
val scrollBehavior = rememberCollapsingTopBarScrollBehavior(
isAlwaysCollapsed = false,
Expand All @@ -83,6 +88,14 @@ private fun HomeScreen(
topBar = {
CollapsingTopBar(
scrollBehavior = scrollBehavior,
colors = CollapsingTopBarDefaults
.colors(
backgroundColorWhenNotCollapsedOrExpanded =
MaterialTheme.colorScheme.onPrimaryContainer,
onBackgroundColorChange = {
window.statusBarColor = it.toArgb()
},
),
title = TitleText,
subtitle = { SubtitleText(contactNames) },
navigationIcon = { NavigationIcon(openLeftDrawer) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun CollapsingTopBarComposeTheme(
SideEffect {
(view.context as Activity).apply {
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view)?.isAppearanceLightStatusBars =
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars =
darkTheme
}
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
compose_version = '1.2.0-rc02'
compose_version = '1.2.0-rc03'
coreKtx = '1.8.0'
material3Version ='1.0.0-alpha13'
timberVersion ='5.0.1'
Expand All @@ -9,7 +9,7 @@ buildscript {
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}

task clean(type: Delete) {
Expand Down
4 changes: 2 additions & 2 deletions collapsingtopbar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ afterEvaluate {
// You can then customize attributes of the publication as shown below.
groupId = 'com.germainkevin.collapsingtopbarcompose'
artifactId = 'collapsingtopbarcompose'
version = '1.0.0-rc03'
version = '1.0.0-rc04'
}
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerExtensionVersion '1.2.0'
}
packagingOptions {
resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

Expand Down Expand Up @@ -56,11 +57,12 @@ fun CollapsingTopBar(
actions = actions,
centeredTitleAndSubtitle = centeredTitleAndSubtitle,
contentPadding = contentPadding,
colors = colors,
expandedColumnAlphaValue = expandedColumnAlphaValue.invoke().value,
collapsedTitleAlpha = collapsedTitleAlpha.invoke().value,
currentTopBarHeight = currentTopBarHeight,
elevation = elevation
elevation = elevation,
currentBackgroundColor = currentBackgroundColor(colors).value,
currentContentColor = colors.contentColor
)
}

Expand All @@ -72,8 +74,6 @@ fun CollapsingTopBar(
* This should typically be an [IconButton] or [IconToggleButton].
* @param actions the actions displayed at the end of the [CollapsingTopBar]. This should typically
* be [IconButton]s. The default layout here is a [Row], so icons inside will be placed horizontally.
* @param colors [CollapsingTopBarColors] that will be used to resolve the colors used for this
* [CollapsingTopBar] in different states. See [CollapsingTopBarDefaults.colors].
* @param contentPadding The padding of the content inside the [CollapsingTopBar]
* @param elevation The size of the shadow below the [Surface]
* @param currentTopBarHeight The current height of the [CollapsingTopBar]
Expand All @@ -88,16 +88,17 @@ private fun CollapsingTopBarLayout(
actions: @Composable RowScope.() -> Unit,
centeredTitleAndSubtitle: Boolean,
contentPadding: PaddingValues,
colors: CollapsingTopBarColors,
currentBackgroundColor: Color,
currentContentColor: Color,
expandedColumnAlphaValue: Float,
collapsedTitleAlpha: Float,
currentTopBarHeight: Dp,
elevation: Dp,
) = CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.high) {
Surface(
modifier = modifier,
color = colors.backgroundColor,
contentColor = colors.contentColor,
color = currentBackgroundColor,
contentColor = currentContentColor,
elevation = elevation,
) {
Box(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,43 @@ object CollapsingTopBarDefaults {

/**
* Default colors used in the [CollapsingTopBar]
* @param backgroundColor The background color of the [CollapsingTopBar]
* @param contentColor The content color inside of the [CollapsingTopBar]
* @param backgroundColor The background color of the [CollapsingTopBar] when collapsed
* or expanded
* @param contentColor The content color inside of the [CollapsingTopBar] when collapsed
* or expanded
* @param backgroundColorWhenNotCollapsedOrExpanded The background color of
* the [CollapsingTopBar] when it's not collapsed or expanded
* */
@Composable
fun colors(
backgroundColor: Color = MaterialTheme.colorScheme.primary,
contentColor: Color = contentColorFor(backgroundColor = backgroundColor)
): CollapsingTopBarColors = CollapsingTopBarColors(backgroundColor, contentColor)
contentColor: Color = contentColorFor(backgroundColor = backgroundColor),
backgroundColorWhenNotCollapsedOrExpanded: Color = backgroundColor,
onBackgroundColorChange: (Color) -> Unit = {},
): CollapsingTopBarColors = CollapsingTopBarColors(
backgroundColor = backgroundColor,
contentColor = contentColor,
backgroundColorWhenNotCollapsedOrExpanded = backgroundColorWhenNotCollapsedOrExpanded,
onBackgroundColorChange = onBackgroundColorChange,
)
}

/**
* Default colors used in the [CollapsingTopBar]
* @param backgroundColor The background color of the [CollapsingTopBar]
* @param contentColor The color for the content inside [CollapsingTopBar]
* @param backgroundColor The background color of the [CollapsingTopBar] when collapsed
* or expanded
* @param contentColor The content color inside of the [CollapsingTopBar] when collapsed
* or expanded
* @param backgroundColorWhenNotCollapsedOrExpanded The background color of
* the [CollapsingTopBar] when it's not collapsed or expanded
* @param onBackgroundColorChange This callback method has a Color parameter which emits the current
* background color of the [CollapsingTopBar] whenever it changes
* */
class CollapsingTopBarColors(
var backgroundColor: Color,
var contentColor: Color
var contentColor: Color,
var backgroundColorWhenNotCollapsedOrExpanded: Color,
var onBackgroundColorChange: (Color) -> Unit,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.germainkevin.collapsingtopbar
import androidx.compose.animation.*
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

/**
Expand Down Expand Up @@ -73,4 +75,22 @@ internal val actionsRow: @Composable (@Composable RowScope.() -> Unit) -> Unit =
verticalAlignment = Alignment.Bottom,
content = it
)
}
}

/**
* Will provide us with the current background color of the [CollapsingTopBar]*/
@Composable
internal fun CollapsingTopBarScrollBehavior.currentBackgroundColor(
colors: CollapsingTopBarColors
): State<Color> = animateColorAsState(
targetValue =
if (currentTopBarHeight == collapsedTopBarHeight ||
currentTopBarHeight == expandedTopBarMaxHeight
) {
colors.onBackgroundColorChange(colors.backgroundColor)
colors.backgroundColor
} else {
colors.onBackgroundColorChange(colors.backgroundColorWhenNotCollapsedOrExpanded)
colors.backgroundColorWhenNotCollapsedOrExpanded
}
)

0 comments on commit 2b0a8ce

Please sign in to comment.