Skip to content

Commit

Permalink
1.0.0-beta04 release version
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingermainbusiness committed Jun 6, 2022
1 parent c8a4630 commit 9e1a2ef
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 40 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-beta03'
implementation 'com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.0-beta04'
}
```

Expand Down
2 changes: 1 addition & 1 deletion 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-beta03"
versionName "1.0.0-beta04"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
2 changes: 1 addition & 1 deletion 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-beta03'
version = '1.0.0-beta04'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

Expand Down Expand Up @@ -50,17 +49,6 @@ fun CollapsingTopBar(
scrollBehavior: TopBarScrollBehavior
) = with(scrollBehavior) {

if (!isAlwaysCollapsed && !isExpandedWhenFirstDisplayed && trackOffSetIsZero >= 3) {
// Makes sure the trackOffSetIsZero stays below the number 6, just a random number above 3
// cause I don't need to store super high numbers for that variable
if (trackOffSetIsZero > 6) {
trackOffSetIsZero = 3
}
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
} else if (isExpandedWhenFirstDisplayed && !isAlwaysCollapsed) {
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
}

val columnWithTitleSubtitleAlpha by getTitleAndSubtitleColumnAlpha(
currentTopBarHeight = currentTopBarHeight,
collapsedTopBarHeight = collapsedTopBarHeight,
Expand All @@ -76,17 +64,17 @@ fun CollapsingTopBar(

CollapsingTopBarLayout(
modifier = modifier,
colors = colors,
elevation = elevation,
currentTopBarHeight = currentTopBarHeight,
columnWithTitleSubtitleAlpha = columnWithTitleSubtitleAlpha,
title = title,
subtitle = subtitle,
centeredTitleAndSubtitle = centeredTitleAndSubtitle,
contentPadding = contentPadding,
navigationIcon = navigationIcon,
actions = actions,
centeredTitleAndSubtitle = centeredTitleAndSubtitle,
contentPadding = contentPadding,
colors = colors,
columnWithTitleSubtitleAlpha = columnWithTitleSubtitleAlpha,
collapsedTitleAlpha = collapsedTitleAlpha,
currentTopBarHeight = currentTopBarHeight,
elevation = elevation
)
}

Expand Down Expand Up @@ -121,11 +109,10 @@ fun CollapsingTopBarLayout(
elevation: Dp,
) = CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.high) {
Surface(
modifier = modifier,
color = colors.backgroundColor,
contentColor = colors.contentColor,
shape = RectangleShape,
elevation = elevation,
modifier = modifier,
) {
Box(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,10 @@ import androidx.compose.ui.graphics.Color

/**
* Default colors used in the [CollapsingTopBar]
* @param backgroundColor The background color of the [CollapsingTopBar]
* @param contentColor The color for the content inside [CollapsingTopBar]
* */
interface CollapsingTopBarColors {

/**
* The background color of the [CollapsingTopBar]
* */
var backgroundColor: Color

/**
* The default color for the content inside [CollapsingTopBar]
* */
class CollapsingTopBarColors(
var backgroundColor: Color,
var contentColor: Color
}

class DefaultCollapsingTopBarColors(
override var backgroundColor: Color,
override var contentColor: Color
) : CollapsingTopBarColors
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object CollapsingTopBarDefaults {
fun colors(
backgroundColor: Color = MaterialTheme.colorScheme.primary,
contentColor: Color = contentColorFor(backgroundColor)
): CollapsingTopBarColors = DefaultCollapsingTopBarColors(backgroundColor, contentColor)
): CollapsingTopBarColors = CollapsingTopBarColors(backgroundColor, contentColor)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
* Defines how a [CollapsingTopBar] should behave during a [Modifier.nestedScroll] event.
Expand Down Expand Up @@ -107,6 +108,16 @@ class DefaultBehaviorOnScroll(

override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {

if (!isAlwaysCollapsed && !isExpandedWhenFirstDisplayed && trackOffSetIsZero >= 3) {
// Just making sure trackOffSetIsZero doesn't store high numbers, it's unnecessary
if (trackOffSetIsZero > 6) {
trackOffSetIsZero = 3
}
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
} else if (isExpandedWhenFirstDisplayed && !isAlwaysCollapsed) {
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
}

val newOffset = (topBarOffset + available.y)
val coerced = newOffset.coerceIn(minimumValue = -offsetLimit, maximumValue = 0f)
topBarOffset = coerced
Expand Down

0 comments on commit 9e1a2ef

Please sign in to comment.