diff --git a/README.md b/README.md
index 0363f0c..576ff89 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
[![](https://jitpack.io/v/germainkevinbusiness/CollapsingTopBarCompose.svg)](https://jitpack.io/#germainkevinbusiness/CollapsingTopBarCompose)
+
# CollapsingTopBarCompose
+
A Jetpack Compose Collapsing Top Bar, that expands or collapses based on the scrolling of a content
@@ -33,75 +35,81 @@ repositories {
```groovy
dependencies {
- implementation 'com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.0-alpha05'
+ implementation 'com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.0-alpha06'
}
```
# Usage
-Basic usage is shown below, there's a more elaborate example in
-the [sample app](https://github.com/germainkevinbusiness/CollapsingTopBarCompose/blob/master/app/src/main/java/com/germainkevin/collapsingtopbarcompose/MainActivity.kt).
+Basic usage is shown below, there's a more elaborate example in
+the [sample app](https://github.com/germainkevinbusiness/CollapsingTopBarCompose/blob/master/app/src/main/java/com/germainkevin/collapsingtopbarcompose/MainActivity.kt)
+.
In order to use a ```CollapsingTopBar```, you first need to create a ```TopBarScrollBehavior```.
+
```kotlin
- val scrollBehavior = remember {
- CollapsingTopBarDefaults.collapsingTopBarScrollBehavior(
+ val scrollBehavior = remember {
+ CollapsingTopBarDefaults.behaviorOnScroll(
isAlwaysCollapsed = false,
isInitiallyCollapsed = true,
collapsedTopBarHeight = 56.dp,
expandedTopBarMaxHeight = 156.dp,
- )
- }
+ )
+}
```
-To know when scrolling occurs inside your Layout so the ```CollapsingTopBar``` can collapse or expand, add the ```scrollBehavior.nestedScrollConnection``` inside your Layout's ```Modifier.nestedScroll``` :
+
+To know when scrolling occurs inside your Layout so the ```CollapsingTopBar``` can collapse or
+expand, add the ```scrollBehavior.nestedScrollConnection``` inside your
+Layout's ```Modifier.nestedScroll``` :
+
```kotlin
Scaffold(
- modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
- topBar = {
+ modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
+ topBar = {
CollapsingTopBar(
- scrollBehavior = scrollBehavior,
- centeredTitleAndSubtitle = true, // set to false if you want the expanded title and subtitle to be at the left instead
- title = { Text(text = "All contacts") },
- subtitle = { Text(text = "17 contacts") },
+ scrollBehavior = scrollBehavior,
+ centeredTitleAndSubtitle = true, // set to false if you want the expanded title and subtitle to be at the left instead
+ title = { Text(text = "All contacts") },
+ subtitle = { Text(text = "17 contacts") },
)
- },
- ){}
+ },
+) {}
```
So when we put it all together we got:
```kotlin
-val scrollBehavior = remember {
- CollapsingTopBarDefaults.collapsingTopBarScrollBehavior(
+val scrollBehavior = remember {
+ CollapsingTopBarDefaults.behaviorOnScroll(
isAlwaysCollapsed = false,
isInitiallyCollapsed = true,
collapsedTopBarHeight = 56.dp,
expandedTopBarMaxHeight = 156.dp,
- )
- }
- Scaffold(
- modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
- topBar = {
+ )
+}
+Scaffold(
+ modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
+ topBar = {
CollapsingTopBar(
- scrollBehavior = scrollBehavior,
- centeredTitleAndSubtitle = true, // set to false if you want the expanded title and subtitle to be at the left instead
- title = { Text(text = "All contacts") },
- subtitle = { Text(text = "17 contacts") },
+ scrollBehavior = scrollBehavior,
+ centeredTitleAndSubtitle = true, // set to false if you want the expanded title and subtitle to be at the left instead
+ title = { Text(text = "All contacts") },
+ subtitle = { Text(text = "17 contacts") },
)
- },
- ) {
+ },
+) {
LazyColumn(
- contentPadding = innerPadding,
- verticalArrangement = Arrangement.spacedBy(8.dp)
+ contentPadding = innerPadding,
+ verticalArrangement = Arrangement.spacedBy(8.dp)
) {
val context = LocalContext.current
val contactNames = context.resources.getStringArray(R.array.contactNames)
items(count = contactNames.size) {
- ContactListNames(context, contactNames[it])
+ ContactListNames(context, contactNames[it])
}
}
- }
+}
```
**That's it!**
diff --git a/app/build.gradle b/app/build.gradle
index d4b1553..e966efc 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -11,7 +11,7 @@ android {
minSdk 21
targetSdk 32
versionCode 1
- versionName "1.0.0-alpha05"
+ versionName "1.0.0-alpha06"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
@@ -50,25 +50,17 @@ dependencies {
implementation project(path: ':collapsingtopbar')
implementation 'androidx.core:core-ktx:1.7.0'
- implementation "androidx.compose.ui:ui:$compose_version"
- implementation 'androidx.compose.material3:material3:1.0.0-alpha12'
- implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.activity:activity-compose:1.4.0'
- implementation "androidx.compose.material3:material3-window-size-class:1.0.0-alpha12"
// Compose dependencies
- implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.0-rc01"
+ implementation "androidx.compose.ui:ui:$compose_version"
+ implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
-
- // Accompanist
- //Jetpack Navigation Compose Material
- implementation 'com.google.accompanist:accompanist-navigation-material:0.24.9-beta'
- //Insets for Jetpack Compose
- implementation 'com.google.accompanist:accompanist-insets:0.24.9-beta'
- //System UI Controller
- implementation 'com.google.accompanist:accompanist-systemuicontroller:0.24.9-beta'
+ implementation 'androidx.compose.material3:material3:1.0.0-alpha12'
+ implementation "androidx.compose.material3:material3-window-size-class:1.0.0-alpha12"
+ implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.0-rc01"
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'
diff --git a/app/src/main/java/com/germainkevin/collapsingtopbarcompose/Components.kt b/app/src/main/java/com/germainkevin/collapsingtopbarcompose/Components.kt
index 4f9584c..a35d9cc 100644
--- a/app/src/main/java/com/germainkevin/collapsingtopbarcompose/Components.kt
+++ b/app/src/main/java/com/germainkevin/collapsingtopbarcompose/Components.kt
@@ -22,46 +22,6 @@ import androidx.compose.ui.unit.sp
import com.germainkevin.collapsingtopbar.CollapsingTopBar
import com.germainkevin.collapsingtopbar.TopBarScrollBehavior
-@Composable
-fun CollapsingTopBarExample(scrollBehavior: TopBarScrollBehavior, contactNames: Array) {
- CollapsingTopBar(
- scrollBehavior = scrollBehavior,
- centeredTitleAndSubtitle = true,
- title = {
- Text(
- stringResource(id = R.string.all_contacts),
- style = LocalTextStyle.current.copy(
- fontSize = 24.sp,
- fontWeight = FontWeight.Normal,
- color = MaterialTheme.colorScheme.primary
- )
- )
- },
- subtitle = {
- Text(
- stringResource(
- id = R.string.contactNamesCount,
- contactNames.size.toString()
- ),
- style = LocalTextStyle.current.copy(
- fontWeight = FontWeight.Normal,
- color = MaterialTheme.colorScheme.onPrimaryContainer
- )
- )
- },
- navigationIcon = {
- IconButton(onClick = { }) {
- Icon(
- imageVector = Icons.Filled.Menu,
- contentDescription = stringResource(id = R.string.hamburger_menu),
- tint = MaterialTheme.colorScheme.primary
- )
- }
- },
- actions = { MoreMenuIcons() },
- )
-}
-
@Composable
fun ContactListNames(context: Context, contactName: String) {
Row(
diff --git a/app/src/main/java/com/germainkevin/collapsingtopbarcompose/MainActivity.kt b/app/src/main/java/com/germainkevin/collapsingtopbarcompose/MainActivity.kt
index a37e30f..0ae6c25 100644
--- a/app/src/main/java/com/germainkevin/collapsingtopbarcompose/MainActivity.kt
+++ b/app/src/main/java/com/germainkevin/collapsingtopbarcompose/MainActivity.kt
@@ -6,15 +6,18 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.material3.ExperimentalMaterial3Api
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Menu
+import androidx.compose.material3.*
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.germainkevin.collapsingtopbar.CollapsingTopBar
import com.germainkevin.collapsingtopbar.CollapsingTopBarDefaults
import com.germainkevin.collapsingtopbarcompose.ui.theme.CollapsingTopBarComposeTheme
@@ -34,18 +37,49 @@ class MainActivity : ComponentActivity() {
// A scrollBehavior determines the behavior of the CollapsingTopBar
// when it is being scrolled and also to track the nestedScroll events
val scrollBehavior = remember {
- CollapsingTopBarDefaults
- .collapsingTopBarScrollBehavior(
- isAlwaysCollapsed = false,
- expandedTopBarMaxHeight = 256.dp,
- )
+ CollapsingTopBarDefaults.behaviorOnScroll(
+ isAlwaysCollapsed = false,
+ expandedTopBarMaxHeight = 256.dp,
+ )
}
Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
- CollapsingTopBarExample(
+ CollapsingTopBar(
scrollBehavior = scrollBehavior,
- contactNames = contactNames
+ centeredTitleAndSubtitle = true,
+ title = {
+ Text(
+ stringResource(id = R.string.all_contacts),
+ style = LocalTextStyle.current.copy(
+ fontSize = 24.sp,
+ fontWeight = FontWeight.Normal,
+ color = MaterialTheme.colorScheme.primary
+ )
+ )
+ },
+ subtitle = {
+ Text(
+ stringResource(
+ id = R.string.contactNamesCount,
+ contactNames.size.toString()
+ ),
+ style = LocalTextStyle.current.copy(
+ fontWeight = FontWeight.Normal,
+ color = MaterialTheme.colorScheme.onPrimaryContainer
+ )
+ )
+ },
+ navigationIcon = {
+ IconButton(onClick = { }) {
+ Icon(
+ imageVector = Icons.Filled.Menu,
+ contentDescription = stringResource(id = R.string.hamburger_menu),
+ tint = MaterialTheme.colorScheme.primary
+ )
+ }
+ },
+ actions = { MoreMenuIcons() },
)
},
content = { innerPadding ->
diff --git a/app/src/main/java/com/germainkevin/collapsingtopbarcompose/ui/theme/Theme.kt b/app/src/main/java/com/germainkevin/collapsingtopbarcompose/ui/theme/Theme.kt
index 407c781..22906b7 100644
--- a/app/src/main/java/com/germainkevin/collapsingtopbarcompose/ui/theme/Theme.kt
+++ b/app/src/main/java/com/germainkevin/collapsingtopbarcompose/ui/theme/Theme.kt
@@ -3,17 +3,13 @@ package com.germainkevin.collapsingtopbarcompose.ui.theme
import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
-import androidx.compose.material3.MaterialTheme
-import androidx.compose.material3.darkColorScheme
-import androidx.compose.material3.dynamicDarkColorScheme
-import androidx.compose.material3.dynamicLightColorScheme
-import androidx.compose.material3.lightColorScheme
+import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
-import androidx.core.view.ViewCompat
+import androidx.core.view.WindowCompat
private val DarkColorScheme = darkColorScheme(
primary = Purple80,
@@ -55,8 +51,11 @@ fun CollapsingTopBarComposeTheme(
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
- (view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
- ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme
+ (view.context as Activity).apply {
+ window.statusBarColor = colorScheme.primary.toArgb()
+ WindowCompat.getInsetsController(window, view)?.isAppearanceLightStatusBars =
+ darkTheme
+ }
}
}
diff --git a/build.gradle b/build.gradle
index 38ace01..2aba049 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,8 +5,8 @@ buildscript {
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
- id 'com.android.application' version '7.2.0' apply false
- id 'com.android.library' version '7.2.0' apply false
+ 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
}
diff --git a/collapsingtopbar/build.gradle b/collapsingtopbar/build.gradle
index 227ba66..93615ad 100644
--- a/collapsingtopbar/build.gradle
+++ b/collapsingtopbar/build.gradle
@@ -4,6 +4,15 @@ plugins {
id 'maven-publish'
}
+android {
+ publishing {
+ singleVariant("release") {
+ withSourcesJar()
+ withJavadocJar()
+ }
+ }
+}
+
afterEvaluate {
publishing {
publications {
@@ -15,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-alpha05'
+ version = '1.0.0-alpha06'
}
}
}
@@ -60,10 +69,10 @@ dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
- implementation 'com.google.android.material:material:1.6.0'
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation "androidx.compose.ui:ui:$compose_version"
- implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
+ implementation "androidx.compose.material:material:$compose_version"
+ implementation 'androidx.compose.material3:material3:1.0.0-alpha12'
}
\ No newline at end of file
diff --git a/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/CollapsingTopBar.kt b/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/CollapsingTopBar.kt
index d71753a..a2681d3 100644
--- a/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/CollapsingTopBar.kt
+++ b/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/CollapsingTopBar.kt
@@ -15,7 +15,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
/**
- * [CollapsingTopBar]s display information and actions at the top of a screen.
+ * [CollapsingTopBar]s display is like a [TopAppBar] that can collapse and/or expand.
*
* This [CollapsingTopBar] has slots for a title, subtitle, navigation icon, and actions.
*
@@ -52,11 +52,11 @@ fun CollapsingTopBar(
scrollBehavior: TopBarScrollBehavior
) = with(scrollBehavior) {
- if (!isAlwaysCollapsed && isInitiallyCollapsed && trackOffSetIsZero >= 3) {
+ if (!isAlwaysCollapsed && !isExpandedWhenFirstDisplayed && trackOffSetIsZero >= 3) {
// Make sure the trackOffSetIsZero variable does not exceed the number 10
if (trackOffSetIsZero > 10) trackOffSetIsZero = 3
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
- } else if (!isInitiallyCollapsed) {
+ } else if (isExpandedWhenFirstDisplayed) {
currentTopBarHeight = expandedTopBarMaxHeight + topBarOffset.dp
}
diff --git a/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/CollapsingTopBarDefaults.kt b/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/CollapsingTopBarDefaults.kt
index 225ac1c..6b87018 100644
--- a/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/CollapsingTopBarDefaults.kt
+++ b/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/CollapsingTopBarDefaults.kt
@@ -4,8 +4,8 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material.MaterialTheme
import androidx.compose.material.contentColorFor
import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
/** Contains default values used for the [CollapsingTopBar] implementation. */
@@ -17,25 +17,26 @@ object CollapsingTopBarDefaults {
/**
* Specifies how the [CollapsingTopBar] should behave when a [Modifier.nestedScroll] is detected.
*
- * @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 isAlwaysCollapsed This will make this [CollapsingTopBar] stay collapsed and stay with
+ * the [collapsedTopBarHeight] height. It's false by default
+ * @param isExpandedWhenFirstDisplayed When true, Sets the [CollapsingTopBar] to an expanded
+ * state when first displayed on the UI by setting the [CollapsingTopBar]'s height to
+ * [expandedTopBarMaxHeight]
* @param collapsedTopBarHeight The height of the [CollapsingTopBar] when it's collapsed, the
* default value is [defaultMinimumTopBarHeight]
* @param expandedTopBarMaxHeight The height of the [CollapsingTopBar] when it's expended,
* the default value is [defaultMaximumTopBarHeight]
* */
- fun collapsingTopBarScrollBehavior(
+ fun behaviorOnScroll(
isAlwaysCollapsed: Boolean = false,
- isInitiallyCollapsed: Boolean = true,
+ isExpandedWhenFirstDisplayed: Boolean = true,
collapsedTopBarHeight: Dp = defaultMinimumTopBarHeight,
expandedTopBarMaxHeight: Dp = defaultMaximumTopBarHeight,
- ): TopBarScrollBehavior = CollapsingTopBarScrollBehavior(
- isAlwaysCollapsed = isAlwaysCollapsed,
- isInitiallyCollapsed = isInitiallyCollapsed,
- collapsedTopBarHeight = collapsedTopBarHeight,
- expandedTopBarMaxHeight = expandedTopBarMaxHeight,
+ ): TopBarScrollBehavior = DefaultBehaviorOnScroll(
+ isAlwaysCollapsed,
+ isExpandedWhenFirstDisplayed,
+ collapsedTopBarHeight,
+ expandedTopBarMaxHeight
)
/**
diff --git a/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/Constants.kt b/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/Constants.kt
index cfce168..3af9130 100644
--- a/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/Constants.kt
+++ b/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/Constants.kt
@@ -10,7 +10,6 @@ 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
-
val appBarHorizontalPadding = 4.dp
val defaultMinimumTopBarHeight = 56.dp
@@ -22,20 +21,4 @@ val noNavIconSpacerModifier = Modifier.width(16.dp - appBarHorizontalPadding)
val navigationIconModifier = Modifier
.fillMaxHeight()
- .width(56.dp - appBarHorizontalPadding)
-
-// MaterialTheme H6
-@Composable
-fun defaultExpandedTitleTextStyle(): TextStyle = LocalTextStyle.current.copy(
- fontWeight = FontWeight.Medium,
- fontSize = 20.sp,
- letterSpacing = 0.15.sp
-)
-
-// MaterialTheme Subtitle1
-@Composable
-fun defaultExpandedSubtitleTextStyle(): TextStyle = LocalTextStyle.current.copy(
- fontWeight = FontWeight.Normal,
- fontSize = 16.sp,
- letterSpacing = 0.15.sp
-)
\ No newline at end of file
+ .width(56.dp - appBarHorizontalPadding)
\ No newline at end of file
diff --git a/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/TopBarScrollBehavior.kt b/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/TopBarScrollBehavior.kt
index 09fe73d..431215f 100644
--- a/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/TopBarScrollBehavior.kt
+++ b/collapsingtopbar/src/main/java/com/germainkevin/collapsingtopbar/TopBarScrollBehavior.kt
@@ -7,7 +7,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
-import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
@@ -62,12 +61,10 @@ interface TopBarScrollBehavior {
var offsetLimit: Float
/**
- * Specifies whether the [CollapsingTopBar] should be displayed in a collapsed state when first
- * displayed on the UI. When set to true, [currentTopBarHeight] will be INITIALLY equal to
- * [collapsedTopBarHeight] and when false [currentTopBarHeight] will be INITIALLY equal to
- * [expandedTopBarMaxHeight]
+ * When true, Sets the [CollapsingTopBar] to an expanded state when first displayed on the UI
+ * by setting the [CollapsingTopBar]'s height to [expandedTopBarMaxHeight]
* */
- var isInitiallyCollapsed: Boolean
+ var isExpandedWhenFirstDisplayed: Boolean
/**
* A [NestedScrollConnection] that should be attached to a [Modifier.nestedScroll] in order to
@@ -76,30 +73,25 @@ interface TopBarScrollBehavior {
var nestedScrollConnection: NestedScrollConnection
}
-/**
- * @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 collapsedTopBarHeight The height of the [CollapsingTopBar] when it's collapsed, the
- * default value is [defaultMinimumTopBarHeight]
- * @param expandedTopBarMaxHeight The height of the [CollapsingTopBar] when it's expended, the
- * default value is [defaultMaximumTopBarHeight]
- * */
-class CollapsingTopBarScrollBehavior(
+class DefaultBehaviorOnScroll(
override var isAlwaysCollapsed: Boolean,
- override var isInitiallyCollapsed: Boolean,
+ override var isExpandedWhenFirstDisplayed: Boolean,
override var collapsedTopBarHeight: Dp,
override var expandedTopBarMaxHeight: Dp,
) : TopBarScrollBehavior {
+ init {
+ require(expandedTopBarMaxHeight > collapsedTopBarHeight) {
+ "expandedTopBarMaxHeight must be greater than collapsedTopBarHeight"
+ }
+ }
+
override var topBarOffset: Float by mutableStateOf(0f)
override var trackOffSetIsZero: Int by mutableStateOf(0)
override var currentTopBarHeight: Dp by mutableStateOf(
- if (isInitiallyCollapsed || isAlwaysCollapsed) collapsedTopBarHeight
+ if (isAlwaysCollapsed || !isExpandedWhenFirstDisplayed) collapsedTopBarHeight
else expandedTopBarMaxHeight
)
@@ -121,13 +113,5 @@ class CollapsingTopBarScrollBehavior(
return Offset.Zero
}
-
- override fun onPostScroll(
- consumed: Offset,
- available: Offset,
- source: NestedScrollSource
- ): Offset {
- return Offset.Zero
- }
}
}
\ No newline at end of file