Skip to content

Commit

Permalink
Updated to 1.0.0-beta08 version
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingermainbusiness committed Jun 23, 2022
1 parent 52dc7a5 commit 970c8c5
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 56 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-beta07'
implementation 'com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.0-beta08'
}
```

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-beta07"
versionName "1.0.0-beta08"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.rememberScaffoldState
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
Expand All @@ -24,6 +25,7 @@ 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.CollapsingTopBarScrollBehavior
import com.germainkevin.collapsingtopbar.rememberCollapsingTopBarScrollBehavior
import com.germainkevin.collapsingtopbarcompose.ui.ContactListNames
import com.germainkevin.collapsingtopbarcompose.ui.LeftDrawer
Expand Down Expand Up @@ -66,45 +68,15 @@ class MainActivity : ComponentActivity() {
centeredTitleAndSubtitle = false,
expandedTopBarMaxHeight = 156.dp,
)

Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
scaffoldState = scaffoldState,
drawerContent = { LeftDrawer(closeLeftDrawer = closeLeftDrawer) },
topBar = {
CollapsingTopBar(
OurCollapsingTopBar(
scrollBehavior = scrollBehavior,
title = {
Text(
stringResource(id = R.string.all_contacts),
style = LocalTextStyle.current.copy(
fontSize = 24.sp,
fontWeight = FontWeight.Normal,
color = MaterialTheme.colorScheme.onPrimary
)
)
},
subtitle = {
Text(
stringResource(
id = R.string.contactNamesCount,
contactNames.size.toString()
),
style = LocalTextStyle.current.copy(
fontWeight = FontWeight.Normal,
color = MaterialTheme.colorScheme.onPrimary
)
)
},
navigationIcon = {
IconButton(onClick = openLeftDrawer) {
Icon(
imageVector = Icons.Filled.Menu,
contentDescription = stringResource(id = R.string.hamburger_menu),
tint = MaterialTheme.colorScheme.onPrimary
)
}
},
actions = { MoreMenuIcons() },
contactNames = contactNames, openLeftDrawer = openLeftDrawer
)
},
content = { innerPadding ->
Expand All @@ -129,4 +101,47 @@ class MainActivity : ComponentActivity() {
}
}
}
}

@Composable
fun OurCollapsingTopBar(
scrollBehavior: CollapsingTopBarScrollBehavior,
contactNames: Array<String>,
openLeftDrawer: () -> Unit,
) {
CollapsingTopBar(
scrollBehavior = scrollBehavior,
title = {
Text(
stringResource(id = R.string.all_contacts),
style = LocalTextStyle.current.copy(
fontSize = 24.sp,
fontWeight = FontWeight.Normal,
color = MaterialTheme.colorScheme.onPrimary
)
)
},
subtitle = {
Text(
stringResource(
id = R.string.contactNamesCount,
contactNames.size.toString()
),
style = LocalTextStyle.current.copy(
fontWeight = FontWeight.Normal,
color = MaterialTheme.colorScheme.onPrimary
)
)
},
navigationIcon = {
IconButton(onClick = openLeftDrawer) {
Icon(
imageVector = Icons.Filled.Menu,
contentDescription = stringResource(id = R.string.hamburger_menu),
tint = MaterialTheme.colorScheme.onPrimary
)
}
},
actions = { MoreMenuIcons() },
)
}
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-beta07'
version = '1.0.0-beta08'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fun CollapsingTopBar(
* @param elevation The size of the shadow below the [Surface]
* */
@Composable
internal fun CollapsingTopBarLayout(
private fun CollapsingTopBarLayout(
modifier: Modifier,
title: @Composable () -> Unit,
subtitle: @Composable () -> Unit,
Expand Down Expand Up @@ -183,7 +183,7 @@ internal fun CollapsingTopBarLayout(
}
}

internal val navigationIconRow: @Composable (@Composable (() -> Unit)?) -> Unit =
private val navigationIconRow: @Composable (@Composable (() -> Unit)?) -> Unit =
{ navigationIcon ->
if (navigationIcon == null) Spacer(modifier = noNavIconSpacerModifier)
else {
Expand All @@ -195,7 +195,7 @@ internal val navigationIconRow: @Composable (@Composable (() -> Unit)?) -> Unit
}
}

internal val collapsedTitle: @Composable (Boolean, Float, @Composable () -> Unit) -> Unit =
private val collapsedTitle: @Composable (Boolean, Float, @Composable () -> Unit) -> Unit =
{ centeredTitleAndSubtitle, collapsedTitleAlpha, title ->
val enterAnimation = if (centeredTitleAndSubtitle)
expandVertically(
Expand All @@ -216,7 +216,7 @@ internal val collapsedTitle: @Composable (Boolean, Float, @Composable () -> Unit
/**
* The Section where all the options menu items will be laid out on
* */
internal val actionsRow: @Composable (@Composable RowScope.() -> Unit) -> Unit = {
private val actionsRow: @Composable (@Composable RowScope.() -> Unit) -> Unit = {
Row(
modifier = Modifier.fillMaxHeight(),
horizontalArrangement = Arrangement.End,
Expand Down Expand Up @@ -266,7 +266,7 @@ internal val actionsRow: @Composable (@Composable RowScope.() -> Unit) -> Unit =
* [currentTopBarHeight] reaches past [collapsedTopBarHeight] + [margin]
*/
@Composable
internal fun getTitleAndSubtitleColumnAlpha(
private fun getTitleAndSubtitleColumnAlpha(
currentTopBarHeight: Dp,
collapsedTopBarHeight: Dp,
expandedTopBarMaxHeight: Dp,
Expand All @@ -287,7 +287,7 @@ internal fun getTitleAndSubtitleColumnAlpha(
* Collapsed Title section should become invisible
* */
@Composable
internal fun getCollapsedTitleAlpha(
private fun getCollapsedTitleAlpha(
currentTopBarHeight: Dp,
visibleValue: Dp,
invisibleValue: Dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,21 @@ fun rememberCollapsingTopBarScrollBehavior(
centeredTitleAndSubtitle: Boolean = true,
collapsedTopBarHeight: Dp = defaultMinimumTopBarHeight,
expandedTopBarMaxHeight: Dp = defaultMaximumTopBarHeight,
): CollapsingTopBarScrollBehavior = remember {
CollapsingTopBarDefaults.scrollBehavior(
isAlwaysCollapsed = isAlwaysCollapsed,
isExpandedWhenFirstDisplayed = isExpandedWhenFirstDisplayed,
centeredTitleAndSubtitle = centeredTitleAndSubtitle,
collapsedTopBarHeight = collapsedTopBarHeight,
expandedTopBarMaxHeight = expandedTopBarMaxHeight
)
): CollapsingTopBarScrollBehavior {
return remember(
isAlwaysCollapsed,
isExpandedWhenFirstDisplayed,
centeredTitleAndSubtitle,
collapsedTopBarHeight,
collapsedTopBarHeight,
expandedTopBarMaxHeight
) {
CollapsingTopBarDefaults.scrollBehavior(
isAlwaysCollapsed = isAlwaysCollapsed,
isExpandedWhenFirstDisplayed = isExpandedWhenFirstDisplayed,
centeredTitleAndSubtitle = centeredTitleAndSubtitle,
collapsedTopBarHeight = collapsedTopBarHeight,
expandedTopBarMaxHeight = expandedTopBarMaxHeight
)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.germainkevin.collapsingtopbar

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.runtime.*
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
Expand Down Expand Up @@ -79,9 +78,6 @@ interface CollapsingTopBarScrollBehavior {
val nestedScrollConnection: NestedScrollConnection
}

/**
* Here lies the logic on how the [CollapsingTopBar] behaves at all times
* */
class DefaultBehaviorOnScroll(
override var isAlwaysCollapsed: Boolean,
override var isExpandedWhenFirstDisplayed: Boolean,
Expand Down

0 comments on commit 970c8c5

Please sign in to comment.