Skip to content

Commit

Permalink
Release 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingermainbusiness committed Sep 6, 2022
1 parent 4008d8a commit 561ee02
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 24 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ A Jetpack Compose Collapsing Top Bar, that expands or collapses based on the scr
</tr>
<tr>
<td valign="top">
<img src="https://user-images.githubusercontent.com/83923717/188755003-dee6b3a7-6d4c-4391-b3a1-96e7cdb4ba8f.gif" alt="Demonstration 6" width="100%" height="auto"/>
<img src="https://user-images.githubusercontent.com/83923717/188755003-dee6b3a7-6d4c-4391-b3a1-96e7cdb4ba8f.gif" alt="Demonstration 4" width="100%" height="auto"/>
</td>
<td valign="top">
<img src="https://user-images.githubusercontent.com/83923717/177464670-545be4be-92f6-43d4-96d4-10bbb88758a7.gif" alt="Demonstration 4" width="100%" height="auto"/>
<img src="https://user-images.githubusercontent.com/83923717/177464670-545be4be-92f6-43d4-96d4-10bbb88758a7.gif" alt="Demonstration 5" width="100%" height="auto"/>
</td>
<td valign="top">
<img src="https://user-images.githubusercontent.com/83923717/177464670-545be4be-92f6-43d4-96d4-10bbb88758a7.gif" alt="Demonstration 5" width="100%" height="auto"/>
<img src="https://user-images.githubusercontent.com/83923717/177464670-545be4be-92f6-43d4-96d4-10bbb88758a7.gif" alt="Demonstration 6" width="100%" height="auto"/>
</td>
</tr>
</table>
Expand All @@ -55,7 +55,7 @@ repositories {

```groovy
dependencies {
implementation "com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.3"
implementation "com.github.germainkevinbusiness:CollapsingTopBarCompose:1.0.4"
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private fun HomeScreen(
isAlwaysCollapsed = false,
isExpandedWhenFirstDisplayed = true,
centeredTitleWhenCollapsed = false,
centeredTitleAndSubtitle = false,
centeredTitleAndSubtitle = true,
expandedTopBarMaxHeight = 156.dp,
)
Scaffold(
Expand All @@ -105,6 +105,7 @@ private fun HomeScreen(
},
),
title = TitleText,
expandedTitle = ExpandedTitleText,
subtitle = { SubtitleText(contactNames) },
navigationIcon = { NavigationIcon(openLeftDrawer) },
actions = { MoreMenuIcons() },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.germainkevin.collapsingtopbarcompose.ui

import android.content.Context
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
Expand All @@ -18,12 +18,14 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
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.collapsingtopbarcompose.R
import com.germainkevin.collapsingtopbarcompose.createToast


/**
Expand All @@ -32,7 +34,7 @@ import com.germainkevin.collapsingtopbarcompose.createToast
* */
val TitleText: @Composable () -> Unit = {
Text(
stringResource(id = R.string.all_contacts),
text = stringResource(id = R.string.contacts),
style = LocalTextStyle.current.copy(
fontSize = 24.sp,
fontWeight = FontWeight.Normal,
Expand All @@ -41,14 +43,41 @@ val TitleText: @Composable () -> Unit = {
)
}


/**
* Content that appears when the [CollapsingTopBar] is expanded
* */
val ExpandedTitleText: @Composable () -> Unit = {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
modifier = Modifier.size(46.dp),
painter = painterResource(id = R.drawable.ic_baseline_contacts_24),
contentDescription = "Contacts icon",
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onPrimary)
)
Text(
stringResource(id = R.string.contacts),
style = LocalTextStyle.current.copy(
fontSize = 22.sp,
fontWeight = FontWeight.Normal,
color = MaterialTheme.colorScheme.onPrimary
)
)
}
}

/**
* Text that appears in the subtitle slot of the
* [CollapsingTopBar][com.germainkevin.collapsingtopbar.CollapsingTopBar]
* */
val SubtitleText: @Composable (Array<String>) -> Unit = { contactNames ->
Text(
stringResource(id = R.string.contactNamesCount, contactNames.size.toString()),
text = stringResource(id = R.string.contactNamesCount, contactNames.size.toString()),
style = LocalTextStyle.current.copy(
fontSize = 14.sp,
fontWeight = FontWeight.Normal,
color = MaterialTheme.colorScheme.onPrimary
)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_contacts_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,0L4,0v2h16L20,0zM4,24h16v-2L4,22v2zM20,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM12,6.75c1.24,0 2.25,1.01 2.25,2.25s-1.01,2.25 -2.25,2.25S9.75,10.24 9.75,9 10.76,6.75 12,6.75zM17,17L7,17v-1.5c0,-1.67 3.33,-2.5 5,-2.5s5,0.83 5,2.5L17,17z"/>
</vector>
26 changes: 14 additions & 12 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="contactNames">
<item>"Andre Bosan"</item>
<item>Emiliano Martinez</item>
<item>Ibrahim Hovis</item>
<item>Omaz</item>
<item>Ubanohf</item>
<item>Yerri Mina</item>
<item>Andre Bosan</item>
<item>Benzema</item>
<item>Jonahtan</item>
<item>David Jamez</item>
<item>irano Sanri</item>
<item>Himenez Verdan</item>
<item>Frantzdy Pierrot</item>
<item>Emiliano Martinez</item>
<item>Irano Sanri</item>
<item>Inaki Pena</item>
<item>Kalib Mandi</item>
<item>Andre Bosan</item>
<item>Jonahtan</item>
<item>Himenez Verdan</item>
<item>Lionel Messi</item>
<item>Ronald Araujo</item>
<item>Robert Lewandowski</item>
<item>Omaz</item>
<item>Pedri</item>
<item>Yerri Mina</item>
<item>Ubanohf</item>
<item>Emiliano Martinez</item>
<item>Ibrahim Hovis</item>
<item>Omaz</item>
<item>Ubanohf</item>
<item>Yerri Mina</item>
</string-array>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources>
<string name="app_name">CollapsingTopBarCompose</string>
<string name="all_contacts">All Contacts</string>
<string name="contacts">Contacts</string>
<string name="contactNamesCount">%s contacts</string>
<string name="action_search">Search</string>
<string name="hamburger_menu">Hamburger menu</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ buildscript {
ext {
compose_version = '1.2.1'
coreKtx = '1.8.0'
libraryVersion ='1.0.3'
libraryVersion ='1.0.4'
kotlin_version = '1.7.0'
material3Version ='1.0.0-beta01'
timberVersion ='5.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.ui.unit.dp
*
* @param modifier A modifier that is passed down to the main layer which is a [Surface]
* @param title The title to be displayed inside the [CollapsingTopBar]
* @param expandedTitle Optional, In case you want the [title] to look different when the
* [CollapsingTopBar] is expanded
* @param subtitle The subtitle to be displayed inside the [CollapsingTopBar]
* @param navigationIcon the navigation icon displayed at the start of the [CollapsingTopBar].
* This should typically be an [IconButton] or [IconToggleButton].
Expand All @@ -41,6 +43,7 @@ import androidx.compose.ui.unit.dp
fun CollapsingTopBar(
modifier: Modifier = Modifier,
title: @Composable () -> Unit,
expandedTitle: @Composable (() -> Unit)? = null,
subtitle: @Composable () -> Unit = {},
navigationIcon: @Composable (() -> Unit)? = null,
actions: @Composable RowScope.() -> Unit = {},
Expand All @@ -52,6 +55,7 @@ fun CollapsingTopBar(
CollapsingTopBarLayout(
modifier = modifier,
title = title,
expandedTitle = expandedTitle,
subtitle = subtitle,
navigationIcon = navigationIcon,
actions = actions,
Expand Down Expand Up @@ -86,6 +90,7 @@ fun CollapsingTopBar(
private fun CollapsingTopBarLayout(
modifier: Modifier,
title: @Composable () -> Unit,
expandedTitle: @Composable (() -> Unit)?,
subtitle: @Composable () -> Unit,
navigationIcon: @Composable (() -> Unit)?,
actions: @Composable RowScope.() -> Unit,
Expand Down Expand Up @@ -130,7 +135,7 @@ private fun CollapsingTopBarLayout(
if (centeredTitleAndSubtitle) Alignment.CenterHorizontally else Alignment.Start,
verticalArrangement = Arrangement.Center,
content = {
title()
if (expandedTitle == null) title() else expandedTitle()
subtitle()
}
)
Expand Down

0 comments on commit 561ee02

Please sign in to comment.