Skip to content

Commit

Permalink
Eighteenth commit, 1.0.0-alpha04 release version
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingermainbusiness committed May 17, 2022
1 parent 713821d commit 376c460
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {

```groovy
dependencies {
implementation 'com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.0-alpha02'
implementation 'com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.0-alpha04'
}
```

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-alpha02"
versionName "1.0.0-alpha04"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ fun CollapsingTopBarExample(context: Context) {
val scrollBehavior = remember {
CollapsingTopBarDefaults
.collapsingTopBarScrollBehavior(
// isInitiallyCollapsed = false,
expandedTopBarHeight = 256.dp
isAlwaysCollapsed = false,
expandedTopBarMaxHeight = 256.dp
)
}
Scaffold(
Expand Down
2 changes: 1 addition & 1 deletion collapsingtopbar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ afterEvaluate {
// You can then customize attributes of the publication as shown below.
groupId = 'com.germainkevin.collapsingtopbarcompose'
artifactId = 'collapsingtopbarcompose'
version = '1.0.0-alpha02'
version = '1.0.0-alpha04'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun CollapsingTopBar(
scrollBehavior: TopBarScrollBehavior
) = with(scrollBehavior) {

if (isInitiallyCollapsed && trackOffSetIsZero >= 3) {
if (!isAlwaysCollapsed && isInitiallyCollapsed && trackOffSetIsZero >= 3) {
// Make sure the trackOffSetIsZero variable does not exceed the number 10
if (trackOffSetIsZero > 10) trackOffSetIsZero = 3
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ object CollapsingTopBarDefaults {
PaddingValues(start = appBarHorizontalPadding, end = appBarHorizontalPadding)

/**
* @param isAlwaysCollapsed This will make this [CollapsingTopBar] never expand and stay with
* the [collapsedTopBarHeight] height, it's false by default
* @param isInitiallyCollapsed Specifies whether the [CollapsingTopBar] should be displayed in a
* collapsed state when first displayed on the UI.
* @param collapsedTopBarHeight The height of the [CollapsingTopBar] when it's collapsed, the
* default value is [defaultMinimumTopBarHeight]
* @param expandedTopBarHeight The height of the [CollapsingTopBar] when it's expended,
* @param expandedTopBarMaxHeight The height of the [CollapsingTopBar] when it's expended,
* the default value is [defaultMaximumTopBarHeight]
* */
fun collapsingTopBarScrollBehavior(
isAlwaysCollapsed: Boolean = false,
isInitiallyCollapsed: Boolean = true,
collapsedTopBarHeight: Dp = defaultMinimumTopBarHeight,
expandedTopBarHeight: Dp = defaultMaximumTopBarHeight
): TopBarScrollBehavior {
return CollapsingTopBarScrollBehavior(
isInitiallyCollapsed = isInitiallyCollapsed,
collapsedHeight = collapsedTopBarHeight,
expandedHeight = expandedTopBarHeight
)
}
expandedTopBarMaxHeight: Dp = defaultMaximumTopBarHeight
): TopBarScrollBehavior = CollapsingTopBarScrollBehavior(
isAlwaysCollapsed = isAlwaysCollapsed,
isInitiallyCollapsed = isInitiallyCollapsed,
collapsedTopBarHeight = collapsedTopBarHeight,
expandedTopBarMaxHeight = expandedTopBarMaxHeight
)

@Composable
fun collapsingTopBarColors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import androidx.compose.ui.unit.Dp
* */
interface TopBarScrollBehavior {

/**
* This will make this [CollapsingTopBar] never expand */
var isAlwaysCollapsed: Boolean

/**
* The height of the TopBar when it's collapsed in [Dp]
* */
Expand Down Expand Up @@ -46,15 +50,6 @@ interface TopBarScrollBehavior {
* */
var trackOffSetIsZero: Int

/**
* The current content offset that is updated when the nested scroll connection consumes scroll
* events.
*
* A common behavior implementation would update this value to be the sum of all
* [NestedScrollConnection.onPostScroll] `consumed.y` values.
*/
var contentOffset: Float

/**
* When offsetting the [currentTopBarHeight], it subtracts its [expandedTopBarMaxHeight]
* to the [topBarOffset] so it can decrease the height of the [CollapsingTopBar], but
Expand All @@ -81,34 +76,32 @@ interface TopBarScrollBehavior {
}

/**
* @param isAlwaysCollapsed This will make this [CollapsingTopBar] never expand, it's false by default.
* @param isInitiallyCollapsed Specifies whether the [CollapsingTopBar] should be displayed in a
* collapsed state when first displayed on the UI. Set to true by default when set in
* [CollapsingTopBarDefaults.collapsingTopBarScrollBehavior]
* @see [CollapsingTopBarDefaults.collapsingTopBarScrollBehavior] where it's set to false by default
* @param collapsedHeight The height of the [CollapsingTopBar] when it's collapsed, the
* @param collapsedTopBarHeight The height of the [CollapsingTopBar] when it's collapsed, the
* default value is [defaultMinimumTopBarHeight]
* @param expandedHeight The height of the [CollapsingTopBar] when it's expended, the default
* value is [defaultMaximumTopBarHeight]
* @param expandedTopBarMaxHeight The height of the [CollapsingTopBar] when it's expended, the
* default value is [defaultMaximumTopBarHeight]
* */
class CollapsingTopBarScrollBehavior(
override var isAlwaysCollapsed: Boolean,
override var isInitiallyCollapsed: Boolean,
collapsedHeight: Dp,
expandedHeight: Dp
override var collapsedTopBarHeight: Dp,
override var expandedTopBarMaxHeight: Dp,
) : TopBarScrollBehavior {
override var collapsedTopBarHeight: Dp = collapsedHeight

override var expandedTopBarMaxHeight: Dp = expandedHeight

override var topBarOffset: Float by mutableStateOf(0f)

override var trackOffSetIsZero: Int by mutableStateOf(0)

override var currentTopBarHeight: Dp by mutableStateOf(
if (isInitiallyCollapsed) collapsedTopBarHeight else expandedTopBarMaxHeight
if (isInitiallyCollapsed || isAlwaysCollapsed) collapsedTopBarHeight
else expandedTopBarMaxHeight
)

override var contentOffset: Float by mutableStateOf(0f)

override var offsetLimit: Float = (expandedTopBarMaxHeight - collapsedTopBarHeight).value

override var nestedScrollConnection = object : NestedScrollConnection {
Expand Down

0 comments on commit 376c460

Please sign in to comment.